/
behavior.php
264 lines (229 loc) · 7.28 KB
/
behavior.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
/**
* Joomlatools Framework - https://www.joomlatools.com/developer/framework/
*
* @copyright Copyright (C) 2007 Johan Janssens and Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link https://github.com/joomlatools/joomlatools-framework for the canonical source repository
*/
/**
* Behavior Template Helper
*
* @author Johan Janssens <https://github.com/johanjanssens>
* @package Koowa\Component\Koowa\Template\Helper
*/
class ComKoowaTemplateHelperBehavior extends KTemplateHelperBehavior
{
/**
* Loads koowa.js
*
* @param array|KObjectConfig $config
* @return string
*/
public function koowa($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::koowa($config);
}
/**
* Loads Vue.js
*
* @param array|KObjectConfig $config
* @return string
*/
public function vue($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::vue($config);
}
/**
* Loads Modernizr
*
* @param array|KObjectConfig $config
* @return string
*/
public function modernizr($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::modernizr($config);
}
/**
* Loads KUI initialize
*
* @param array|KObjectConfig $config
* @return string
*/
public function kodekitui($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::kodekitui($config);
}
public function modal($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::modal($config);
}
/**
* Loads jQuery under a global variable called kQuery.
*
* Loads it from Joomla in 3.0+ and our own sources in 2.5. If debug config property is set, an uncompressed
* version will be included.
*
* You can do window.jQuery = window.$ = window.kQuery; to use the default names
*
* @param array|KObjectConfig $config
* @return string
*/
public function jquery($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
$html = '';
if ($this->getTemplate()->decorator() === 'joomla')
{
if (class_exists('JHtml') && !static::isLoaded('jquery'))
{
JHtml::_('jquery.framework');
// Can't use JHtml here as it makes a file_exists call on koowa.kquery.js?version
$path = JUri::root(true).'/media/koowa/framework/js/koowa.kquery.js?'.substr(md5(Koowa::VERSION), 0, 8);
JFactory::getDocument()->addScript($path);
static::setLoaded('jquery');
}
}
else $html .= parent::jquery($config);
return $html;
}
/**
* Add Bootstrap JS and CSS a modal box
*
* @param array|KObjectConfig $config
* @return string The html output
*/
public function bootstrap($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
$html = '';
if (class_exists('JHtml') && $this->getTemplate()->decorator() === 'joomla')
{
$config->append([
'css' => file_exists(JPATH_THEMES.'/'.JFactory::getApplication()->getTemplate().'/enable-koowa-bootstrap.txt')
]);
if ($config->javascript && !static::isLoaded('bootstrap-javascript'))
{
$html .= $this->jquery($config);
JHtml::_('bootstrap.framework');
static::setLoaded('bootstrap-javascript');
$config->javascript = false;
}
}
$html .= parent::bootstrap($config);
return $html;
}
/**
* Loads the Forms.Validator class and connects it to Koowa.Controller.Form
*
* @param array|KObjectConfig $config
* @return string The html output
*/
public function validator($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::validator($config);
}
/**
* Loads the select2 behavior and attaches it to a specified element
*
* @see http://ivaynberg.github.io/select2/select-2.1.html
*
* @param array|KObjectConfig $config
* @return string The html output
*/
public function select2($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::select2($config);
}
/**
* Loads the Koowa customized jQtree behavior and renders a sidebar-nav list useful in split views
*
* @see http://mbraak.github.io/jqTree/
*
* @note If no 'element' option is passed, then only assets will be loaded.
*
* @param array|KObjectConfig $config
* @throws InvalidArgumentException
* @return string The html output
*/
public function tree($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::tree($config);
}
/**
* Loads the calendar behavior and attaches it to a specified element
*
* @param array|KObjectConfig $config
* @return string The html output
*/
public function calendar($config = array())
{
$config = new KObjectConfigJson($config);
if ($config->filter) {
$config->offset = strtoupper($config->filter); // @TODO Backwards compatibility
}
$config->append(array(
'debug' => JFactory::getConfig()->get('debug'),
'server_offset' => JFactory::getConfig()->get('offset'),
'first_week_day' => JFactory::getLanguage()->getFirstDay(),
'options' => array(
'language' => JFactory::getLanguage()->getTag(),
)
));
return parent::calendar($config);
}
/**
* Loads Alpine.js
*
* If debug config property is set, an uncompressed version will be included.
*
* @param array|KObjectConfig $config
* @return string
*/
public function alpine($config = array())
{
$config = new KObjectConfigJson($config);
$config->append(array(
'debug' => JFactory::getConfig()->get('debug')
));
return parent::alpine($config);
}
}