예제 #1
0
 /**
  * Generates an icon.
  * @param string $icon the icon type.
  * @param array $htmlOptions additional HTML attributes.
  * @param string $tagName the icon HTML tag.
  * @return string the generated icon.
  */
 public static function icon($icon, $htmlOptions = array(), $tagName = 'i')
 {
     if (is_string($icon)) {
         if (strpos($icon, 'foundicon-') === false) {
             $icon = 'foundicon-' . implode(' foundicon-', array_unique(explode(' ', $icon)));
         }
         ArrayHelper::addValue('class', $icon, $htmlOptions);
         return \CHtml::openTag($tagName, $htmlOptions) . \CHtml::closeTag($tagName);
     }
     return '';
 }
예제 #2
0
 public static function bar($percent, $htmlOptions = array())
 {
     $percent = substr(trim($percent), -1) !== '%' ? $percent . '%' : $percent;
     ArrayHelper::addValue('class', Enum::PROGRESS, $htmlOptions);
     ob_start();
     echo \CHtml::openTag('div', $htmlOptions);
     echo \CHtml::openTag('span', array('class' => Enum::PROGRESS_METER, 'style' => 'width:' . $percent));
     echo \CHtml::closeTag('span');
     echo \CHtml::closeTag('div');
     return ob_get_clean();
 }
예제 #3
0
 /**
  * Initializes the widget
  */
 public function init()
 {
     $this->assets = array('js' => YII_DEBUG ? 'foundation/foundation.tooltips.js' : 'foundation.min.js');
     Html::addCssClass($this->htmlOptions, Enum::TOOLTIP);
     Html::addCssClass($this->htmlOptions, $this->position);
     ArrayHelper::addValue('title', $this->tip, $this->htmlOptions);
     ArrayHelper::addValue('data-tooltip', 'data-tooltip', $this->htmlOptions);
     if ($this->tip === null || $this->text === null) {
         throw new InvalidConfigException('"tip" and "text" cannot be null.');
     }
     $this->registerClientScript();
     parent::init();
 }
예제 #4
0
 /**
  * Renders the alert
  * @return string the rendering result
  */
 public function renderAlert()
 {
     $user = \Yii::app()->user;
     if (count($user->getFlashes(false)) == 0) {
         return;
     }
     $alerts = array();
     foreach ($this->config as $style => $config) {
         if ($user->hasFlash($style)) {
             $options = ArrayHelper::getValue($config, 'htmlOptions', array());
             Html::addCssClass($options, $style);
             $close = ArrayHelper::getValue($config, 'close', '×');
             $alerts[] = \foundation\helpers\Alert::alert($user->getFlash($style), $options, $close);
         }
     }
     $this->registerEvents("#{$this->htmlOptions['id']} > .alert-box", $this->events);
     return \CHtml::tag('div', $this->htmlOptions, implode("\n", $alerts));
 }
예제 #5
0
 /**
  * Renders dropdown items
  * @return string
  * @throws InvalidConfigException
  */
 protected function renderItems()
 {
     $lines = array();
     if ($this->type === Enum::DROPDOWN_CONTENT) {
         $lines[] = $this->dropdownContent;
     }
     if ($this->type === Enum::DROPDOWN_LIST) {
         foreach ($this->items as $item) {
             if (is_string($item)) {
                 $lines[] = $item;
                 continue;
             }
             if (!isset($item['label'])) {
                 throw new InvalidConfigException("The 'label' option is required.");
             }
             $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label'];
             $options = ArrayHelper::getValue($item, 'options', array());
             $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array());
             $linkOptions['tabindex'] = '-1';
             $content = \CHtml::link($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
             $lines[] = \CHtml::tag('li', $options, $content);
         }
     }
     return \CHtml::tag('ul', $this->htmlOptions, implode("\n", $lines));
 }
예제 #6
0
 /**
  * Generates the rendering of a breadcrumb item
  * @param string $label
  * @param array $options
  */
 public function renderItem($label, $options = array())
 {
     if ($this->tagName === 'nav') {
         $url = ArrayHelper::removeValue($options, 'href', '#');
         $htmlOptions = ArrayHelper::removeValue($options, 'options', array());
         echo \CHtml::openTag('li', $htmlOptions);
         echo \CHtml::link($label, $url);
         echo \CHtml::closeTag('li');
     } else {
         $htmlOptions = ArrayHelper::removeValue($options, 'options', array());
         echo \CHtml::tag('a', array_merge($htmlOptions, $options), $label);
     }
 }
