Ejemplo n.º 1
0
 /**
  * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also
  * configure `panes` accordingly.
  * @param string $itemNumber number of the item
  * @param array $items the dropdown items configuration.
  * @param array $panes the panes reference array.
  * @return boolean whether any of the dropdown items is `active` or not.
  * @throws InvalidConfigException
  */
 protected function renderDropdown($itemNumber, &$items, &$panes)
 {
     $itemActive = false;
     foreach ($items as $n => &$item) {
         if (is_string($item)) {
             continue;
         }
         if (isset($item['visible']) && !$item['visible']) {
             continue;
         }
         if (!array_key_exists('content', $item)) {
             throw new InvalidConfigException("The 'content' option is required.");
         }
         $content = ArrayHelper::remove($item, 'content');
         $options = ArrayHelper::remove($item, 'contentOptions', []);
         Html::addCssClass($options, ['widget' => 'tab-pane']);
         if (ArrayHelper::remove($item, 'active')) {
             Html::addCssClass($options, 'active');
             Html::addCssClass($item['options'], 'active');
             $itemActive = true;
         }
         $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd' . $itemNumber . '-tab' . $n);
         $item['url'] = '#' . $options['id'];
         $item['linkOptions']['data-toggle'] = 'tab';
         $panes[] = Html::tag('div', $content, $options);
         unset($item);
     }
     return $itemActive;
 }
 /**
  * Renders menu items.
  * @param array $items the menu items to be rendered
  * @param array $options the container HTML attributes
  * @return string the rendering result.
  * @throws InvalidConfigException if the label option is not specified in one of the items.
  */
 protected function renderItems($items, $options = [])
 {
     $lines = [];
     foreach ($items as $item) {
         if (isset($item['visible']) && !$item['visible']) {
             continue;
         }
         if (is_string($item)) {
             $lines[] = $item;
             continue;
         }
         if (!array_key_exists('label', $item)) {
             throw new InvalidConfigException("The 'label' option is required.");
         }
         $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
         $label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
         $itemOptions = ArrayHelper::getValue($item, 'options', []);
         $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
         $linkOptions['tabindex'] = '-1';
         $url = array_key_exists('url', $item) ? $item['url'] : null;
         if (empty($item['items'])) {
             if ($url === null) {
                 $content = $label;
                 Html::addCssClass($itemOptions, ['widget' => 'dropdown-header']);
             } else {
                 $content = Html::a($label, $url, $linkOptions);
             }
         } else {
             $submenuOptions = $this->submenuOptions;
             if (isset($item['submenuOptions'])) {
                 $submenuOptions = array_merge($submenuOptions, $item['submenuOptions']);
             }
             $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions);
             Html::addCssClass($itemOptions, ['widget' => 'dropdown-submenu']);
         }
         $lines[] = Html::tag('li', $content, $itemOptions);
     }
     return Html::tag('ul', implode("\n", $lines), $options);
 }
 /**
  * Generates a bar
  * @param integer $percent the percentage of the bar
  * @param string $label, optional, the label to display at the bar
  * @param array $options the HTML attributes of the bar
  * @return string the rendering result.
  */
 protected function renderBar($percent, $label = '', $options = [])
 {
     $defaultOptions = ['role' => 'progressbar', 'aria-valuenow' => $percent, 'aria-valuemin' => 0, 'aria-valuemax' => 100, 'style' => "width:{$percent}%"];
     $options = array_merge($defaultOptions, $options);
     Html::addCssClass($options, ['widget' => 'progress-bar']);
     $out = Html::beginTag('div', $options);
     $out .= $label;
     $out .= Html::tag('span', \Yii::t('yii', '{percent}% Complete', ['percent' => $percent]), ['class' => 'sr-only']);
     $out .= Html::endTag('div');
     return $out;
 }
