/** * Renders menu items. * @param array $items the menu items to be rendered * @return string the rendering result. * @throws InvalidConfigException if the label option is not specified in one of the items. */ protected function renderItems($items) { $lines = []; foreach ($items as $i => $item) { if (isset($item['visible']) && !$item['visible']) { unset($items[$i]); continue; } if (is_string($item)) { $lines[] = $item; continue; } if (!isset($item['title'])) { throw new InvalidConfigException("The 'title' option is required."); } $title = $this->encode ? Html::encode($item['title']) : $item['title']; $titleOptions = ArrayHelper::getValue($item, 'titleOptions', []); Html::addCssClass($titleOptions, 'list-group-item-heading'); $titleCode = Html::tag('h4', $title, $titleOptions); $description = $this->encode ? Html::encode($item['description']) : $item['description']; $descriptionOptions = ArrayHelper::getValue($item, 'descriptionOptions', []); Html::addCssClass($descriptionOptions, 'list-group-item-text'); $descriptionCode = Html::tag('p', $description, $descriptionOptions); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); Html::addCssClass($linkOptions, 'list-group-item'); Html::addCssStyle($linkOptions, 'word-wrap: break-word'); if (isset($item['active']) && $item['active']) { Html::addCssClass($linkOptions, 'active'); } $linkOptions['tabindex'] = '-1'; $lines[] = Html::a($titleCode . "\n" . $descriptionCode, ArrayHelper::getValue($item, 'url', '#'), $linkOptions); } return Html::tag('div', implode("\n", $lines), $this->options); }
public function run() { //$id = $this->getId(); Html::addCssClass($this->options, "form-control"); echo $this->getInput($this->type, $this->list); $this->registerAssets(); }
protected function renderReloader() { $text = Html::tag('p', 'На изображении плохо видно буквы?'); $link = Html::tag('p', 'Нажмите сюда для обновления.', ['id' => 'verifycode-hint', 'class' => 'captcha-hint-link']); Html::addCssClass($options, 'captcha-hint'); return Html::tag('div', $text . $link, $options); }
public function run() { if (!$this->visible) { return false; } if (($class = self::sizeToClass($this->size)) !== false) { Html::addCssClass($this->options, $class); } Html::addCssClass($this->options, "btn-{$this->type}"); $label = $this->encodeLabel ? Html::encode($this->label) : $this->label; if (isset($this->icon)) { $label = "<i class='glyphicon glyphicon-{$this->icon}'></i> " . $label; } if (isset($this->url)) { $this->tagName = 'a'; $this->options['role'] = 'button'; $this->options['href'] = Url::to($this->url); if ($this->disabled) { Html::addCssClass($this->options, 'disabled'); } } else { if ($this->disabled) { $this->options['disabled'] = 'disabled'; } } if ($this->block) { Html::addCssClass($this->options, 'btn-block'); } $html = Html::tag($this->tagName, $label, $this->options); echo $html; $this->registerPlugin('button'); }
public function init() { parent::init(); Html::addCssClass($this->options, 'ui message'); if ($this->icon) { Html::addCssClass($this->options, self::TYPE_ICON); } if ($this->hidden) { Html::addCssClass($this->options, self::TYPE_HIDDEN); } if ($this->visible) { Html::addCssClass($this->options, self::TYPE_VISIBLE); } if ($this->floating) { Html::addCssClass($this->options, self::TYPE_FLOATING); } if ($this->compact) { Html::addCssClass($this->options, self::TYPE_COMPACT); } if ($this->attached) { Html::addCssClass($this->options, self::TYPE_ATTACHED); } if ($this->size) { Html::addCssClass($this->options, $this->size); } if ($this->color) { Html::addCssClass($this->options, $this->color); } if ($this->type) { Html::addCssClass($this->options, $this->type); } echo Html::beginTag('div', $this->options); }
/** * @inheritdoc */ public function run() { $this->_msgCat = 'kvcolor'; if (!isset($this->type)) { $this->type = $this->useNative ? 'color' : 'text'; } $this->width = '60px'; $this->initI18N(__DIR__); if (empty($this->html5Container['id'])) { $this->html5Container['id'] = $this->options['id'] . '-cont'; } if ($this->type === 'text') { Html::addCssStyle($this->html5Options, 'display:none'); if ($this->pluginLoading) { Html::addCssClass($this->html5Container, 'kv-center-loading'); } } $this->html5Options['value'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value; if (substr($this->language, 0, 2) !== 'en') { $this->_defaultOptions += ['cancelText' => Yii::t('kvcolor', 'cancel'), 'chooseText' => Yii::t('kvcolor', 'choose'), 'clearText' => Yii::t('kvcolor', 'Clear Color Selection'), 'noColorSelectedText' => Yii::t('kvcolor', 'No Color Selected'), 'togglePaletteMoreText' => Yii::t('kvcolor', 'more'), 'togglePaletteLessText' => Yii::t('kvcolor', 'less')]; } Html::addCssClass($this->containerOptions, 'spectrum-group'); Html::addCssClass($this->html5Options, 'spectrum-source'); Html::addCssClass($this->options, 'spectrum-input'); if (!$this->useNative) { Html::addCssClass($this->html5Container, 'input-group-sp'); $this->pluginOptions = array_replace_recursive($this->_defaultOptions, $this->pluginOptions); } $this->initInput(); $this->registerColorInput(); }
/** * Generates the button dropdown. * @return string the rendering result. */ protected function renderButton() { Html::addCssClass($this->options, 'btn'); $label = $this->label; if ($this->encodeLabel) { $label = Html::encode($label); } $options = $this->options; $splitButton = ''; $caretHtml = $this->caretHtml ? $this->caretHtml : '<span class="caret"></span>'; if ($this->split) { $options = $this->options; $this->options['data-toggle'] = 'dropdown'; Html::addCssClass($this->options, 'dropdown-toggle'); $splitButton = Button::widget(['label' => $this->caretHtml ? $this->caretHtml : '<span class="caret"></span>', 'encodeLabel' => false, 'options' => $this->options, 'view' => $this->getView()]); } else { $label .= ' ' . $this->caretHtml ? $this->caretHtml : '<span class="caret"></span>'; $options = $this->options; if (!isset($options['href'])) { $options['href'] = '#'; } Html::addCssClass($options, 'dropdown-toggle'); $options['data-toggle'] = 'dropdown'; } return Button::widget(['tagName' => $this->tagName, 'label' => $label, 'options' => $options, 'encodeLabel' => false, 'view' => $this->getView()]) . "\n" . $splitButton; }
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; $expanded = false; if (array_key_exists('expanded', $item)) { $expanded = $item['expanded']; } Html::addCssClass($options, 'panel-collapse collapse' . ($expanded ? ' in' : '')); $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'])) { $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 or array.'); } } 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); }
public function init() { parent::init(); $clientValue = self::toClientFormat($this->model->{$this->attribute}); if ($clientValue === false) { throw new InvalidConfigException(); } $this->model->{$this->attribute} = $clientValue; if (!isset($this->select2Config['pluginOptions']['allowClear'])) { $this->select2Config['pluginOptions']['placeholder'] = ''; $this->select2Config['pluginOptions']['allowClear'] = true; } if (!isset($this->select2Config['options'])) { $this->select2Config['options'] = null; } $this->setDataTarget($this->select2Config['options']); Html::addCssClass($this->select2Config['options'], 'combowidget-select2'); if (!isset($this->select2Config['value'])) { $this->select2Config['value'] = $this->inputValue(self::STATE_LIST); } // ugly workaround (InputWidget must have name or model) $this->select2Config['name'] = Html::getInputId($this->model, $this->attribute) . '-ignored-combowidget-select2'; $this->setDataTarget($this->switchOptions); Html::addCssClass($this->switchOptions, 'combowidget-switch'); $this->setDataTarget($this->textInputOptions); Html::addCssClass($this->textInputOptions, 'combowidget-textinput'); }
public function prepareOptions() { $defaultItem = $this->getDefaultItem(); $this->options['item'] = ArrayHelper::getValue($this->options, 'item', $defaultItem); $this->options['itemOptions'] = $this->listOptions; Html::addCssClass($this->options, 'grouped inline fields'); }
public function init() { parent::init(); Html::addCssClass($this->htmlOptions, 'custom-dz'); /** @var Image[] $files */ $files = Image::find()->where(['and', 'object_id = :objectId', 'object_model_id = :modelId'], [':objectId' => $this->objectId, ':modelId' => $this->modelId])->orderBy(['sort_order' => SORT_ASC])->all(); /** Image $file */ foreach ($files as $file) { $thumbnail_src = $file->getThumbnail('80x80'); $this->storedFiles[] = ['id' => $file->id, 'name' => $file->filename, 'file' => $file->file, 'thumbnail' => $thumbnail_src, 'description' => $file->image_description]; } $params = ArrayHelper::merge(isset($this->options['params']) ? $this->options['params'] : [], ['objectId' => $this->objectId, 'modelId' => $this->modelId]); $this->sortable = true; $this->options = ArrayHelper::merge($this->options, ['acceptedFiles' => 'image/*', 'params' => $params, 'previewTemplate' => '<div class="file-row"> ' . Html::input('hidden', 'id[]') . Html::input('hidden', 'file[]') . ' <!-- This is used as the file preview template --> <div> <span class="preview"><img style="width: 80px; height: 80px;" data-dz-thumbnail /></span> </div> <div> <p class="name" data-dz-name></p> <div class="dz-error-message"><span data-dz-errormessage></span></div> </div> <div class="description"> ' . Html::textarea('description', '', ['style' => 'width: 100%; min-width: 80px; height: 80px;']) . ' </div> <div> <p class="size" data-dz-size></p> <div class="dz-progress progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"> <div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div> </div> <div class="dz-success-mark"><span>✔</span> OK</div> <div class="dz-error-mark"><span>✘</span> ERROR</div> </div> <div> <button data-dz-remove class="btn btn-danger delete"> <i class="fa fa-trash-o"></i> <span>' . Yii::t('app', 'Delete') . '</span> </button> </div> </div>', 'thumbnailWidth' => '80', 'thumbnailHeight' => '80', 'previewsContainer' => "#{$this->id}"]); $this->eventHandlers = ['removedfile' => 'function(file) { jQuery.get( "' . Url::toRoute($this->removeUrl) . '", { "id" : jQuery(file.previewElement).find("[name=\\"id[]\\"]").val(), "filename" : jQuery(file.previewElement).data("filename") } ).done(function (data) { return data }); }', 'success' => 'function(file, response) { response = jQuery.parseJSON(response); jQuery(file.previewElement).find("[data-dz-name]").text(response.filename); jQuery(file.previewElement).data("filename", response.filename); jQuery(file.previewElement).find("[name=\\"id[]\\"]").val(response.afterUpload.id); jQuery(file.previewElement).find("[name=\\"file[]\\"]").val(response.afterUpload.file); jQuery(file.previewElement).find(".description textarea").attr("name", "description["+response.afterUpload.id+"]"); }', 'complete' => 'function(file) { jQuery(file.previewElement).removeClass("dz-processing"); }']; }
/** * @inheritdoc */ public function init() { parent::init(); $formatter = Yii::$app->getFormatter(); if (is_null($this->dateFormat)) { $this->dateFormat = $formatter->dateFormat; if (is_null($this->dateFormat)) { $this->dateFormat = 'medium'; } } if (is_null($this->timeFormat)) { $this->timeFormat = $formatter->timeFormat; if (is_null($this->timeFormat)) { $this->timeFormat = 'medium'; } } if (is_null($this->altDateFormat)) { $this->altDateFormat = 'yyyy-MM-dd'; } if (is_null($this->altTimeFormat)) { $this->altTimeFormat = 'HH:mm:ss'; } Html::addCssClass($this->options, 'form-control'); $this->altOptions['id'] = $this->options['id'] . '-alt'; $this->clientOptions = array_merge(array_diff_assoc(['numberOfMonths' => $this->numberOfMonths, 'showButtonPanel' => $this->showButtonPanel], get_class_vars(__CLASS__)), $this->clientOptions, ['dateFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->dateFormat), 'separator' => static::SEPARATOR, 'timeFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->timeFormat, 'time'), 'altField' => '#' . $this->altOptions['id'], 'altFieldTimeOnly' => false, 'altFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altDateFormat), 'altSeparator' => static::SEPARATOR, 'altTimeFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altTimeFormat, 'time')]); if (array_key_exists('readonly', $this->options) && $this->options['readonly']) { if (!array_key_exists('beforeShow', $this->clientOptions)) { $this->clientOptions['beforeShow'] = new JsExpression('function (input, inst) { return false; }'); } } }
public function init() { parent::init(); $this->options['id'] = $this->id; Html::addCssClass($this->options, 'sx-tree'); $this->_beginPjax(); }
/** * @inheritdoc */ public function init() { parent::init(); if (!empty($this->size)) { Html::addCssClass($this->options, 'btn-group-' . $this->size); } }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); $this->clientOptions = false; Html::addCssClass($this->options, $this->size); Html::addCssClass($this->options, 'material-icons'); }
public function run() { if (empty($this->links)) { return; } $links = []; if ($this->actions !== null) { Html::addCssClass($this->actions['dropdown']['options'], 'pull-right'); if (is_string($this->actions)) { $links[] = $this->actions; } else { if (is_array($this->actions)) { $links[] = ButtonDropdown::widget($this->actions); } else { throw new InvalidConfigException('Actions must be of type "string" or "array".'); } } } if ($this->homeLink === null) { $links[] = $this->renderItem(['label' => Yii::t('yii', 'Home'), 'url' => Yii::$app->homeUrl], $this->itemTemplate); } elseif ($this->homeLink !== false) { $links[] = $this->renderItem($this->homeLink, $this->itemTemplate); } foreach ($this->links as $link) { if (!is_array($link)) { $link = ['label' => $link]; } $links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate); } echo Html::tag($this->tag, implode('', $links), $this->options); }
/** * @inheritdoc */ public function init() { parent::init(); if (is_null($this->language)) { $this->language = Yii::$app->language; if (is_null($this->language)) { $this->language = 'en-US'; } } $formatter = Yii::$app->getFormatter(); if (is_null($this->items)) { $this->items = $formatter->booleanFormat; if (is_null($this->items)) { $this->items = [Yii::t('yii', 'No', [], $this->language), Yii::t('yii', 'Yes', [], $this->language)]; } } if (is_null($this->prompt)) { $this->prompt = $formatter->nullDisplay; if (is_null($this->prompt)) { $this->prompt = Yii::t('yii', '(not set)', [], $this->language); } } Html::addCssClass($this->options, 'form-control'); if (array_key_exists('value', $this->options)) { $this->value = $this->options['value']; unset($this->options['value']); } if (is_string($this->prompt) && !array_key_exists('prompt', $this->options)) { $this->options['prompt'] = strip_tags($this->prompt); } }
public function init() { parent::init(); $this->registerJs(); Html::addCssClass($this->options, 'ui sticky'); echo Html::beginTag('div', $this->options); }
/** * Initializes the widget. */ public function init() { parent::init(); if (!isset($this->options['class'])) { Html::addCssClass($this->options, 'dropdown'); } }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { if ($this->showButton) { Html::addCssClass($this->options, 'uk-button'); } $this->options = array_merge(['data-uk-smooth-scroll' => ''], $this->options); }
protected function renderButtonAdd() { Html::addCssClass($this->buttonOptions, 'btn'); $this->buttonOptions = ArrayHelper::merge($this->buttonOptions, ['role' => 'area.add', 'data-tmpl' => $this->options['id']]); $templateButtonAdding = strtr($this->templateButtonAdding, ['{button}' => Html::button('+', $this->buttonOptions), '{label}' => Html::tag('label', $this->label)]); echo Html::tag('div', $templateButtonAdding, ['class' => 'form-group']); }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { Html::addCssClass($this->options, 'uk-badge'); if ($this->isNotification) { Html::addCssClass($this->options, 'uk-badge-notification'); } }
public function init() { parent::init(); if (empty($this->options)) { Html::addCssClass($this->options, ['horizontal-menu']); } }
public function renderItem($model, $key, $index) { if ($this->itemView === null) { $content = $key; } elseif (is_string($this->itemView)) { $content = $this->getView()->render($this->itemView, array_merge(['model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this, 'user' => $this->user], $this->viewParams)); } else { $content = call_user_func($this->itemView, $model, $key, $index, $this); } $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); if ($tag !== false) { $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; $options['data-contact'] = $model['contact_id']; if (isset($this->clientOptions['unreadCssClass'])) { if ($model['new_messages'] > 0) { Html::addCssClass($options, $this->clientOptions['unreadCssClass']); } } if (isset($this->clientOptions['currentCssClass'])) { if ($model['contact_id'] == \Yii::$app->request->get('contactId')) { Html::addCssClass($options, $this->clientOptions['currentCssClass']); } } return Html::tag($tag, $content, $options); } else { return $content; } }
protected function renderPageButton($label, $page, $class, $disabled, $active) { $options = ['class' => $class === '' ? null : $class]; if (!$this->disableHighlightActive) { if ($active) { Html::addCssClass($options, $this->activePageCssClass); } } if ($disabled) { Html::addCssClass($options, $this->disabledPageCssClass); if ($this->noArrows) { return; } return Html::tag('li', Html::tag('span', $label), $options); } if ((string) $label == '') { if ($this->noArrows) { return; } } $linkOptions = $this->linkOptions; $linkOptions['data-page'] = $page; //$linkOptions['onclick'] = 'submit_form(' . $page . ')'; $linkPage = $page + 1; return Html::tag('li', Html::a($label, $this->url . $linkPage, $linkOptions), $options); }
public function init() { parent::init(); Html::addCssClass($this->htmlOptions, 'dropzone'); Html::addCssClass($this->messageOptions, 'dz-message'); $this->dropzoneName = 'dropzone_' . $this->id; }
/** * @inheritdoc */ public function init() { parent::init(); //register asset FlagIconAsset::register($this->getView()); //assert country code is set and valid if ($this->countryCode === null) { $msg = Yii::t('app', 'The country code is required'); throw new InvalidConfigException($msg); } else { if (!is_string($this->countryCode) || strlen($this->countryCode) !== 2) { $msg = Yii::t('app', 'The country code needs to be a string with a length of 2 characters'); throw new InvalidConfigException($msg); } $this->countryCode = strtolower($this->countryCode); } //add default classes Html::addCssClass($this->options, 'flag-icon'); if ($this->isSquared) { Html::addCssClass($this->options, 'flag-icon-squared'); } //add actual flag class Html::addCssClass($this->options, 'flag-icon-' . $this->countryCode); //set size if defined if (strcmp($this->sizeCss, Flag::SIZE_DEFAULT) !== 0) { $this->addSizeToOptions(); } }
public function init() { \kartik\base\InputWidget::init(); $this->pluginOptions['theme'] = $this->theme; if (!empty($this->addon) || empty($this->pluginOptions['width'])) { $this->pluginOptions['width'] = '100%'; } $multiple = ArrayHelper::getValue($this->pluginOptions, 'multiple', false); unset($this->pluginOptions['multiple']); $multiple = ArrayHelper::getValue($this->options, 'multiple', $multiple); $this->options['multiple'] = $multiple; if ($this->hideSearch) { $css = ArrayHelper::getValue($this->pluginOptions, 'dropdownCssClass', ''); $css .= ' kv-hide-search'; $this->pluginOptions['dropdownCssClass'] = $css; } $this->initPlaceholder(); if ($this->data == null) { if (!isset($this->value) && !isset($this->initValueText)) { $this->data = []; } else { $key = isset($this->value) ? $this->value : ($multiple ? [] : ''); $val = isset($this->initValueText) ? $this->initValueText : $key; $this->data = $multiple ? array_combine($key, $val) : [$key => $val]; } } Html::addCssClass($this->options, 'form-control'); $this->initLanguage('language', true); $this->registerAssets(); $this->renderInput(); }
public static function getHtmlOptions($tag, $asString = true) { $tag = strtolower($tag); $options = []; switch ($tag) { case 'body': if (strcasecmp(Metronic::getComponent()->headerOption, 'fixed') === 0) { Html::addCssClass($options, 'page-header-fixed'); } switch (Metronic::getComponent()->layoutOption) { case Metronic::LAYOUT_FULL_WIDTH: Html::addCssClass($options, Metronic::LAYOUT_FULL_WIDTH); break; case Metronic::LAYOUT_BOXED: Html::addCssClass($options, Metronic::LAYOUT_BOXED); break; } break; case 'header': Html::addCssClass($options, 'header navbar'); if (strcasecmp(Metronic::getComponent()->headerOption, 'fixed') === 0) { Html::addCssClass($options, 'navbar-fixed-top'); } else { Html::addCssClass($options, 'navbar-static-top'); } break; } return $asString ? Html::renderTagAttributes($options) : $options; }
protected function renderFilterCellContent() { if (is_string($this->filter)) { return $this->filter; } $model = $this->grid->filterModel; if ($this->filter !== false && $model instanceof Model && $this->attribute !== null && $model->isAttributeActive($this->attribute)) { if ($model->hasErrors($this->attribute)) { $error = Html::error($model, $this->attribute, $this->grid->filterErrorOptions); } else { $error = ''; } if (is_array($this->filter)) { $options = array_merge(['prompt' => ''], $this->filterDropdownOptions); if ($model->hasErrors($this->attribute)) { Html::addCssClass($options, 'error'); } return Select::widget(['model' => $model, 'attribute' => $this->attribute, 'items' => $this->filter, 'options' => $options, 'search' => true]) . ' ' . $error; } else { $options = ['class' => 'fluid']; if ($model->hasErrors($this->attribute)) { Html::addCssClass($options, 'error'); } return Elements::input(Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error, $options); } } else { return parent::renderFilterCellContent(); } }