예제 #7
0
 /**
  * Renders menu items. It differs from [[Dropdown]] widget as it is factorial to render multi-level dropdown menus.
  * @param array $items the items to render
  * @param bool $encodeLabels whether to encode link labels or not
  * @return string the resulting dropdown element.
  * @throws \foundation\exception\InvalidConfigException
  */
 public static function dropdown($items, $encodeLabels = true)
 {
     $li = array();
     foreach ($items as $item) {
         if (is_string($item)) {
             $li[] = $item;
             continue;
         }
         if (!isset($item['label'])) {
             throw new InvalidConfigException("The 'label' option is required.");
         }
         $label = $encodeLabels ? \CHtml::encode($item['label']) : $item['label'];
         $options = ArrayHelper::getValue($item, 'options', array());
         $items = ArrayHelper::getValue($item, 'items');
         $url = \CHtml::normalizeUrl(ArrayHelper::getValue($item, 'url', '#'));
         $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array());
         if (ArrayHelper::getValue($item, 'active')) {
             ArrayHelper::addValue('class', 'active', $options);
         }
         if ($items !== null) {
             ArrayHelper::addValue('class', 'has-dropdown', $options);
             if (is_array($items)) {
                 $items = static::dropdown($items, $encodeLabels);
             }
         }
         $li[] = \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items);
     }
     return \CHtml::tag('ul', array('class' => 'dropdown'), implode("\n", $li));
 }
예제 #8
0
 /**
  * Generates a split button.
  * Important: Currently split buttons require the dropdown list items to be rendered before the body tag, so the
  * dropdown list hides on document.click. You will have to click again on dropdown to hide the list.
  * Please, use the button widget for better performance. At the moment, Foundation uses a hack until its new release 4.2
  * @param $label
  * @param $list
  * @param array $htmlOptions
  * @return string
  */
 public static function split($label, $list, $htmlOptions = array())
 {
     $id = Enum::ID_PREFIX . '-' . ++Html::$count;
     ArrayHelper::addValue('class', Enum::DROPDOWN_SPLIT, $htmlOptions);
     $label .= ' <span data-dropdown="' . $id . '"></span>';
     $dropHtmlOptions = ArrayHelper::removeValue($htmlOptions, 'dropHtmlOptions', array());
     $dropHtmlOptions['id'] = $id;
     ArrayHelper::addValue('class', Enum::DROPDOWN_LIST, $dropHtmlOptions);
     ob_start();
     echo '<div style="position:relative">';
     // hack
     echo static::link($label, $htmlOptions);
     echo Dropdown::display(array('items' => $list, 'htmlOptions' => $dropHtmlOptions));
     echo '</div>';
     return ob_get_clean();
 }
예제 #9
0
 /**
  * Renders the close button.
  * @return string the rendering result
  */
 protected function renderCloseButton()
 {
     if ($this->closeButton !== null) {
         $tag = ArrayHelper::removeValue($this->closeButton, 'tag', 'a');
         $label = ArrayHelper::removeValue($this->closeButton, 'label', '&times;');
         if ($tag === 'button' && !isset($this->closeButton['type'])) {
             $this->closeButton['type'] = 'button';
         }
         Html::addCssClass($this->closeButton, Enum::DIALOG_CLOSE);
         return \CHtml::tag($tag, $this->closeButton, $label);
     } else {
         return null;
     }
 }
예제 #10
0
 /**
  * Generates a callout panel
  *
  * @param string $content the content to display
  * @param array $htmlOptions the HTML attributes of the panel
  * @return string
  */
 public static function callout($content, $htmlOptions = array())
 {
     ArrayHelper::addValue('class', Enum::PANEL_CALLOUT, $htmlOptions);
     return static::panel($content, $htmlOptions);
 }
예제 #11
0
 /**
  * Returns a generated LI tag item
  * @param array $item the item configuration
  * @return string the resulting li tag
  */
 public function renderItem($item)
 {
     $content = ArrayHelper::getValue($item, 'content', '');
     $caption = ArrayHelper::getValue($item, 'caption');
     if ($caption !== null) {
         $caption = \CHtml::tag('div', array('class' => Enum::ORBIT_CAPTION), $caption);
     }
     return \CHtml::tag('li', array(), $content . $caption);
 }
