1 | <?php |
||
78 | class Slider extends Widget |
||
79 | { |
||
80 | /** |
||
81 | * @var string|integer |
||
82 | * 'id' => 'myId', |
||
83 | */ |
||
84 | public $id = ''; |
||
85 | |||
86 | /** |
||
87 | * Items |
||
88 | * @var array |
||
89 | * |
||
90 | * [ |
||
91 | * '<h1>Slide 1</h1><p>Text 1</p>', |
||
92 | * '<h1>Slide 2</h1><p>Text 2</p>', |
||
93 | * '...', |
||
94 | * ] |
||
95 | */ |
||
96 | public $items = []; |
||
97 | |||
98 | /** |
||
99 | * @var array |
||
100 | * @see http://sachinchoolur.github.io/lightslider/ |
||
101 | */ |
||
102 | public $clientOptions = []; |
||
103 | |||
104 | /** |
||
105 | * List Options |
||
106 | * @var array |
||
107 | * 'listOptions' => ['class' => 'myListCssClass'] |
||
108 | */ |
||
109 | public $listOptions = []; |
||
110 | |||
111 | /** |
||
112 | * Items options |
||
113 | * @var array |
||
114 | * 'itemOptions' => ['class' => 'myItemsCssClass'] |
||
115 | */ |
||
116 | public $itemOptions = []; |
||
117 | |||
118 | /** |
||
119 | * @var integer|string |
||
120 | */ |
||
121 | private $_selector; |
||
122 | |||
123 | /** |
||
124 | * @var array |
||
125 | */ |
||
126 | private $_options = []; |
||
127 | |||
128 | /** |
||
129 | * Initializes the widget. |
||
130 | */ |
||
131 | 3 | public function init() |
|
138 | |||
139 | /** |
||
140 | * Renders widget |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | 2 | public function run() |
|
144 | { |
||
145 | 2 | if (!empty($this->items)) { |
|
146 | 2 | $this->registerAssets(); |
|
147 | 2 | echo Html::beginTag('ul', $this->listOptions) . PHP_EOL; |
|
148 | 2 | if (ArrayHelper::isAssociative($this->items[0])) { |
|
149 | 1 | $this->renderGalleryItems(); |
|
150 | } else { |
||
151 | 1 | $this->renderSliderItems(); |
|
152 | } |
||
153 | 2 | echo Html::endTag('ul') . PHP_EOL; |
|
154 | } |
||
155 | 2 | } |
|
156 | |||
157 | /** |
||
158 | * Render Slider Items |
||
159 | */ |
||
160 | 1 | public function renderSliderItems() |
|
166 | |||
167 | /** |
||
168 | * Render Gallery Items |
||
169 | */ |
||
170 | 1 | public function renderGalleryItems() |
|
171 | { |
||
172 | 1 | foreach ($this->items as $item) { |
|
173 | 1 | $itemData = []; |
|
174 | 1 | if (isset($item['options'])) { |
|
175 | 1 | foreach ($item['options'] as $key => $data) { |
|
176 | 1 | $itemData[$key] = $data; |
|
177 | } |
||
178 | } |
||
179 | 1 | $itemOptions = ArrayHelper::merge($itemData, $this->itemOptions); |
|
180 | 1 | echo Html::tag('li', $item['item'], $itemOptions) . PHP_EOL; |
|
181 | } |
||
182 | 1 | } |
|
183 | |||
184 | /** |
||
185 | * Set client options |
||
186 | * @return array |
||
187 | */ |
||
188 | 3 | public function getOptions() |
|
193 | |||
194 | /** |
||
195 | * Register resource |
||
196 | */ |
||
197 | 2 | public function registerAssets() |
|
210 | } |
||
211 |