/** * 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() { if ($this->brandLabel !== false) { if (!isset($this->brandLabel)) { $this->brandLabel = CHtml::encode(Yii::app()->name); } if (!isset($this->brandUrl)) { $this->brandUrl = Yii::app()->homeUrl; } } if (isset($this->color)) { \bootstrap\helpers\BSArray::defaultValue('color', $this->color, $this->htmlOptions); } if (isset($this->position) && $this->position !== BSHtml::NAVBAR_POSITION) { \bootstrap\helpers\BSArray::defaultValue('position', $this->position, $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; }
/** * Generates an image carousel. * @param array $items the item configurations. * @param array $htmlOptions additional HTML attributes. * @return string the generated carousel. */ public static function carousel(array $items, $htmlOptions = array()) { if (!empty($items)) { $id = \bootstrap\helpers\BSArray::getValue('id', $htmlOptions, parent::ID_PREFIX . parent::$count++); \bootstrap\helpers\BSArray::defaultValue('id', $id, $htmlOptions); $selector = '#' . $id; self::addCssClass('carousel', $htmlOptions); if (\bootstrap\helpers\BSArray::popValue('slide', $htmlOptions, true)) { self::addCssClass('slide', $htmlOptions); } $interval = \bootstrap\helpers\BSArray::popValue('data-interval', $htmlOptions); if ($interval) { $htmlOptions['data-interval'] = $interval; } $pause = \bootstrap\helpers\BSArray::popValue('data-pause', $htmlOptions); if ($pause) { $htmlOptions['data-pause'] = $pause; } $indicatorOptions = \bootstrap\helpers\BSArray::popValue('indicatorOptions', $htmlOptions, array()); $innerOptions = \bootstrap\helpers\BSArray::popValue('innerOptions', $htmlOptions, array()); self::addCssClass('carousel-inner', $innerOptions); $prevOptions = \bootstrap\helpers\BSArray::popValue('prevOptions', $htmlOptions, array()); $prevLabel = \bootstrap\helpers\BSArray::popValue('label', $prevOptions, '‹'); $nextOptions = \bootstrap\helpers\BSArray::popValue('nextOptions', $htmlOptions, array()); $nextLabel = \bootstrap\helpers\BSArray::popValue('label', $nextOptions, '›'); $hidePrevAndNext = \bootstrap\helpers\BSArray::popValue('hidePrevAndNext', $htmlOptions, false); $output = self::openTag('div', $htmlOptions); $output .= self::carouselIndicators($selector, count($items), $indicatorOptions); $output .= self::openTag('div', $innerOptions); foreach ($items as $i => $itemOptions) { if (isset($itemOptions['visible']) && $itemOptions['visible'] === false) { continue; } if ($i === 0) { // first item should be active self::addCssClass('active', $itemOptions); } $content = \bootstrap\helpers\BSArray::popValue('content', $itemOptions, ''); $image = \bootstrap\helpers\BSArray::popValue('image', $itemOptions, ''); $imageOptions = \bootstrap\helpers\BSArray::popValue('imageOptions', $itemOptions, array()); $imageAlt = \bootstrap\helpers\BSArray::popValue('alt', $imageOptions, ''); if (!empty($image)) { $content = parent::image($image, $imageAlt, $imageOptions); } $label = \bootstrap\helpers\BSArray::popValue('label', $itemOptions); $caption = \bootstrap\helpers\BSArray::popValue('caption', $itemOptions); $output .= self::carouselItem($content, $label, $caption, $itemOptions); } $output .= '</div>'; if (!$hidePrevAndNext) { $output .= self::carouselPrevLink($prevLabel, $selector, $prevOptions); $output .= self::carouselNextLink($nextLabel, $selector, $nextOptions); } $output .= '</div>'; return $output; } return ''; }
/** * Displays a summary of validation errors for one or several models. * @param mixed $models the models whose input errors are to be displayed. * @param string $header a piece of HTML code that appears in front of the errors * @param string $footer a piece of HTML code that appears at the end of the errors * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag. * @return string the error summary. Empty if no errors are found. */ public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array()) { if (!$this->enableAjaxValidation && !$this->enableClientValidation) { return BSHtml::errorSummary($models, $header, $footer, $htmlOptions); } \bootstrap\helpers\BSArray::defaultValue('id', $this->id . '_es_', $htmlOptions); $html = BSHtml::errorSummary($models, $header, $footer, $htmlOptions); if ($html === '') { if ($header === null) { $header = '<p>' . Yii::t('yii', 'Please fix the following input errors:') . '</p>'; } BSHtml::addCssClass(BSHtml::$errorSummaryCss, $htmlOptions); BSHtml::addCssStyle('display:none', $htmlOptions); $html = CHtml::tag('div', $htmlOptions, $header . '<ul><li>dummy</li></ul>' . $footer); } $this->summaryID = $htmlOptions['id']; return $html; }
/** * 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); }