예제 #12
0
 /**
  * Renders a section item
  * @param array $item the section item
  * @return string the section result
  */
 public function renderItem($item)
 {
     $sectionItem = array();
     $sectionItem[] = \CHtml::tag('p', array('class' => 'title', 'data-section-title' => 'data-section-title'), \CHtml::link(ArrayHelper::getValue($item, 'label', 'Section Title'), '#'));
     $options = ArrayHelper::getValue($item, 'options', array());
     Html::addCssClass($options, 'content');
     ArrayHelper::addValue('data-section-content', 'data-section-content', $options);
     $sectionOptions = array();
     if (ArrayHelper::getValue($item, 'active')) {
         ArrayHelper::addValue('class', 'active', $sectionOptions);
     }
     $sectionItem[] = \CHtml::tag('div', $options, ArrayHelper::getValue($item, 'content', 'Section Content'));
     return \CHtml::tag('section', $sectionOptions, implode("\n", $sectionItem));
 }
예제 #13
0
 /**
  * Generates a close link.
  * @param string $label the link label text.
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated link.
  */
 public static function closeLink($label = '&times;', $htmlOptions = array())
 {
     $htmlOptions = ArrayHelper::defaultValue('href', '#', $htmlOptions);
     ArrayHelper::addValue('class', 'close', $htmlOptions);
     return \CHtml::openTag('a', $htmlOptions) . $label . \CHtml::closeTag('a');
 }
예제 #14
0
 /**
  * Renders a clearing (lightbox) item
  * @param array $item
  * @return string the resulting LI tag item
  */
 public function renderItem($item)
 {
     $options = ArrayHelper::getValue($item, 'options', array());
     if (isset($item['featured'])) {
         Html::addCssClass($this->htmlOptions, Enum::ClEARING_FEATURE);
         Html::addCssClass($options, Enum::CLEARING_FEATURE_IMG);
     }
     $imgOptions = array();
     $imgOptions['src'] = ArrayHelper::getValue($item, 'th', '#');
     $imgOptions['data-caption'] = ArrayHelper::getValue($item, 'caption', null);
     $imgOptions['class'] = 'th';
     $url = ArrayHelper::getValue($item, 'img', '#');
     return \CHtml::tag('li', $options, \CHtml::link(\CHtml::tag('img', $imgOptions), $url));
 }
예제 #15
0
 /**
  * Renders a widget's item
  * @param mixed $item the item to render
  * @return string the rendering result.
  * @throws InvalidConfigException
  */
 protected function renderItem($item)
 {
     if (is_string($item)) {
         return $item;
     }
     if (!isset($item['label'])) {
         throw new InvalidConfigException("The 'label' option is required.");
     }
     $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label'];
     $options = ArrayHelper::getValue($item, 'options', array());
     $items = ArrayHelper::getValue($item, 'items');
     $url = \CHtml::normalizeUrl(ArrayHelper::getValue($item, 'url', '#'));
     $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array());
     if (ArrayHelper::getValue($item, Enum::STATE_ACTIVE)) {
         ArrayHelper::addValue('class', Enum::STATE_ACTIVE, $options);
     }
     if ($items !== null) {
         Html::addCssClass($options, Enum::DROPDOWN_HAS);
         if (is_array($items)) {
             $items = Nav::dropdown($items, $this->encodeLabels);
         }
     }
     return \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items);
 }
예제 #16
0
 /**
  * Renders a single stop
  * @param array $stop the stop configuration
  * @return string the resulting li tag
  */
 public function renderStop($stop)
 {
     $options = array();
     $options['data-id'] = ArrayHelper::getValue($stop, 'id');
     $options['data-text'] = ArrayHelper::getValue($stop, 'text');
     $options['data-button'] = ArrayHelper::getValue($stop, 'button');
     $options['data-class'] = ArrayHelper::getValue($stop, 'class');
     $options['data-options'] = ArrayHelper::getValue($stop, 'options');
     if ($options['data-options'] !== null) {
         $config = array();
         foreach ($options['data-options'] as $key => $option) {
             $config[] = $key . ':' . $option;
         }
         $options['data-options'] = implode(';', $config);
     }
     $title = ArrayHelper::getValue($stop, 'title');
     if (!empty($title)) {
         $title = "<h4>{$title}</h4>";
     }
     $content = '<p>' . ArrayHelper::getValue($stop, 'body', '') . '</p>';
     return \CHtml::tag('li', $options, $title . $content);
 }