1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: namespace Cakestrap\View\Helper;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
33:
34: class AssetHelper extends Basic
35: {
36: 37: 38: 39: 40:
41: public $helpers = ['Html'];
42:
43: 44: 45: 46: 47:
48: protected $_jquery = '//code.jquery.com/jquery-1.11.3.min.js';
49:
50: 51: 52: 53: 54:
55: protected $_autoScript = [
56: 'Alert' => ['alert'],
57: 'Dropdown' => ['dropdown'],
58: 'Modal' => ['modal'],
59: 'Tab' => ['tab'],
60: 'Collapse' => ['collapse', 'transition'],
61: 'NiceCollapse' => ['collapse', 'transition', 'nice-collapse'],
62: 'NiceModal' => ['modal', 'nice-modal'],
63: ];
64:
65: 66: 67: 68: 69:
70: protected $_script = [];
71:
72: 73: 74: 75: 76:
77: protected $_style = [];
78:
79: 80: 81: 82: 83: 84:
85: public function style($style = [])
86: {
87: if(!empty($style)) {
88: foreach($style as $key=>$value) {
89: $css[] = $this->Html->css($value);
90: }
91:
92: $this->_style = $css;
93: } else {
94: $css[] = $this->Html->css('Cakestrap.bootstrap');
95: $css[] = $this->Html->css('Cakestrap.extend');
96: $css[] = $this->Html->css('Cakestrap.font-awesome');
97: }
98:
99: return implode("", $css) . implode("", $this->_style);
100: }
101:
102: 103: 104: 105: 106: 107:
108: public function script($script = [])
109: {
110: if(!empty($script)) {
111: foreach($script as $key=>$value) {
112: $js[] = $this->Html->script($value);
113: }
114:
115: $this->_script = implode('', $js);
116: }
117:
118: $js[] = $this->Html->script($this->_jquery);
119: $helpers = $this->_View->helpers()->loaded();
120:
121: foreach($helpers as $key=>$value) {
122: if(isset($this->_autoScript[$value])) {
123: foreach($this->_autoScript[$value] as $name) {
124: $js[] = $this->Html->script('Cakestrap.' . strtolower($name));
125: }
126: }
127: }
128:
129: $hasNoScript = !$this->_View->get("Cakestrap.script");
130: if(!$hasNoScript) {
131: $plugin = sprintf('%s.%s', $this->request->params["plugin"], strtolower($this->request->params['controller']));
132: $js[] = $this->Html->script($plugin);
133: }
134:
135: $script = array_merge($js, $this->_script);
136: return implode("", $script);
137: }
138:
139: 140: 141: 142: 143: 144:
145: public function ident($classOrId = null)
146: {
147: $params = $this->request->params;
148: $controller = strtolower($params['controller']);
149: $id = sprintf("%s%s", $controller, ucfirst(strtolower($params['action'])));
150: $class = sprintf("%s-%s", $controller, strtolower($params['action']));
151:
152: if($classOrId) {
153: $class = $classOrId['class'] . "-" . strtolower($classOrId['id']);
154: $id = $classOrId['class'] . ucwords($classOrId['id']);
155: }
156:
157: return sprintf("class='%s' id='%s'", $class, $id);
158: }
159: }