YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Alert
  • Breadcrumbs
  • Clearing
  • Dropdown
  • FlexVideo
  • Interchange
  • JoyRide
  • Magellan
  • Orbit
  • Pager
  • Reveal
  • Section
  • SwitchButton
  • Tooltip
  • TopBar
 1 <?php
 2 /**
 3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
 4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 5  * @package foundation.components
 6  * @version 1.0.0
 7  */
 8 namespace foundation\widgets;
 9 
10 use foundation\helpers\ArrayHelper;
11 use foundation\helpers\Html;
12 use foundation\enum\Enum;
13 
14 /**
15  * Clearing creates responsive lightboxes with any size image
16  *
17  * @see http://foundation.zurb.com/docs/components/clearing.html
18  *
19  * @author Antonio Ramirez <amigo.cobos@gmail.com>
20  * @package foundation\widgets
21  */
22 class Clearing extends base\Widget
23 {
24     /**
25      * @var array $items the items to be displayed on the gallery. The syntax is the following:
26      *
27      * <pre>
28      * 'items' => array(
29      *      array(
30      *          'img' => 'large image source',
31      *          'th' => 'thumbnail image',
32      *          'featured' => true, // whether is featured image or not
33      *          'caption' => 'caption of the image',
34      *          'options' => array(...)
35      *      )
36      * )
37      * </pre>
38      */
39     public $items;
40 
41 
42     /**
43      * Initializes the widget
44      */
45     public function init()
46     {
47         $this->assets = array(
48             'js' => YII_DEBUG ? 'foundation/foundation.clearing.js' : 'foundation.min.js'
49         );
50         Html::addCssClass($this->htmlOptions, Enum::CLEARING_THUMBS);
51         ArrayHelper::addValue('data-clearing', 'data-clearing', $this->htmlOptions);
52         parent::init();
53     }
54 
55     /**
56      * Renders the widget
57      */
58     public function run()
59     {
60         echo $this->renderClearing();
61     }
62 
63     /**
64      * Renders the clearing widget
65      * @return bool|string the resulting element
66      */
67     public function renderClearing()
68     {
69         if (empty($this->items)) {
70             return true;
71         }
72         $list = array();
73         foreach ($this->items as $item) {
74             $list[] = $this->renderItem($item);
75         }
76         return \CHtml::tag('ul', $this->htmlOptions, implode("\n", $list));
77     }
78 
79     /**
80      * Renders a clearing (lightbox) item
81      * @param array $item
82      * @return string the resulting LI tag item
83      */
84     public function renderItem($item)
85     {
86         $options = ArrayHelper::getValue($item, 'options', array());
87         if (isset($item['featured'])) {
88             Html::addCssClass($this->htmlOptions, Enum::ClEARING_FEATURE);
89             Html::addCssClass($options, Enum::CLEARING_FEATURE_IMG);
90         }
91         $imgOptions                 = array();
92         $imgOptions['src']          = ArrayHelper::getValue($item, 'th', '#');
93         $imgOptions['data-caption'] = ArrayHelper::getValue($item, 'caption', null);
94         $url                        = ArrayHelper::getValue($item, 'img', '#');
95 
96         return \CHtml::tag('li', $options, \CHtml::link(\CHtml::tag('img', $imgOptions), $url));
97 
98     }
99 }
YiiFoundation API documentation generated by ApiGen 2.8.0