/** * Renders a link button. * @param string $id the ID of the button * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements. * @param integer $row the row number (zero-based) * @param mixed $data the data object associated with the row */ protected function renderButton($id, $button, $row, $data) { if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data))) { return; } $url = \bootstrap\helpers\BSArray::popValue('url', $button, '#'); if (strcmp($url, '#') !== 0) { $url = $this->evaluateExpression($url, array('data' => $data, 'row' => $row)); } $imageUrl = \bootstrap\helpers\BSArray::popValue('imageUrl', $button, false); $label = \bootstrap\helpers\BSArray::popValue('label', $button, $id); $options = \bootstrap\helpers\BSArray::popValue('options', $button, array()); \bootstrap\helpers\BSArray::defaultValue('data-title', $label, $options); \bootstrap\helpers\BSArray::defaultValue('title', $label, $options); \bootstrap\helpers\BSArray::defaultValue('data-toggle', 'tooltip', $options); if ($icon = \bootstrap\helpers\BSArray::popValue('icon', $button, false)) { echo CHtml::link(BSHtml::icon($icon), $url, $options); } else { if ($imageUrl && is_string($imageUrl)) { echo CHtml::link(CHtml::image($imageUrl, $label), $url, $options); } else { echo CHtml::link($label, $url, $options); } } }
/** * Initializes the widget. */ public function init() { $this->attachBehavior('BsWidget', new BsWidget()); $this->copyId(); if (isset($this->size)) { \bootstrap\helpers\BSArray::defaultValue('size', $this->size, $this->htmlOptions); } }
/** * Initializes the widget. */ public function init() { Yii::app()->clientScript->registerCoreScript('jquery'); $this->attachBehavior('BsWidget', new BsWidget()); $this->copyId(); BSHtml::addCssClass('collapse', $this->htmlOptions); if (isset($this->parent)) { \bootstrap\helpers\BSArray::defaultValue('data-parent', $this->parent, $this->htmlOptions); } if (isset($this->toggle) && $this->toggle) { BSHtml::addCssClass('in', $this->htmlOptions); } if (isset($this->view)) { $controller = $this->getController(); if (isset($controller) && $controller->getViewFile($this->view) !== false) { $this->content = $this->controller->renderPartial($this->view, $this->viewData, true); } } echo BSHtml::openTag($this->tagName, $this->htmlOptions); echo $this->content; }
/** * Runs the widget. */ public function run() { $brand = $this->brandLabel !== false ? BSHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : ''; ob_start(); foreach ($this->items as $item) { if (is_string($item)) { echo $item; } else { $widgetClassName = \bootstrap\helpers\BSArray::popValue('class', $item); if ($widgetClassName !== null) { $this->controller->widget($widgetClassName, $item); } } } $items = ob_get_clean(); ob_start(); if ($this->collapse !== false) { BSHtml::addCssClass('collapse navbar-collapse', $this->collapseOptions); ob_start(); /* @var BsCollapse $collapseWidget */ $collapseWidget = $this->controller->widget('bootstrap.widgets.BsCollapse', array('toggle' => false, 'content' => $items, 'htmlOptions' => $this->collapseOptions)); $collapseContent = ob_get_clean(); $collapseLink = BSHtml::navbarCollapseLink('#' . $collapseWidget->getId()); echo BSHtml::tag('div', array('class' => 'navbar-header'), $collapseLink . $brand) . $collapseContent; } else { echo BSHtml::tag('div', array('class' => 'navbar-header'), $brand) . $items; } $containerContent = ob_get_clean(); $containerOptions = \bootstrap\helpers\BSArray::popValue('containerOptions', $this->htmlOptions, array()); BSHtml::addCssClass('container', $containerOptions); $content = BSHtml::tag('div', $containerOptions, $containerContent); echo BSHtml::navbar($content, $this->htmlOptions); }
/** * Generates a carousel item. * @param string $content the content. * @param string $label the item label text. * @param string $caption the item caption text. * @param array $htmlOptions additional HTML attributes. * @return string the generated item. */ public static function carouselItem($content, $label, $caption, $htmlOptions = array()) { self::addCssClass('item', $htmlOptions); $overlayOptions = \bootstrap\helpers\BSArray::popValue('overlayOptions', $htmlOptions, array()); self::addCssClass('carousel-caption', $overlayOptions); $labelOptions = \bootstrap\helpers\BSArray::popValue('labelOptions', $htmlOptions, array()); $captionOptions = \bootstrap\helpers\BSArray::popValue('captionOptions', $htmlOptions, array()); $url = \bootstrap\helpers\BSArray::popValue('url', $htmlOptions, false); if ($url !== false) { $content = self::link($content, $url); } $output = self::openTag('div', $htmlOptions); $output .= $content; if (isset($label) || isset($caption)) { $output .= self::openTag('div', $overlayOptions); if ($label) { $output .= self::tag('h4', $labelOptions, $label); } if ($caption) { $output .= self::tag('p', $captionOptions, $caption); } $output .= '</div>'; } $output .= '</div>'; return $output; }
/** * set the label CssClass by Layout * @param string $layout * @param array $labelOptions * @return array new label options */ private static function setLabelOptionsByLayout($layout, $labelOptions = array()) { if (empty($layout) || $layout === BSHtml::FORM_LAYOUT_VERTICAL) { BSHtml::addCssClass('control-label', $labelOptions); return $labelOptions; } if ($layout === BSHtml::FORM_LAYOUT_INLINE) { BSHtml::addCssClass('control-label', $labelOptions); BSHtml::addCssClass('sr-only', $labelOptions); return $labelOptions; } $labelClass = \bootstrap\helpers\BSArray::popValue('class', $labelOptions, BSHtml::FORM_LAYOUT_HORIZONTAL_LABEL_CLASS); BSHtml::addCssClass('control-label', $labelOptions); BSHtml::addCssClass($labelClass, $labelOptions); return $labelOptions; }
/** * Renders the button */ public function renderButton() { if (!empty($this->buttonOptions) && is_array($this->buttonOptions)) { \bootstrap\helpers\BSArray::defaultValue('data-toggle', 'modal', $this->buttonOptions); if ($this->remote !== null) { $this->buttonOptions['data-remote'] = CHtml::normalizeUrl($this->remote); } $selector = '#' . $this->htmlOptions['id']; $label = \bootstrap\helpers\BSArray::popValue('label', $this->buttonOptions, 'button'); $attr = isset($this->buttonOptions['data-remote']) ? 'data-target' : 'href'; \bootstrap\helpers\BSArray::defaultValue($attr, $selector, $this->buttonOptions); echo BSHtml::button($label, $this->buttonOptions); } }
/** * Normalizes the menu items. * @param array $items the items to be normalized. * @param string $route the route of the current request. * @param boolean $active whether there is an active child menu item. * @return array the normalized menu items. */ protected function normalizeItems($items, $route, &$active) { foreach ($items as $i => $item) { // skip dividers if (is_string($item)) { continue; } if (isset($item['visible']) && !$item['visible']) { unset($items[$i]); continue; } \bootstrap\helpers\BSArray::defaultValue('label', '', $item); if ($this->encodeLabel) { $items[$i]['label'] = CHtml::encode($item['label']); } $hasActiveChild = false; if (isset($item['items']) && !empty($item['items'])) { $items[$i]['items'] = $this->normalizeItems($item['items'], $route, $hasActiveChild); if (empty($items[$i]['items']) && $this->hideEmptyItems) { unset($items[$i]['items']); if (!isset($item['url'])) { unset($items[$i]); continue; } } } if (!isset($item['active'])) { if ($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item, $route)) { $active = $items[$i]['active'] = true; } else { $items[$i]['active'] = false; } } else { if ($item['active']) { $active = true; } } } return array_values($items); }