1 <?php
2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 class EFancyboxWidget extends CWidget
18 {
19 20 21
22 public $assetsUrl;
23 24 25
26 public $scriptFile;
27 28 29
30 public $cssFile;
31 32 33 34
35 public $selector='[href$=\'.jpg\'],a[href$=\'.png\'],a[href$=\'.gif\']';
36 37 38 39
40 public $enableMouseWheel=false;
41 42 43
44 public $options=array();
45
46 47 48
49 function init()
50 {
51 if($this->assetsUrl===null)
52 $this->assetsUrl=Yii::app()->getAssetManager()->publish(dirname(__FILE__).'/assets',false,-1,YII_DEBUG);
53
54 if($this->scriptFile===null)
55 $this->scriptFile=YII_DEBUG ? 'jquery.fancybox-1.3.4.js' : 'jquery.fancybox-1.3.4.pack.js';
56
57 if($this->cssFile===null)
58 $this->cssFile='jquery.fancybox-1.3.4.css';
59
60 $this->registerClientScript();
61 }
62 63 64
65 public function run()
66 {
67 }
68 69 70 71
72 protected function registerClientScript()
73 {
74 $cs=Yii::app()->getClientScript();
75 if($this->cssFile!==false)
76 $cs->registerCssFile($this->assetsUrl.'/'.$this->cssFile);
77 $cs->registerCoreScript('jquery');
78 $cs->registerScriptFile($this->assetsUrl.'/'.$this->scriptFile);
79
80 if((isset($this->options['transitionIn']) && $this->options['transitionIn']=='elastic')
81 || (isset($this->options['transitionOut']) && $this->options['transitionOut']=='elastic'))
82 $cs->registerScriptFile($this->assetsUrl.'/jquery.easing-1.3.pack.js');
83
84 if($this->enableMouseWheel)
85 $cs->registerScriptFile($this->assetsUrl.'/jquery.mousewheel-3.0.4.pack.js');
86 $cs->registerScript($this->getId(),'$("'.$this->selector.'").fancybox('.CJavaScript::encode($this->options).');',CClientScript::POS_READY);
87 }
88 }
89