-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeAssets.php
59 lines (54 loc) · 1.43 KB
/
TreeAssets.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
<?php
/**
* @author Капенкин Дмитрий <dkapenkin@rambler.ru>
* @date 26.08.14
* @time 23:21
* Created by JetBrains PhpStorm.
*/
namespace dkeeper\tree;
class TreeAssets extends \yii\web\AssetBundle
{
public $depends = [
'yii\web\JqueryAsset',
];
public function init()
{
$this->setSourcePath(__DIR__ . '/assets');
$this->setupAssets('css', ['css/zTreeStyle']);
$this->setupAssets('js', ['js/jquery.ztree.all-3.5']);
parent::init();
}
/**
* Set up CSS and JS asset arrays based on the base-file names
*
* @param string $type whether 'css' or 'js'
* @param array $files the list of 'css' or 'js' basefile names
*/
protected function setupAssets($type, $files = [])
{
if (empty($this->$type)) {
$srcFiles = [];
$minFiles = [];
foreach ($files as $file) {
$srcFiles[] = "{$file}.{$type}";
$minFiles[] = "{$file}.min.{$type}";
}
$this->$type = YII_DEBUG ? $srcFiles : $minFiles;
} else {
$this->$type = [];
}
}
/**
* Sets the source path if empty
*
* @param string $path the path to be set
*/
protected function setSourcePath($path)
{
if (empty($this->sourcePath)) {
$this->sourcePath = $path;
} else {
$this->sourcePath = '';
}
}
}