1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15 Yii::import('bootstrap.helpers.TbHtml');
16 Yii::import('bootstrap.helpers.TbArray');
17 Yii::import('yiiwheels.widgets.gallery.WhGallery');
18
19 class WhCarousel extends WhGallery
20 {
21
22 23 24
25 public function init()
26 {
27 parent::init();
28 $this->pluginOptions['carousel'] = true;
29 $this->pluginOptions['container'] = '#' . $this->htmlOptions['id'] . '-carousel';
30 }
31
32 33 34
35 public function renderLinks()
36 {
37 echo CHtml::openTag('div', $this->htmlOptions);
38 foreach ($this->items as $item) {
39 $url = TbArray::getValue('url', $item, '#');
40 $src = TbArray::getValue('src', $item, '#');
41 $options = TbArray::getValue('options', $item );
42 echo CHtml::link(CHtml::image($src), $url, $options);
43 }
44 echo CHtml::closeTag('div');
45 }
46
47 48 49
50 public function renderTemplate()
51 {
52 $options = array(
53 'id' => $this->htmlOptions['id'] . '-carousel',
54 'class' => 'blueimp-gallery blueimp-gallery-carousel'
55 );
56 if($this->displayControls) {
57 TbHtml::addCssClass('blueimp-gallery-controls', $options);
58 }
59 echo CHtml::openTag('div', $options);
60 echo '<div class="slides"></div>
61 <h3 class="title"></h3>
62 <a class="prev">‹</a>
63 <a class="next">›</a>
64 <a class="play-pause"></a>
65 <ol class="indicator"></ol>';
66 echo CHtml::closeTag('div');
67 }
68
69 70 71
72 public function registerClientScript()
73 {
74 $this->registerGalleryScriptFiles();
75 $selector = $this->htmlOptions['id'];
76 $options = CJavaScript::encode($this->pluginOptions);
77
78 $js = ";$('#{$selector} a').hide();blueimp.Gallery($('#{$selector}')[0].getElementsByTagName('a'),{$options});";
79
80 Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->getId(), $js);
81 }
82
83 }
84