/** * Initializes the widget. */ public function init() { parent::init(); Yii::import('bootstrap.behaviors.TbWidget'); $this->attachBehavior('tbWidget', new TbWidget()); if (!isset($this->assetPath)) { $this->assetPath = realpath(dirname(__FILE__) . '/../assets'); } if (!$this->asDropDownList && !isset($this->pluginOptions['data'])) { $this->pluginOptions['data'] = $this->normalizeData($this->data); } if (isset($this->htmlOptions['placeholder'])) { if ($this->asDropDownList) { $this->htmlOptions['prompt'] = $this->htmlOptions['placeholder']; } else { $this->pluginOptions['placeholder'] = $this->htmlOptions['placeholder']; } unset($this->htmlOptions['placeholder']); } if (!$this->bindPlugin) { $this->htmlOptions['data-plugin'] = 'select2'; $this->htmlOptions['data-plugin-options'] = CJSON::encode($this->pluginOptions); } if (TbArray::popValue('block', $this->htmlOptions, false)) { TbHtml::addCssClass('input-block-level', $this->htmlOptions); } }
public function init() { parent::init(); TbHtml::addCssClass('bfh-fonts', $this->htmlOptions); if (!isset($this->htmlOptions['data-font'])) { $this->htmlOptions['data-font'] = TbArray::popValue('data-value', $this->htmlOptions); } unset($this->htmlOptions['data-name'], $this->htmlOptions['data-value']); }
public function testPopValue() { $array = array('key' => 'value'); $this->assertEquals('value', TbArray::popValue('key', $array)); $this->assertArrayNotHasKey('key', $array); $nullValueArray = array('key' => null); $this->assertNull(TbArray::popValue('key', $nullValueArray, 'not null'), 'Null value has to be found'); $this->assertArrayNotHasKey('key', $nullValueArray); }
/** * Widget's init function */ public function init() { $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin')); if (!($style = TbArray::popValue('style', $this->htmlOptions, ''))) { $this->htmlOptions['style'] = $style; } $width = TbArray::getValue('width', $this->htmlOptions, '100%'); $height = TbArray::popValue('height', $this->htmlOptions, '450px'); $this->htmlOptions['style'] = "width:{$width};height:{$height};" . $this->htmlOptions['style']; }
public function init() { if (empty($this->country)) { throw new CException('"$country" cannot be empty.'); } $this->pluginOptions['country'] = $this->country; parent::init(); TbHtml::addCssClass('bfh-states', $this->htmlOptions); if (!isset($this->htmlOptions['data-state'])) { $this->htmlOptions['data-state'] = TbArray::popValue('data-value', $this->htmlOptions); } unset($this->htmlOptions['data-name'], $this->htmlOptions['data-value']); }
/** * Initializes the widget. */ public function init() { parent::init(); Yii::import('bootstrap.behaviors.TbWidget'); $this->attachBehavior('tbWidget', new TbWidget()); if (!isset($this->assetPath)) { $this->assetPath = Yii::getPathOfAlias('lib.select2'); } if (!$this->asDropDownList && !isset($this->pluginOptions['data'])) { $this->pluginOptions['data'] = $data = $this->normalizeData($this->data); } if (!$this->bindPlugin) { $this->htmlOptions['data-plugin'] = 'select2'; $this->htmlOptions['data-plugin-options'] = CJSON::encode($this->pluginOptions); } if (TbArray::popValue('block', $this->htmlOptions, false)) { TbHtml::addCssClass('input-block-level', $this->htmlOptions); } }
/** * Runs the widget. */ public function run() { /* @var $user CWebUser */ $user = Yii::app()->getUser(); if (count($user->getFlashes(false)) == 0) { return; } echo TbHtml::openTag('div', $this->htmlOptions); foreach ($this->alerts as $color => $alert) { if (isset($alert['visible']) && !$alert['visible']) { continue; } if ($user->hasFlash($color)) { $htmlOptions = TbArray::popValue('htmlOptions', $alert, array()); TbArray::defaultValue('closeText', $this->closeText, $htmlOptions); TbArray::defaultValue('block', $this->block, $htmlOptions); TbArray::defaultValue('fade', $this->fade, $htmlOptions); echo TbHtml::alert($color, $user->getFlash($color), $htmlOptions); } } echo '</div>'; $this->registerEvents("#{$this->htmlOptions['id']} > .alert", $this->events); }
/** * 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 = TbArray::popValue('url', $button); if ($url !== '#') { $url = $this->evaluateExpression($url, array('data' => $data, 'row' => $row)); } $imageUrl = TbArray::popValue('imageUrl', $button, false); $label = TbArray::popValue('label', $button, $id); $options = TbArray::popValue('options', $button, array()); TbArray::defaultValue('title', $label, $options); TbArray::defaultValue('rel', 'tooltip', $options); if ($icon = TbArray::popValue('icon', $button, false)) { echo CHtml::link(TbHtml::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); } } }
/** * Adds the text align class to the given options if applicable. * @param array $htmlOptions the HTML attributes. */ protected static function addTextAlignClass(&$htmlOptions) { $align = TbArray::popValue('textAlign', $htmlOptions); if (!empty($align)) { self::addCssClass('text-' . $align, $htmlOptions); } }
/** * Processes the options for a input row. * @param CModel $model the data model. * @param string $attribute the attribute name. * @param array $options the options. * @return array the processed options. */ protected function processControlGroupOptions($model, $attribute, $options) { $errorOptions = TbArray::popValue('errorOptions', $options, array()); $enableAjaxValidation = TbArray::popValue('enableAjaxValidation', $errorOptions, true); $enableClientValidation = TbArray::popValue('enableClientValidation', $errorOptions, true); $errorOptions['type'] = $this->helpType; $error = $this->error($model, $attribute, $errorOptions, $enableAjaxValidation, $enableClientValidation); // kind of a hack for ajax forms but this works for now. if (!empty($error) && strpos($error, 'display:none') === false) { $options['color'] = TbHtml::INPUT_COLOR_ERROR; } if (!$this->hideInlineErrors) { $options['error'] = $error; } $helpOptions = TbArray::popValue('helpOptions', $options, array()); $helpOptions['type'] = $this->helpType; $options['helpOptions'] = $helpOptions; return $options; }
/** * Normalizes the tab configuration. * @param array $tabs a reference to the tabs tab configuration. */ protected function normalizeTabs($tabs) { $controller = $this->getController(); if (isset($controller)) { foreach ($tabs as &$tabOptions) { $items = TbArray::getValue('items', $tabOptions, array()); if (!empty($items)) { $tabOptions['items'] = $this->normalizeTabs($items); } else { if (isset($tabOptions['view'])) { $view = TbArray::popValue('view', $tabOptions); if ($controller->getViewFile($view) !== false) { $tabOptions['content'] = $controller->renderPartial($view, $this->viewData, true); } } } } } return $tabs; }
/** * Adds the text align class to the given options if applicable. * @param array $htmlOptions the HTML attributes. */ protected static function addTextAlignClass(&$htmlOptions) { // todo: check if this is supported in bs3 $align = TbArray::popValue('textAlign', $htmlOptions); if (!empty($align)) { self::addCssClass('text-' . $align, $htmlOptions); } }
/** * Runs the widget. */ public function run() { $brand = $this->brandLabel !== false ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : ''; ob_start(); foreach ($this->items as $item) { if (is_string($item)) { echo $item; } else { $widgetClassName = TbArray::popValue('class', $item); if ($widgetClassName !== null) { $this->controller->widget($widgetClassName, $item); } } } $items = ob_get_clean(); ob_start(); if ($this->collapse !== false) { TbHtml::addCssClass('nav-collapse', $this->collapseOptions); ob_start(); /* @var TbCollapse $collapseWidget */ $collapseWidget = $this->controller->widget('bootstrap.widgets.TbCollapse', array('toggle' => false, 'content' => $items, 'htmlOptions' => $this->collapseOptions)); $collapseContent = ob_get_clean(); echo TbHtml::navbarCollapseLink('#' . $collapseWidget->getId()); echo $brand . $collapseContent; } else { echo $brand . $items; } $containerContent = ob_get_clean(); $containerOptions = TbArray::popValue('containerOptions', $this->htmlOptions, array()); TbHtml::addCssClass($this->fluid ? 'container-fluid' : 'container', $containerOptions); ob_start(); echo TbHtml::openTag('div', $containerOptions); echo $containerContent; echo '</div>'; $content = ob_get_clean(); echo TbHtml::navbar($content, $this->htmlOptions); }
public function testPopValue() { $array = array('key' => 'value'); $this->assertEquals('value', TbArray::popValue('key', $array)); $this->assertArrayNotHasKey('key', $array); }
/** * Registers the client scripts for the button column. */ protected function registerClientScript() { $js = array(); $function = CJavaScript::encode(TbArray::popValue('click', $this->toggleOptions, '')); $class = preg_replace('/\\s+/', '.', $this->toggleOptions['htmlOptions']['class']); $js[] = "\$(document).on('click','#{$this->grid->id} a.{$class}',{$function});"; Yii::app()->getClientScript()->registerScript($this->name . '#ReadyJS', implode("\n", $js)); }
/** * Renders the button */ public function renderButton() { if (!empty($this->buttonOptions) && is_array($this->buttonOptions)) { TbArray::defaultValue('data-toggle', 'modal', $this->buttonOptions); if ($this->remote !== null) { $this->buttonOptions['data-remote'] = CHtml::normalizeUrl($this->remote); } $selector = '#' . $this->htmlOptions['id']; $label = TbArray::popValue('label', $this->buttonOptions, 'button'); $attr = isset($this->buttonOptions['data-remote']) ? 'data-target' : 'href'; TbArray::defaultValue($attr, $selector, $this->buttonOptions); echo TbHtml::button($label, $this->buttonOptions); } }
/** * Runs the widget. */ public function run() { $brand = $this->brandLabel !== false ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : ''; ob_start(); if (!Yii::app()->user->isGuest) { $menus = $this->Menudata(); } else { $menus[0] = array(); } $menus[1] = array('class' => 'bootstrap.widgets.TbNav', 'htmlOptions' => array('class' => 'pull-right'), 'items' => array(array('label' => '网站前台', 'url' => Yii::app()->request->hostInfo . Yii::app()->baseUrl), array('label' => '站点配置', 'url' => array('/settings/index'), 'visible' => !Yii::app()->user->isGuest), array('label' => '登录', 'url' => array('/site/login'), 'visible' => Yii::app()->user->isGuest), array('label' => Yii::app()->user->name, 'url' => '#', 'items' => array(array('label' => '个人资料', 'icon' => 'user', 'url' => '#'), array('label' => '退出', 'icon' => 'off', 'url' => array('/site/logout'))), 'visible' => !Yii::app()->user->isGuest))); $this->items = $menus; foreach ($this->items as $item) { if (is_string($item)) { echo $item; } else { $widgetClassName = TbArray::popValue('class', $item); if ($widgetClassName !== null) { $this->controller->widget($widgetClassName, $item); } } } $items = ob_get_clean(); ob_start(); if ($this->collapse !== false) { TbHtml::addCssClass('nav-collapse', $this->collapseOptions); ob_start(); /* @var TbCollapse $collapseWidget */ $collapseWidget = $this->controller->widget('bootstrap.widgets.TbCollapse', array('toggle' => false, 'content' => $items, 'htmlOptions' => $this->collapseOptions)); $collapseContent = ob_get_clean(); echo TbHtml::navbarCollapseLink('#' . $collapseWidget->getId()); echo $brand . $collapseContent; } else { echo $brand . $items; } $containerContent = ob_get_clean(); $containerOptions = TbArray::popValue('containerOptions', $this->htmlOptions, array()); TbHtml::addCssClass($this->fluid ? 'container-fluid' : 'container', $containerOptions); ob_start(); echo TbHtml::openTag('div', $containerOptions); echo $containerContent; echo '</div>'; $content = ob_get_clean(); echo TbHtml::navbar($content, $this->htmlOptions); }