Ejemplo n.º 4
0
 /**
  * Initializes the widget options.
  * This method sets the default values for various options.
  */
 protected function initOptions()
 {
     $this->options = array_merge(['class' => 'fade', 'role' => 'dialog', 'tabindex' => -1], $this->options);
     Html::addCssClass($this->options, ['widget' => 'modal']);
     if ($this->clientOptions !== false) {
         $this->clientOptions = array_merge(['show' => false], $this->clientOptions);
     }
     if ($this->closeButton !== false) {
         $this->closeButton = array_merge(['data-dismiss' => 'modal', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton);
     }
     if ($this->toggleButton !== false) {
         $this->toggleButton = array_merge(['data-toggle' => 'modal'], $this->toggleButton);
         if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) {
             $this->toggleButton['data-target'] = '#' . $this->options['id'];
         }
     }
 }
 /**
  * Renders a single collapsible item group
  * @param string $header a label of the item group [[items]]
  * @param array $item a single item from [[items]]
  * @param integer $index the item index as each item group content must have an id
  * @return string the rendering result
  * @throws InvalidConfigException
  */
 public function renderItem($header, $item, $index)
 {
     if (array_key_exists('content', $item)) {
         $id = $this->options['id'] . '-collapse' . $index;
         $options = ArrayHelper::getValue($item, 'contentOptions', []);
         $options['id'] = $id;
         Html::addCssClass($options, ['widget' => 'panel-collapse', 'collapse' => 'collapse']);
         $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
         if ($encodeLabel) {
             $header = Html::encode($header);
         }
         $headerToggle = Html::a($header, '#' . $id, ['class' => 'collapse-toggle', 'data-toggle' => 'collapse', 'data-parent' => '#' . $this->options['id']]) . "\n";
         $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']);
         if (is_string($item['content']) || is_object($item['content'])) {
             $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n";
         } elseif (is_array($item['content'])) {
             $content = Html::ul($item['content'], ['class' => 'list-group', 'itemOptions' => ['class' => 'list-group-item'], 'encode' => false]) . "\n";
             if (isset($item['footer'])) {
                 $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n";
             }
         } else {
             throw new InvalidConfigException('The "content" option should be a string, array or object.');
         }
     } else {
         throw new InvalidConfigException('The "content" option is required.');
     }
     $group = [];
     $group[] = Html::tag('div', $header, ['class' => 'panel-heading']);
     $group[] = Html::tag('div', $content, $options);
     return implode("\n", $group);
 }
 /**
  * Parses and returns addon content
  *
  * @param string|array $addon the addon parameter
  *
  * @return string
  */
 public static function getAppendAddonContent($addon)
 {
     if (!is_array($addon)) {
         return $addon;
     }
     $content = ArrayHelper::getValue($addon, 'content', '');
     $options = ArrayHelper::getValue($addon, 'options', []);
     if (ArrayHelper::getValue($addon, 'asButton', false) == true) {
         Html::addCssClass($options, 'input-group-btn');
         return Html::tag('span', $content, $options);
     } else {
         Html::addCssClass($options, 'icon-right');
         return Html::tag('span', $content, $options);
     }
 }
 /**
  * Generates the button dropdown.
  * @return string the rendering result.
  */
 protected function renderButton()
 {
     Html::addCssClass($this->options, ['widget' => 'btn']);
     $label = $this->label;
     if ($this->encodeLabel) {
         $label = Html::encode($label);
     }
     if ($this->split) {
         $options = $this->options;
         $this->options['data-toggle'] = 'dropdown';
         Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']);
         unset($this->options['id']);
         $splitButton = Button::widget(['label' => '<span class="caret"></span>', 'encodeLabel' => false, 'options' => $this->options, 'view' => $this->getView()]);
     } else {
         $label .= ' <span class="caret"></span>';
         $options = $this->options;
         if (!isset($options['href'])) {
             $options['href'] = '#';
         }
         Html::addCssClass($options, ['toggle' => 'dropdown-toggle']);
         $options['data-toggle'] = 'dropdown';
         $splitButton = '';
     }
     return Button::widget(['tagName' => $this->tagName, 'label' => $label, 'options' => $options, 'encodeLabel' => false, 'view' => $this->getView()]) . "\n" . $splitButton;
 }
