-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript_manager.php
More file actions
87 lines (76 loc) · 1.48 KB
/
Script_manager.php
File metadata and controls
87 lines (76 loc) · 1.48 KB
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
<?php
namespace core_view;
/**
*
*/
class Script_manager
{
private $scripts = array();
function __construct()
{
}
public function add_js($src, $group = 'default')
{
if(isset($this->scripts[$src])) {
$this->scripts[$src]->group($group);
} else {
$this->scripts[$src] = new Script_manager_js_tag($src);
$this->scripts[$src]->group($group);
return $this->scripts[$src];
}
}
public function add_css($src, $group = 'default')
{
if(isset($this->scripts[$src])) {
$this->scripts[$src]->group($group);
} else {
$this->scripts[$src] = new Script_manager_css_tag($src);
$this->scripts[$src]->group($group);
return $this->scripts[$src];
}
}
public function render($group = 'default')
{
foreach ($this->scripts as $value) {
if($value->group() == $group){
echo $value->__toString();
}
}
}
}
class Script_manager_js_tag extends Html_tag
{
protected $group;
function __construct($src)
{
parent::__construct('script');
$this->attr('src', $src);
}
public function group($value = NULL)
{
if($value === NULL) {
return $this->group;
} else {
$this->group = $value;
return $this;
}
}
}
class Script_manager_css_tag extends Html_tag
{
protected $group;
function __construct($src)
{
parent::__construct('link', FALSE);
$this->attr('rel', 'stylesheet')->attr('href', $src);
}
public function group($value = NULL)
{
if($value === NULL) {
return $this->group;
} else {
$this->group = $value;
return $this;
}
}
}