-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleFadeSlideShow.php
113 lines (102 loc) · 4.37 KB
/
SimpleFadeSlideShow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
* SimpleFadeSlideShow.php
*
* Copyright 2014 Philipp Roggan <[email protected]>
*
* Dual licensed under GPLv3+ and MIT
* See License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the MIT license used for this program along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* This Yii extension wraps the jQuery plugin "Simple FadeSlideShow"
* from Pascal Bajorat [http://www.simplefadeslideshow.com/]
* which itself also comes dual licensed under GPLv3+ and MIT
*
* @license GPLv3+ & MIT
* @copyright Copyright © 2014 Philipp Roggan
* @link https://github.com/schlypel/Yii-SimpleFadeSlideShow
*
*/
/**
* Set
*/
class SimpleFadeSlideShow extends CWidget{
// options from original jQuery plugin
public $width = 640;
public $height = 480;
public $speed = 'slow'; // speed of animation (jQuery animation values are allowed)
public $interval = 3000; // delay between changes (ms)
public $PlayPauseElement = 'fssPlayPause'; // id for pause/play element
public $PlayText = 'Play'; // play text
public $PauseText = 'Pause'; // pause text
public $NextElement = 'fssNext'; // id for next button
public $NextElementText = 'Next >'; // text on next button
public $PrevElement = 'fssPrev'; // id for previous button
public $PrevElementText = '< Prev'; // text on previous button
public $ListElement = 'fssList'; // id for the list element
public $ListLi = 'fssLi'; // class to assign to each list element
public $ListLiActive = 'fssActive'; // class to assign to the active list element
public $addListToId = false; // insert image list into a html element with this id (false to not wrap)
public $allowKeyboardCtrl = true; // should left and right arrow keys control image flow
public $autoPlay = true; // autoplay active
public $pathToCss = false; // use this to overwrite the default css
//public $pathToArrowImage = false; // use this to overwrite the default arrows image
public $images; // add images as array: [<url1>,<url2>] || [['src'=><url1>,'href'=><link1>,'text'=><title1>],['src'=><url2>,'href'=><link2>,'text'=><title2>]]
protected function registerClientScript(){
$assetsPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.SimpleFadeSlideShow.assets'));
$cssFile = ($this->pathToCss)?$this->pathToCss:$assetsPath."/default.css";
$jsFile = $assetsPath."/simplefadeslideshow/fadeSlideShow.js";
Yii::app()->clientScript->registerCoreScript('jquery');
$cs = Yii::app()->clientScript;
$cs->registerCssFile($cssFile);
$cs->registerScriptFile($jsFile,CClientScript::POS_END);
$this->autoPlay = ($this->autoPlay)?'true':'false';
$this->allowKeyboardCtrl = ($this->allowKeyboardCtrl)?'true':'false';
$cs->registerScript('startSimpleFadeSlideShow',"
;jQuery('#simpleFadeSlideShow_images').fadeSlideShow({
width: ".$this->width.",
height: ".$this->height.",
speed: '".$this->speed."',
interval: ".$this->interval.",
PlayPauseElement: '".(string)$this->PlayPauseElement."',
PlayText: '".(string)$this->PlayText."',
PauseText: '".(string)$this->PauseText."',
NextElement: '".(string)$this->NextElement."',
NextElementText: '".(string)$this->NextElementText."',
PrevElement: '".(string)$this->PrevElement."',
PrevElementText: '".(string)$this->PrevElementText."',
ListElement: '".(string)$this->ListElement."',
ListLi: '".(string)$this->ListLi."',
ListLiActive: '".(string)$this->ListLiActive."',
addListToId: '".(string)$this->addListToId."',
allowKeyboardCtrl: ".$this->allowKeyboardCtrl.",
autoplay: ".$this->autoPlay."
})
",CClientScript::POS_READY);
}
public function init() {
if (is_array($this->images)){
parent::init();
$this->registerClientScript();
}
}
public function run(){
if (is_array($this->images)){
$this->render('simpleFadeSlideShow', array('images'=>$this->images));
}else{
echo '<!-- SimpleFadeSlideShow Widget was loaded without an array of images, no slideshow to see here! -->';
}
parent::run();
}
}
?>