-
Notifications
You must be signed in to change notification settings - Fork 2
/
JqplotWidget.php
executable file
·72 lines (58 loc) · 2.06 KB
/
JqplotWidget.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
<?php
abstract class JqplotWidget extends CWidget{
public $scriptUrl;
public $themeUrl;
public $theme='base';
public $scriptFile=array('excanvas.min.js','jquery.jqplot.js');
public $pluginScriptFile=array();
public $cssFile=array('jquery.jqplot.css');
public $data=array();
public $options=array();
public $htmlOptions=array();
public function init(){
$this->resolvePackagePath();
$this->registerCoreScripts();
parent::init();
}
protected function resolvePackagePath(){
if($this->scriptUrl===null || $this->themeUrl===null){
$basePath=Yii::getPathOfAlias('application.extensions.jqplot.assets');
$baseUrl=Yii::app()->getAssetManager()->publish($basePath);
if($this->scriptUrl===null)
$this->scriptUrl=$baseUrl.'';
if($this->themeUrl===null)
$this->themeUrl=$baseUrl.'';
}
}
protected function registerCoreScripts(){
$cs=Yii::app()->getClientScript();
if(is_string($this->cssFile))
$this->registerCssFile($this->cssFile);
else if(is_array($this->cssFile)){
foreach($this->cssFile as $cssFile)
$this->registerCssFile($cssFile);
}
$cs->registerCoreScript('jquery');
if(is_string($this->scriptFile))
$this->registerScriptFile($this->scriptFile);
else if(is_array($this->scriptFile)){
foreach($this->scriptFile as $scriptFile)
$this->registerScriptFile($scriptFile);
}
if(is_string($this->pluginScriptFile))
$this->registerPluginScriptFile($this->pluginScriptFile);
else if(is_array($this->pluginScriptFile)){
foreach($this->pluginScriptFile as $scriptFile)
$this->registerPluginScriptFile($scriptFile);
}
}
protected function registerScriptFile($fileName,$position=CClientScript::POS_END){
Yii::app()->clientScript->registerScriptFile($this->scriptUrl.'/'.$fileName,$position);
}
protected function registerPluginScriptFile($fileName,$position=CClientScript::POS_END){
Yii::app()->clientScript->registerScriptFile($this->scriptUrl.'/plugins/'.$fileName,$position);
}
protected function registerCssFile($fileName){
Yii::app()->clientScript->registerCssFile($this->themeUrl.'/'.$fileName);
}
}