Beispiel #1
0
 /**
  * Normalizes the items list and correct urls if any are set.
  *
  * @param  array   $items
  * @param  array   $panes
  * @param  int 	   $i
  * @return array
  */
 protected static function normalize($items, &$panes, &$i = 0)
 {
     $id = Helpers::rand_string(5);
     $tabs = array();
     if (!is_array($items)) {
         return;
     }
     foreach ($items as $key => $item) {
         $tab = $item;
         if (isset($tab['items'])) {
             $tab['items'] = static::normalize($tab['items'], $panes, $i);
         } else {
             if (!isset($tab['content'])) {
                 $tab['content'] = '';
             }
             $tabId = 'tab_' . $id . '_' . $i;
             $tab['attributes'] = array('data-toggle' => 'tab');
             $tab['url'] = '#' . $tabId;
             $class = 'tab-pane';
             if (isset($tab['active']) && $tab['active']) {
                 $class .= ' active';
             }
             $panes[] = '<div class="' . $class . '" id="' . $tabId . '">' . $tab['content'] . '</div>';
             unset($tab['content']);
             $i++;
         }
         $tabs[] = $tab;
     }
     return $tabs;
 }
Beispiel #2
0
 /**
  * Create a Bootstrap carousel. Returns the HTML for the carousel.
  *
  * @param  array   $items
  * @param  array   $attributes
  * @return Carousel
  */
 public static function create($items, $attributes = array())
 {
     $attributes = Helpers::add_class($attributes, 'carousel slide');
     if (!isset($attributes['id'])) {
         $attributes['id'] = "carousel_" . Helpers::rand_string(5);
     }
     $html = '<div' . HTML::attributes($attributes) . '>';
     $html .= '<div class="carousel-inner">';
     $first = true;
     foreach ($items as $item) {
         $html .= static::createItem($item, $first);
         $first = false;
     }
     $html .= '</div>';
     $html .= '<a class="carousel-control left" href="#' . $attributes['id'] . '" data-slide="prev">' . Carousel::$prev . '</a>';
     $html .= '<a class="carousel-control right" href="#' . $attributes['id'] . '" data-slide="next">' . Carousel::$next . '</a>';
     $html .= '</div>';
     return $html;
 }
 /**
  * Creates a new Carousel instance
  *
  * @param array $items      The items to use as pictures
  * @param array $attributes Its attributes
  */
 public function __construct($items, $attributes = array())
 {
     $this->items = $items;
     $this->attributes = Helpers::add_class($attributes, 'carousel slide');
     // Set default active item
     $this->active = key($items);
     // Calculate the Carousel ID
     $this->hash = '#' . array_get($attributes, 'id', 'carousel_' . Helpers::rand_string(5));
 }
 /**
  * Normalizes the items list and correct urls if any are set.
  *
  * @param array $items Tab items
  * @param array &$panes array of panes
  * @param int   &$i     index
  *
  * @return array
  */
 protected static function normalize($items, &$panes, &$i = 0)
 {
     $id = Helpers::rand_string(5);
     $tabs = array();
     if (!is_array($items)) {
         return false;
     }
     foreach ($items as $key => $tab) {
         $url = '#';
         if (isset($tab['items'])) {
             $tab['items'] = static::normalize($tab['items'], $panes, $i);
         } else {
             if (!isset($tab['url'])) {
                 $tab['url'] = '';
             }
             $tabId = 'tab_' . $id . '_' . $i;
             //if not disabled set toggle and url
             if (!isset($tab['disabled']) || !$tab['disabled']) {
                 $tab['attributes'] = array('data-toggle' => 'tab');
                 $url .= $tabId;
             }
             $class = 'tab-pane';
             if (isset($tab['active']) && $tab['active']) {
                 $class .= ' active';
             }
             $panes[] = '<div class="' . $class . '" id="' . $tabId . '">' . $tab['url'] . '</div>';
             $tab['url'] = $url;
             $i++;
         }
         $tabs[] = $tab;
     }
     return $tabs;
 }