Ejemplo n.º 8
0
 /**
  * Initializes the widget options.
  * This method sets the default values for various options.
  */
 protected function initOptions()
 {
     Html::addCssClass($this->options, ['alert', 'fade', 'in']);
     if ($this->closeButton !== false) {
         $this->closeButton = array_merge(['data-dismiss' => 'alert', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton);
     }
 }
 /**
  * Renders a single carousel item
  * @param string|array $item a single item from [[items]]
  * @param integer $index the item index as the first item should be set to `active`
  * @return string the rendering result
  * @throws InvalidConfigException if the item is invalid
  */
 public function renderItem($item, $index)
 {
     if (is_string($item)) {
         $content = $item;
         $caption = null;
         $options = [];
     } elseif (isset($item['content'])) {
         $content = $item['content'];
         $caption = ArrayHelper::getValue($item, 'caption');
         if ($caption !== null) {
             $caption = Html::tag('div', $caption, ['class' => 'carousel-caption']);
         }
         $options = ArrayHelper::getValue($item, 'options', []);
     } else {
         throw new InvalidConfigException('The "content" option is required.');
     }
     Html::addCssClass($options, ['widget' => 'item']);
     if ($index === 0) {
         Html::addCssClass($options, 'active');
     }
     return Html::tag('div', $content . "\n" . $caption, $options);
 }
 /**
  * Initializes the widget.
  * If you override this method, make sure you call the parent implementation first.
  */
 public function init()
 {
     parent::init();
     Html::addCssClass($this->options, ['widget' => 'btn-group']);
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) {
         throw new InvalidConfigException('Invalid layout type: ' . $this->layout);
     }
     if ($this->layout !== 'default') {
         Html::addCssClass($this->options, 'form-' . $this->layout);
     }
     parent::init();
 }
Ejemplo n.º 12
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     $this->clientOptions = false;
     if (empty($this->options['class'])) {
         Html::addCssClass($this->options, ['navbar', 'navbar-default']);
     } else {
         Html::addCssClass($this->options, ['widget' => 'navbar']);
     }
     if (empty($this->options['role'])) {
         $this->options['role'] = 'navigation';
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'nav');
     echo Html::beginTag($tag, $options);
     if ($this->renderInnerContainer) {
         if (!isset($this->innerContainerOptions['class'])) {
             Html::addCssClass($this->innerContainerOptions, 'container');
         }
         echo Html::beginTag('div', $this->innerContainerOptions);
     }
     echo Html::beginTag('div', ['class' => 'navbar-header']);
     if (!isset($this->containerOptions['id'])) {
         $this->containerOptions['id'] = "{$this->options['id']}-collapse";
     }
     echo $this->renderToggleButton();
     if ($this->brandLabel !== false) {
         Html::addCssClass($this->brandOptions, ['widget' => 'navbar-brand']);
         echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
     }
     echo Html::endTag('div');
     Html::addCssClass($this->containerOptions, ['collapse' => 'collapse', 'widget' => 'navbar-collapse']);
     $options = $this->containerOptions;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     echo Html::beginTag($tag, $options);
 }
Ejemplo n.º 13
0
 /**
  * Check to see if a child item is active optionally activating the parent.
  * @param array $items @see items
  * @param boolean $active should the parent be active too
  * @return array @see items
  */
 protected function isChildActive($items, &$active)
 {
     foreach ($items as $i => $child) {
         if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
             Html::addCssClass($items[$i]['options'], 'active');
             if ($this->activateParents) {
                 $active = true;
             }
         }
     }
     return $items;
 }
 /**
  * @inheritdoc
  */
 public function textInput($options = [])
 {
     Html::addCssClass($options, $this->addClass);
     var_dump($options);
     return parent::textInput($options);
 }