This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathYiiWheels.php
130 lines (114 loc) · 3.53 KB
/
YiiWheels.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* @copyright Copyright (c) 2013 2amigOS! Consulting Group LLC
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
/**
* YiiWheels class file.
* @author Antonio Ramirez <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package yiiwheels
*/
class YiiWheels extends CApplicationComponent
{
/**
* @var array the HTML options for the view container tag.
*/
public $htmlOptions = array();
/**
* @var array $assetsJs of javascript library names to be registered when initializing the library.
*/
public $assetsJs = array();
/**
* @var array $assetsCss of style library names to be registered when initializing the library.
*/
public $assetsCss = array();
/**
* @var TbApi $_api
*/
protected $_api;
/**
* @var string holds the published assets
*/
protected $_assetsUrl;
/**
* Widget's initialization
* @throws CException
*/
public function init()
{
$this->_api = Yii::app()->getComponent('bootstrap');
if (null === $this->_api) {
throw new CException(Yii::t('zii', '"YiiWheels" must work in conjunction with "YiiStrap".'));
}
/* ensure all widgets - plugins are accessible to the library */
Yii::import('bootstrap.widgets.*');
/* ensure common behavior is also accessible to the library */
Yii::import('yiiwheels.behaviors.WhPlugin');
/* register css assets */
foreach ($this->assetsCss as $css) {
$this->registerAssetCss($css);
}
/* register js assets */
foreach ($this->assetsJs as $js) {
$this->registerAssetJs($js);
}
}
/**
* Returns the core library (yiistrap) component
* @return TbApi
*/
public function getApi()
{
return $this->_api;
}
/**
* Returns the assets URL.
* Assets folder has few orphan and very useful utility libraries.
* @return string
*/
public function getAssetsUrl()
{
if (isset($this->_assetsUrl)) {
return $this->_assetsUrl;
} else {
$forceCopyAssets = $this->getApi()->forceCopyAssets;
$path = Yii::getPathOfAlias('yiiwheels');
$assetsUrl = Yii::app()->assetManager->publish(
$path . DIRECTORY_SEPARATOR . 'assets',
false,
-1,
$forceCopyAssets
);
return $this->_assetsUrl = $assetsUrl;
}
}
/**
* Register a specific js file in the asset's js folder
*
* @param string $jsFile
* @param int $position the position of the JavaScript code.
*
* @see CClientScript::registerScriptFile
* @return $this
*/
public function registerAssetJs($jsFile, $position = CClientScript::POS_END)
{
Yii::app()->getClientScript()->registerScriptFile($this->getAssetsUrl() . "/js/{$jsFile}", $position);
return $this;
}
/**
* Registers a specific css in the asset's css folder
*
* @param string $cssFile the css file name to register
* @param string $media the media that the CSS file should be applied to. If empty, it means all media types.
*
* @return $this
*/
public function registerAssetCss($cssFile, $media = '')
{
Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . "/css/{$cssFile}", $media);
return $this;
}
}