1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax; |
4
|
|
|
|
5
|
|
|
use Ajax\service\PhalconUtils; |
6
|
|
|
use Ajax\service\JString; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* JQuery Phalcon library |
10
|
|
|
* |
11
|
|
|
* @author jcheron |
12
|
|
|
* @version 1.002 |
13
|
|
|
* @license Apache 2 http://www.apache.org/licenses/ |
14
|
|
|
*/ |
15
|
|
|
/** |
16
|
|
|
* jQuery Class |
17
|
|
|
*/ |
18
|
|
|
class Jquery { |
19
|
|
|
protected $_di; |
20
|
|
|
protected $_ui; |
21
|
|
|
protected $_bootstrap; |
22
|
|
|
protected $libraryFile; |
23
|
|
|
protected $_javascript_folder='js'; |
24
|
|
|
protected $jquery_code_for_load=array (); |
25
|
|
|
protected $jquery_code_for_compile=array (); |
26
|
|
|
protected $jquery_corner_active=FALSE; |
27
|
|
|
protected $jquery_table_sorter_active=FALSE; |
28
|
|
|
protected $jquery_table_sorter_pager_active=FALSE; |
29
|
|
|
protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
30
|
|
|
protected $jquery_events=array ( |
31
|
|
|
"bind","blur","change","click","dblclick","delegate","die","error","focus","focusin","focusout","hover","keydown","keypress","keyup","live","load","mousedown","mousseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","off","on","one","ready","resize","scroll","select","submit","toggle","trigger","triggerHandler","undind","undelegate","unload" |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
public function setDi($di) { |
35
|
|
|
$this->_di=$di; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function ui($ui=NULL) { |
39
|
|
|
if ($ui!==NULL) { |
40
|
|
|
$this->_ui=$ui; |
41
|
|
|
} |
42
|
|
|
return $this->_ui; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function bootstrap($bootstrap=NULL) { |
46
|
|
|
if ($bootstrap!==NULL) { |
47
|
|
|
$this->_bootstrap=$bootstrap; |
48
|
|
|
} |
49
|
|
|
return $this->_bootstrap; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __construct($params) { |
53
|
|
|
$this->params=array(); |
|
|
|
|
54
|
|
|
foreach ( $params as $key => $val ) { |
55
|
|
|
$this->params[$key]=$params[$key]; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// -------------------------------------------------------------------- |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Inline |
63
|
|
|
* |
64
|
|
|
* Outputs a <script> tag |
65
|
|
|
* |
66
|
|
|
* @access public |
67
|
|
|
* @param string $script |
68
|
|
|
* @param boolean $cdata a CDATA section should be added |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function inline($script, $cdata=TRUE) { |
|
|
|
|
72
|
|
|
$str=$this->_open_script(); |
73
|
|
|
$str.=($cdata) ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n"; |
74
|
|
|
$str.=$this->_close_script(); |
75
|
|
|
|
76
|
|
|
return $str; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// -------------------------------------------------------------------- |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Open Script |
83
|
|
|
* |
84
|
|
|
* Outputs an opening <script> |
85
|
|
|
* |
86
|
|
|
* @access private |
87
|
|
|
* @param string $src |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
private function _open_script($src='') { |
91
|
|
|
$str='<script type="text/javascript" '; |
92
|
|
|
$str.=($src=='') ? '>' : ' src="'.$src.'">'; |
93
|
|
|
return $str; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// -------------------------------------------------------------------- |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Close Script |
100
|
|
|
* |
101
|
|
|
* Outputs an closing </script> |
102
|
|
|
* |
103
|
|
|
* @param string |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
private function _close_script($extra="\n") { |
107
|
|
|
return "</script>{$extra}"; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getLibraryScript() { |
111
|
|
|
$assets=$this->_di->get('assets'); |
112
|
|
|
$assets->addJs($this->libraryFile); |
113
|
|
|
return $assets->outputJs(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setLibraryFile($name) { |
117
|
|
|
$this->libraryFile=$name; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function _setAjaxLoader($loader) { |
121
|
|
|
$this->ajaxLoader=$loader; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// -------------------------------------------------------------------- |
125
|
|
|
// Event Code |
126
|
|
|
// -------------------------------------------------------------------- |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Blur |
130
|
|
|
* |
131
|
|
|
* Outputs a jQuery blur event |
132
|
|
|
* |
133
|
|
|
* @param string The element to attach the event to |
134
|
|
|
* @param string The code to execute |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function _blur($element='this', $js='') { |
138
|
|
|
return $this->_add_event($element, $js, 'blur'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// -------------------------------------------------------------------- |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Change |
145
|
|
|
* |
146
|
|
|
* Outputs a jQuery change event |
147
|
|
|
* |
148
|
|
|
* @param string The element to attach the event to |
149
|
|
|
* @param string The code to execute |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function _change($element='this', $js='') { |
153
|
|
|
return $this->_add_event($element, $js, 'change'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
// -------------------------------------------------------------------- |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Outputs a jQuery click event |
160
|
|
|
* |
161
|
|
|
* @param string $element The element to attach the event to |
162
|
|
|
* @param mixed $js The code to execute |
163
|
|
|
* @param boolean $ret_false whether or not to return false |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function _click($element='this', $js=array(), $ret_false=TRUE) { |
167
|
|
|
if (!is_array($js)) { |
168
|
|
|
$js=array ( |
169
|
|
|
$js |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if ($ret_false) { |
174
|
|
|
$js[]="return false;"; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this->_add_event($element, $js, 'click'); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Outputs a jQuery contextmenu event |
182
|
|
|
* |
183
|
|
|
* @param string The element to attach the event to |
184
|
|
|
* @param string The code to execute |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
public function _contextmenu($element='this', $js='') { |
188
|
|
|
return $this->_add_event($element, $js, 'contextmenu'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
// -------------------------------------------------------------------- |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Outputs a jQuery dblclick event |
195
|
|
|
* |
196
|
|
|
* @param string The element to attach the event to |
197
|
|
|
* @param string The code to execute |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function _dblclick($element='this', $js='') { |
201
|
|
|
return $this->_add_event($element, $js, 'dblclick'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// -------------------------------------------------------------------- |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Outputs a jQuery error event |
208
|
|
|
* |
209
|
|
|
* @param string The element to attach the event to |
210
|
|
|
* @param string The code to execute |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public function _error($element='this', $js='') { |
214
|
|
|
return $this->_add_event($element, $js, 'error'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// -------------------------------------------------------------------- |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Outputs a jQuery focus event |
221
|
|
|
* |
222
|
|
|
* @param string The element to attach the event to |
223
|
|
|
* @param string The code to execute |
224
|
|
|
* @return string |
225
|
|
|
*/ |
226
|
|
|
public function _focus($element='this', $js='') { |
227
|
|
|
return $this->_add_event($element, $js, 'focus'); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
// -------------------------------------------------------------------- |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Outputs a jQuery hover event |
234
|
|
|
* |
235
|
|
|
* @param string - element |
236
|
|
|
* @param string - Javascript code for mouse over |
237
|
|
|
* @param string - Javascript code for mouse out |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function _hover($element='this', $over, $out) { |
241
|
|
|
$event="\n\t$(".$this->_prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
242
|
|
|
|
243
|
|
|
$this->jquery_code_for_compile[]=$event; |
244
|
|
|
|
245
|
|
|
return $event; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
// -------------------------------------------------------------------- |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Outputs a jQuery keydown event |
252
|
|
|
* |
253
|
|
|
* @param string The element to attach the event to |
254
|
|
|
* @param string The code to execute |
255
|
|
|
* @return string |
256
|
|
|
*/ |
257
|
|
|
public function _keydown($element='this', $js='') { |
258
|
|
|
return $this->_add_event($element, $js, 'keydown'); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
// -------------------------------------------------------------------- |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Outputs a jQuery keypress event |
265
|
|
|
* |
266
|
|
|
* @param string The element to attach the event to |
267
|
|
|
* @param string The code to execute |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
|
|
public function _keypress($element='this', $js='') { |
271
|
|
|
return $this->_add_event($element, $js, 'keypress'); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// -------------------------------------------------------------------- |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Outputs a jQuery keydown event |
278
|
|
|
* |
279
|
|
|
* @param string The element to attach the event to |
280
|
|
|
* @param string The code to execute |
281
|
|
|
* @return string |
282
|
|
|
*/ |
283
|
|
|
public function _keyup($element='this', $js='') { |
284
|
|
|
return $this->_add_event($element, $js, 'keyup'); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
// -------------------------------------------------------------------- |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Outputs a jQuery load event |
291
|
|
|
* |
292
|
|
|
* @param string The element to attach the event to |
293
|
|
|
* @param string The code to execute |
294
|
|
|
* @return string |
295
|
|
|
*/ |
296
|
|
|
public function _load($element='this', $js='') { |
297
|
|
|
return $this->_add_event($element, $js, 'load'); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
// -------------------------------------------------------------------- |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Outputs a jQuery mousedown event |
304
|
|
|
* |
305
|
|
|
* @param string The element to attach the event to |
306
|
|
|
* @param string The code to execute |
307
|
|
|
* @return string |
308
|
|
|
*/ |
309
|
|
|
public function _mousedown($element='this', $js='') { |
310
|
|
|
return $this->_add_event($element, $js, 'mousedown'); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
// -------------------------------------------------------------------- |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Outputs a jQuery mouseout event |
317
|
|
|
* |
318
|
|
|
* @param string The element to attach the event to |
319
|
|
|
* @param string The code to execute |
320
|
|
|
* @return string |
321
|
|
|
*/ |
322
|
|
|
public function _mouseout($element='this', $js='') { |
323
|
|
|
return $this->_add_event($element, $js, 'mouseout'); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
// -------------------------------------------------------------------- |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Outputs a jQuery mouseover event |
330
|
|
|
* |
331
|
|
|
* @param string The element to attach the event to |
332
|
|
|
* @param string The code to execute |
333
|
|
|
* @return string |
334
|
|
|
*/ |
335
|
|
|
public function _mouseover($element='this', $js='') { |
336
|
|
|
return $this->_add_event($element, $js, 'mouseover'); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
// -------------------------------------------------------------------- |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Outputs a jQuery mouseup event |
343
|
|
|
* |
344
|
|
|
* @param string The element to attach the event to |
345
|
|
|
* @param string The code to execute |
346
|
|
|
* @return string |
347
|
|
|
*/ |
348
|
|
|
public function _mouseup($element='this', $js='') { |
349
|
|
|
return $this->_add_event($element, $js, 'mouseup'); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
// -------------------------------------------------------------------- |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Outputs script directly |
356
|
|
|
* |
357
|
|
|
* @param string The element to attach the event to |
358
|
|
|
* @param string The code to execute |
359
|
|
|
* @return string |
360
|
|
|
*/ |
361
|
|
|
public function _output($array_js='') { |
362
|
|
|
if (!is_array($array_js)) { |
363
|
|
|
$array_js=array ( |
364
|
|
|
$array_js |
365
|
|
|
); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
foreach ( $array_js as $js ) { |
369
|
|
|
$this->jquery_code_for_compile[]="\t$js\n"; |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
// -------------------------------------------------------------------- |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Outputs a jQuery resize event |
377
|
|
|
* |
378
|
|
|
* @param string The element to attach the event to |
379
|
|
|
* @param string The code to execute |
380
|
|
|
* @return string |
381
|
|
|
*/ |
382
|
|
|
public function _resize($element='this', $js='') { |
383
|
|
|
return $this->_add_event($element, $js, 'resize'); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
// -------------------------------------------------------------------- |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Outputs a jQuery scroll event |
390
|
|
|
* |
391
|
|
|
* @param string The element to attach the event to |
392
|
|
|
* @param string The code to execute |
393
|
|
|
* @return string |
394
|
|
|
*/ |
395
|
|
|
public function _scroll($element='this', $js='') { |
396
|
|
|
return $this->_add_event($element, $js, 'scroll'); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
// -------------------------------------------------------------------- |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Outputs a jQuery unload event |
403
|
|
|
* |
404
|
|
|
* @param string The element to attach the event to |
405
|
|
|
* @param string The code to execute |
406
|
|
|
* @return string |
407
|
|
|
*/ |
408
|
|
|
public function _unload($element='this', $js='') { |
409
|
|
|
return $this->_add_event($element, $js, 'unload'); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// -------------------------------------------------------------------- |
413
|
|
|
// Effects |
414
|
|
|
// -------------------------------------------------------------------- |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Insert content, specified by the parameter, after each element in the set of matched elements |
418
|
|
|
* @param string $element |
419
|
|
|
* @param string $value |
420
|
|
|
* @param boolean $immediatly defers the execution if set to false |
421
|
|
|
* @return string |
422
|
|
|
*/ |
423
|
|
|
public function after($element='this', $value='', $immediatly=false){ |
424
|
|
|
$element=$this->_prep_element($element); |
425
|
|
|
$value=$this->_prep_value($value); |
426
|
|
|
$str="$({$element}).after({$value});"; |
427
|
|
|
if ($immediatly) |
428
|
|
|
$this->jquery_code_for_compile[]=$str; |
429
|
|
|
return $str; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Get or set the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element. |
434
|
|
|
* @param string $element |
435
|
|
|
* @param string $attributeName |
436
|
|
|
* @param string $value |
437
|
|
|
* @param boolean $immediatly delayed if false |
438
|
|
|
*/ |
439
|
|
View Code Duplication |
public function _attr($element='this', $attributeName, $value="", $immediatly=false) { |
|
|
|
|
440
|
|
|
$element=$this->_prep_element($element); |
441
|
|
|
if (isset($value)) { |
442
|
|
|
$value=$this->_prep_value($value); |
443
|
|
|
$str="$({$element}).attr(\"$attributeName\",{$value});"; |
444
|
|
|
} else |
445
|
|
|
$str="$({$element}).attr(\"$attributeName\");"; |
446
|
|
|
if ($immediatly) |
447
|
|
|
$this->jquery_code_for_compile[]=$str; |
448
|
|
|
return $str; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Execute a generic jQuery call with a value. |
453
|
|
|
* @param string $jQueryCall |
454
|
|
|
* @param string $element |
455
|
|
|
* @param string $param |
456
|
|
|
* @param boolean $immediatly delayed if false |
457
|
|
|
*/ |
458
|
|
View Code Duplication |
public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
|
|
|
459
|
|
|
$element=$this->_prep_element($element); |
460
|
|
|
if (isset($param)) { |
461
|
|
|
$param=$this->_prep_value($param); |
462
|
|
|
$str="$({$element}).{$jQueryCall}({$param});"; |
463
|
|
|
} else |
464
|
|
|
$str="$({$element}).{$jQueryCall}();"; |
465
|
|
|
if ($immediatly) |
466
|
|
|
$this->jquery_code_for_compile[]=$str; |
467
|
|
|
return $str; |
468
|
|
|
} |
469
|
|
|
/** |
470
|
|
|
* Execute a generic jQuery call with 2 elements. |
471
|
|
|
* @param string $jQueryCall |
472
|
|
|
* @param string $to |
473
|
|
|
* @param string $element |
474
|
|
|
* @param boolean $immediatly delayed if false |
475
|
|
|
* @return string |
476
|
|
|
*/ |
477
|
|
|
public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
478
|
|
|
$to=$this->_prep_element($to); |
479
|
|
|
$element=$this->_prep_element($element); |
480
|
|
|
$str="$({$to}).{$jQueryCall}({$element});"; |
481
|
|
|
if ($immediatly) |
482
|
|
|
$this->jquery_code_for_compile[]=$str; |
483
|
|
|
return $str; |
484
|
|
|
} |
485
|
|
|
// -------------------------------------------------------------------- |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Outputs a jQuery animate event |
489
|
|
|
* |
490
|
|
|
* @param string $element element |
491
|
|
|
* @param string|array $params One of 'slow', 'normal', 'fast', or time in milliseconds |
492
|
|
|
* @param string $speed |
493
|
|
|
* @param string $extra |
494
|
|
|
* @param boolean $immediatly delayed if false |
495
|
|
|
* @return string |
496
|
|
|
*/ |
497
|
|
|
public function _animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
498
|
|
|
$element=$this->_prep_element($element); |
499
|
|
|
$speed=$this->_validate_speed($speed); |
500
|
|
|
|
501
|
|
|
$animations="\t\t\t"; |
502
|
|
|
if (is_array($params)) { |
503
|
|
|
foreach ( $params as $param => $value ) { |
504
|
|
|
$animations.=$param.': \''.$value.'\', '; |
505
|
|
|
} |
506
|
|
|
} |
507
|
|
|
$animations=substr($animations, 0, -2); // remove the last ", " |
508
|
|
|
|
509
|
|
|
if ($speed!='') { |
510
|
|
|
$speed=', '.$speed; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
if ($extra!='') { |
514
|
|
|
$extra=', '.$extra; |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
$str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
518
|
|
|
|
519
|
|
|
if ($immediatly) |
520
|
|
|
$this->jquery_code_for_compile[]=$str; |
521
|
|
|
return $str; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
// -------------------------------------------------------------------- |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Outputs a jQuery hide event |
528
|
|
|
* |
529
|
|
|
* @param string $element element |
530
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
531
|
|
|
* @param string $callback Javascript callback function |
532
|
|
|
* @param boolean $immediatly delayed if false |
533
|
|
|
* @return string |
534
|
|
|
*/ |
535
|
|
View Code Duplication |
public function _fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
536
|
|
|
$element=$this->_prep_element($element); |
537
|
|
|
$speed=$this->_validate_speed($speed); |
538
|
|
|
|
539
|
|
|
if ($callback!='') { |
540
|
|
|
$callback=", function(){\n{$callback}\n}"; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
$str="$({$element}).fadeIn({$speed}{$callback});"; |
544
|
|
|
|
545
|
|
|
if ($immediatly) |
546
|
|
|
$this->jquery_code_for_compile[]=$str; |
547
|
|
|
return $str; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
// -------------------------------------------------------------------- |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Outputs a jQuery hide event |
554
|
|
|
* |
555
|
|
|
* @param string $element element |
556
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
557
|
|
|
* @param string $callback Javascript callback function |
558
|
|
|
* @param boolean $immediatly delayed if false |
559
|
|
|
* @return string |
560
|
|
|
*/ |
561
|
|
View Code Duplication |
public function _fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
562
|
|
|
$element=$this->_prep_element($element); |
563
|
|
|
$speed=$this->_validate_speed($speed); |
564
|
|
|
|
565
|
|
|
if ($callback!='') { |
566
|
|
|
$callback=", function(){\n{$callback}\n}"; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
$str="$({$element}).fadeOut({$speed}{$callback});"; |
570
|
|
|
|
571
|
|
|
if ($immediatly) |
572
|
|
|
$this->jquery_code_for_compile[]=$str; |
573
|
|
|
return $str; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
// -------------------------------------------------------------------- |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* Outputs a jQuery hide action |
580
|
|
|
* |
581
|
|
|
* @param string $element element |
582
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
583
|
|
|
* @param string $callback Javascript callback function |
584
|
|
|
* @param boolean $immediatly delayed if false |
585
|
|
|
* @return string |
586
|
|
|
*/ |
587
|
|
View Code Duplication |
public function _hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
588
|
|
|
$element=$this->_prep_element($element); |
589
|
|
|
$speed=$this->_validate_speed($speed); |
590
|
|
|
|
591
|
|
|
if ($callback!='') { |
592
|
|
|
$callback=", function(){\n{$callback}\n}"; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
$str="$({$element}).hide({$speed}{$callback});"; |
596
|
|
|
|
597
|
|
|
if ($immediatly) |
598
|
|
|
$this->jquery_code_for_compile[]=$str; |
599
|
|
|
return $str; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
// -------------------------------------------------------------------- |
603
|
|
|
|
604
|
|
|
// -------------------------------------------------------------------- |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* Outputs a jQuery slideUp event |
608
|
|
|
* |
609
|
|
|
* @param string $element element |
610
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
611
|
|
|
* @param string $callback Javascript callback function |
612
|
|
|
* @param boolean $immediatly delayed if false |
613
|
|
|
* @return string |
614
|
|
|
*/ |
615
|
|
View Code Duplication |
public function _slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
616
|
|
|
$element=$this->_prep_element($element); |
617
|
|
|
$speed=$this->_validate_speed($speed); |
618
|
|
|
|
619
|
|
|
if ($callback!='') { |
620
|
|
|
$callback=", function(){\n{$callback}\n}"; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
$str="$({$element}).slideUp({$speed}{$callback});"; |
624
|
|
|
|
625
|
|
|
if ($immediatly) |
626
|
|
|
$this->jquery_code_for_compile[]=$str; |
627
|
|
|
return $str; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
// -------------------------------------------------------------------- |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Outputs a jQuery slideDown event |
634
|
|
|
* |
635
|
|
|
* @param string $element element |
636
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
637
|
|
|
* @param string $callback Javascript callback function |
638
|
|
|
* @param boolean $immediatly delayed if false |
639
|
|
|
* @return string |
640
|
|
|
*/ |
641
|
|
View Code Duplication |
public function _slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
642
|
|
|
$element=$this->_prep_element($element); |
643
|
|
|
$speed=$this->_validate_speed($speed); |
644
|
|
|
|
645
|
|
|
if ($callback!='') { |
646
|
|
|
$callback=", function(){\n{$callback}\n}"; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
$str="$({$element}).slideDown({$speed}{$callback});"; |
650
|
|
|
|
651
|
|
|
if ($immediatly) |
652
|
|
|
$this->jquery_code_for_compile[]=$str; |
653
|
|
|
return $str; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
// -------------------------------------------------------------------- |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* Outputs a jQuery slideToggle event |
660
|
|
|
* |
661
|
|
|
* @param string $element element |
662
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
663
|
|
|
* @param string $callback Javascript callback function |
664
|
|
|
* @param boolean $immediatly delayed if false |
665
|
|
|
* @return string |
666
|
|
|
*/ |
667
|
|
View Code Duplication |
public function _slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
668
|
|
|
$element=$this->_prep_element($element); |
669
|
|
|
$speed=$this->_validate_speed($speed); |
670
|
|
|
|
671
|
|
|
if ($callback!='') { |
672
|
|
|
$callback=", function(){\n{$callback}\n}"; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
$str="$({$element}).slideToggle({$speed}{$callback});"; |
676
|
|
|
|
677
|
|
|
if ($immediatly) |
678
|
|
|
$this->jquery_code_for_compile[]=$str; |
679
|
|
|
return $str; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
// -------------------------------------------------------------------- |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* Outputs a jQuery toggle event |
686
|
|
|
* |
687
|
|
|
* @param string $element element |
688
|
|
|
* @param boolean $immediatly delayed if false |
689
|
|
|
* @return string |
690
|
|
|
*/ |
691
|
|
View Code Duplication |
public function _toggle($element='this', $immediatly=false) { |
|
|
|
|
692
|
|
|
$element=$this->_prep_element($element); |
693
|
|
|
$str="$({$element}).toggle();"; |
694
|
|
|
|
695
|
|
|
if ($immediatly) |
696
|
|
|
$this->jquery_code_for_compile[]=$str; |
697
|
|
|
return $str; |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
// -------------------------------------------------------------------- |
701
|
|
|
|
702
|
|
|
/** |
703
|
|
|
* Execute all handlers and behaviors attached to the matched elements for the given event. |
704
|
|
|
* @param string $element |
705
|
|
|
* @param string $event |
706
|
|
|
* @param boolean $immediatly delayed if false |
707
|
|
|
*/ |
708
|
|
View Code Duplication |
public function _trigger($element='this', $event='click', $immediatly=false) { |
|
|
|
|
709
|
|
|
$element=$this->_prep_element($element); |
710
|
|
|
$str="$({$element}).trigger(\"$event\");"; |
711
|
|
|
|
712
|
|
|
if ($immediatly) |
713
|
|
|
$this->jquery_code_for_compile[]=$str; |
714
|
|
|
return $str; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
// -------------------------------------------------------------------- |
718
|
|
|
|
719
|
|
|
/** |
720
|
|
|
* Outputs a jQuery show event |
721
|
|
|
* |
722
|
|
|
* @param string $element element |
723
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
724
|
|
|
* @param string $callback Javascript callback function |
725
|
|
|
* @param boolean $immediatly delayed if false |
726
|
|
|
* @return string |
727
|
|
|
*/ |
728
|
|
View Code Duplication |
public function _show($element='this', $speed='', $callback='', $immediatly=false) { |
|
|
|
|
729
|
|
|
$element=$this->_prep_element($element); |
730
|
|
|
$speed=$this->_validate_speed($speed); |
731
|
|
|
|
732
|
|
|
if ($callback!='') { |
733
|
|
|
$callback=", function(){\n{$callback}\n}"; |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
$str="$({$element}).show({$speed}{$callback});"; |
737
|
|
|
|
738
|
|
|
if ($immediatly) |
739
|
|
|
$this->jquery_code_for_compile[]=$str; |
740
|
|
|
return $str; |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Places a condition |
745
|
|
|
* @param string $condition |
746
|
|
|
* @param string $jsCodeIfTrue |
747
|
|
|
* @param string $jsCodeIfFalse |
748
|
|
|
* @param boolean $immediatly delayed if false |
749
|
|
|
* @return string |
750
|
|
|
*/ |
751
|
|
|
public function _condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
752
|
|
|
$str="if(".$condition."){".$jsCodeIfTrue."}"; |
753
|
|
|
if (isset($jsCodeIfFalse)) { |
754
|
|
|
$str.="else{".$jsCodeIfFalse."}"; |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
if ($immediatly) |
758
|
|
|
$this->jquery_code_for_compile[]=$str; |
759
|
|
|
return $str; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
// -------------------------------------------------------------------- |
763
|
|
|
// Plugins |
764
|
|
|
// -------------------------------------------------------------------- |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* Creates a jQuery sortable |
768
|
|
|
* |
769
|
|
|
* @param string $element |
770
|
|
|
* @param array $options |
771
|
|
|
* @return void |
772
|
|
|
*/ |
773
|
|
|
public function sortable($element, $options=array()) { |
774
|
|
|
if (count($options)>0) { |
775
|
|
|
$sort_options=array (); |
776
|
|
|
foreach ( $options as $k => $v ) { |
777
|
|
|
$sort_options[]="\n\t\t".$k.': '.$v.""; |
778
|
|
|
} |
779
|
|
|
$sort_options=implode(",", $sort_options); |
780
|
|
|
} else { |
781
|
|
|
$sort_options=''; |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
return "$(".$this->_prep_element($element).").sortable({".$sort_options."\n\t});"; |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
// -------------------------------------------------------------------- |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* Table Sorter Plugin |
791
|
|
|
* |
792
|
|
|
* @param string $table table name |
793
|
|
|
* @param string $options plugin location |
794
|
|
|
* @return string |
795
|
|
|
*/ |
796
|
|
|
public function tablesorter($table='', $options='') { |
797
|
|
|
$this->jquery_code_for_compile[]="\t$(".$this->_prep_element($table).").tablesorter($options);\n"; |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
// -------------------------------------------------------------------- |
801
|
|
|
// Class functions |
802
|
|
|
// -------------------------------------------------------------------- |
803
|
|
|
|
804
|
|
|
/** |
805
|
|
|
* Constructs the syntax for an event, and adds to into the array for compilation |
806
|
|
|
* |
807
|
|
|
* @param string $element The element to attach the event to |
808
|
|
|
* @param string $js The code to execute |
809
|
|
|
* @param string $event The event to pass |
810
|
|
|
* @param boolean $preventDefault If set to true, the default action of the event will not be triggered. |
811
|
|
|
* @param boolean $stopPropagation Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. |
812
|
|
|
* @return string |
813
|
|
|
*/ |
814
|
|
|
public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
815
|
|
|
if (is_array($js)) { |
816
|
|
|
$js=implode("\n\t\t", $js); |
817
|
|
|
} |
818
|
|
|
if ($preventDefault===true) { |
819
|
|
|
$js="event.preventDefault();\n".$js; |
820
|
|
|
} |
821
|
|
|
if ($stopPropagation===true) { |
822
|
|
|
$js="event.stopPropagation();\n".$js; |
823
|
|
|
} |
824
|
|
|
if (array_search($event, $this->jquery_events)===false) |
825
|
|
|
$event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
826
|
|
|
else |
827
|
|
|
$event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
828
|
|
|
if($immediatly) |
829
|
|
|
$this->jquery_code_for_compile[]=$event; |
830
|
|
|
return $event; |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
// -------------------------------------------------------------------- |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* As events are specified, they are stored in an array |
837
|
|
|
* This function compiles them all for output on a page |
838
|
|
|
* @param view $view |
839
|
|
|
* @param string $view_var |
840
|
|
|
* @param boolean $script_tags |
841
|
|
|
* @return string |
842
|
|
|
*/ |
843
|
|
|
public function _compile($view=NULL, $view_var='script_foot', $script_tags=TRUE) { |
844
|
|
|
// Components UI |
845
|
|
|
$ui=$this->ui(); |
846
|
|
|
if ($this->ui()!=NULL) { |
847
|
|
|
if ($ui->isAutoCompile()) { |
848
|
|
|
$ui->compile(true); |
849
|
|
|
} |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
// Components UI |
853
|
|
|
$bootstrap=$this->bootstrap(); |
854
|
|
|
if ($this->bootstrap()!=NULL) { |
855
|
|
|
if ($bootstrap->isAutoCompile()) { |
856
|
|
|
$bootstrap->compile(true); |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
// External references |
861
|
|
|
$external_scripts=implode('', $this->jquery_code_for_load); |
862
|
|
|
extract(array ( |
863
|
|
|
'library_src' => $external_scripts |
864
|
|
|
)); |
865
|
|
|
|
866
|
|
|
if (count($this->jquery_code_for_compile)==0) { |
867
|
|
|
// no inline references, let's just return |
868
|
|
|
return; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
// Inline references |
872
|
|
|
$script='$(document).ready(function() {'."\n"; |
873
|
|
|
$script.=implode('', $this->jquery_code_for_compile); |
874
|
|
|
$script.='});'; |
875
|
|
|
|
876
|
|
|
$this->jquery_code_for_compile=array(); |
877
|
|
|
if($this->params["debug"]==false){ |
878
|
|
|
$script=$this->minify($script); |
879
|
|
|
} |
880
|
|
|
$output=($script_tags===FALSE) ? $script : $this->inline($script); |
881
|
|
|
|
882
|
|
|
if ($view!=NULL) |
883
|
|
|
$view->setVar($view_var, $output); |
884
|
|
|
return $output; |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
public function _addToCompile($jsScript) { |
888
|
|
|
$this->jquery_code_for_compile[]=$jsScript; |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
// -------------------------------------------------------------------- |
892
|
|
|
|
893
|
|
|
/** |
894
|
|
|
* Clears the array of script events collected for output |
895
|
|
|
* |
896
|
|
|
* @return void |
897
|
|
|
*/ |
898
|
|
|
public function _clear_compile() { |
899
|
|
|
$this->jquery_code_for_compile=array (); |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
// -------------------------------------------------------------------- |
903
|
|
|
|
904
|
|
|
/** |
905
|
|
|
* A wrapper for writing document.ready() |
906
|
|
|
* |
907
|
|
|
* @return string |
908
|
|
|
*/ |
909
|
|
|
public function _document_ready($js) { |
910
|
|
|
if (!is_array($js)) { |
911
|
|
|
$js=array ( |
912
|
|
|
$js |
913
|
|
|
); |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
foreach ( $js as $script ) { |
917
|
|
|
$this->jquery_code_for_compile[]=$script; |
918
|
|
|
} |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
// -------------------------------------------------------------------- |
922
|
|
|
|
923
|
|
|
/** |
924
|
|
|
* Puts HTML element in quotes for use in jQuery code |
925
|
|
|
* unless the supplied element is the Javascript 'this' |
926
|
|
|
* object, in which case no quotes are added |
927
|
|
|
* |
928
|
|
|
* @param string $element |
929
|
|
|
* @return string |
930
|
|
|
*/ |
931
|
|
|
public function _prep_element($element) { |
932
|
|
View Code Duplication |
if (strrpos($element, 'this')===false&&strrpos($element, 'event')===false&&strrpos($element, 'self')===false) { |
|
|
|
|
933
|
|
|
$element='"'.addslashes($element).'"'; |
934
|
|
|
} |
935
|
|
|
return $element; |
936
|
|
|
} |
937
|
|
|
|
938
|
|
|
/** |
939
|
|
|
* Puts HTML values in quotes for use in jQuery code |
940
|
|
|
* unless the supplied value contains the Javascript 'this' or 'event' |
941
|
|
|
* object, in which case no quotes are added |
942
|
|
|
* |
943
|
|
|
* @param string $value |
944
|
|
|
* @return string |
945
|
|
|
*/ |
946
|
|
|
public function _prep_value($value) { |
947
|
|
|
if (is_array($value)) { |
948
|
|
|
$value=implode(",", $value); |
949
|
|
|
} |
950
|
|
View Code Duplication |
if (strrpos($value, 'this')===false&&strrpos($value, 'event')===false&&strrpos($value, 'self')===false) { |
|
|
|
|
951
|
|
|
$value='"'.$value.'"'; |
952
|
|
|
} |
953
|
|
|
return $value; |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
// -------------------------------------------------------------------- |
957
|
|
|
|
958
|
|
|
/** |
959
|
|
|
* Ensures the speed parameter is valid for jQuery |
960
|
|
|
* |
961
|
|
|
* @param string|int $speed |
962
|
|
|
* @return string |
963
|
|
|
*/ |
964
|
|
|
private function _validate_speed($speed) { |
965
|
|
|
if (in_array($speed, array ( |
966
|
|
|
'slow','normal','fast' |
967
|
|
|
))) { |
968
|
|
|
$speed='"'.$speed.'"'; |
969
|
|
|
} elseif (preg_match("/[^0-9]/", $speed)) { |
970
|
|
|
$speed=''; |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
return $speed; |
974
|
|
|
} |
975
|
|
|
// ------------------------------------------------------------------------ |
976
|
|
|
protected function addLoading(&$retour, $responseElement) { |
977
|
|
|
$loading_notifier='<div class="ajax-loader">'; |
978
|
|
|
if ($this->ajaxLoader=='') { |
979
|
|
|
$loading_notifier.="Loading..."; |
980
|
|
|
} else { |
981
|
|
|
$loading_notifier.=$this->ajaxLoader; |
982
|
|
|
} |
983
|
|
|
$loading_notifier.='</div>'; |
984
|
|
|
$retour.="$({$responseElement}).empty();\n"; |
985
|
|
|
$retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
986
|
|
|
} |
987
|
|
|
|
988
|
|
|
public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
989
|
|
|
return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
990
|
|
|
} |
991
|
|
|
public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
992
|
|
|
return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
996
|
|
|
if(JString::isNull($params)){$params="{}";} |
997
|
|
|
$jsCallback=isset($jsCallback) ? $jsCallback : ""; |
998
|
|
|
$retour=$this->_getAjaxUrl($url, $attr); |
999
|
|
|
$responseElement=$this->_getResponseElement($responseElement); |
1000
|
|
|
$retour.="var self=this;\n"; |
1001
|
|
|
if($hasLoader===true){ |
1002
|
|
|
$this->addLoading($retour, $responseElement); |
1003
|
|
|
} |
1004
|
|
|
$retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
1005
|
|
|
$retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n"; |
1006
|
|
|
if ($immediatly) |
1007
|
|
|
$this->jquery_code_for_compile[]=$retour; |
1008
|
|
|
return $retour; |
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
|
protected function _getAjaxUrl($url,$attr){ |
1012
|
|
|
$url=$this->_correctAjaxUrl($url); |
1013
|
|
|
$retour="url='".$url."';\n"; |
1014
|
|
|
$slash="/"; |
1015
|
|
|
if(PhalconUtils::endsWith($url, "/")) |
1016
|
|
|
$slash=""; |
1017
|
|
|
if(JString::isNotNull($attr)){ |
1018
|
|
|
if ($attr=="value") |
1019
|
|
|
$retour.="url=url+'".$slash."'+$(this).val();\n"; |
1020
|
|
|
else if($attr!=null && $attr!=="") |
1021
|
|
|
$retour.="url=url+'".$slash."'+$(this).attr('".$attr."');\n"; |
1022
|
|
|
} |
1023
|
|
|
return $retour; |
1024
|
|
|
} |
1025
|
|
|
|
1026
|
|
|
protected function _getOnAjaxDone($responseElement,$jsCallback){ |
1027
|
|
|
$retour=""; |
1028
|
|
|
if ($responseElement!=="") { |
1029
|
|
|
$retour="\t$({$responseElement}).html( data );\n"; |
1030
|
|
|
} |
1031
|
|
|
$retour.="\t".$jsCallback."\n"; |
1032
|
|
|
return $retour; |
1033
|
|
|
} |
1034
|
|
|
|
1035
|
|
|
protected function _getResponseElement($responseElement){ |
1036
|
|
|
if ($responseElement!=="") { |
1037
|
|
|
$responseElement=$this->_prep_value($responseElement); |
1038
|
|
|
} |
1039
|
|
|
return $responseElement; |
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
protected function _correctAjaxUrl($url) { |
1043
|
|
|
if (PhalconUtils::endsWith($url, "/")) |
1044
|
|
|
$url=substr($url, 0, strlen($url)-1); |
1045
|
|
|
if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
1046
|
|
|
$url=$this->_di->get("url")->get($url); |
1047
|
|
|
} |
1048
|
|
|
return $url; |
1049
|
|
|
} |
1050
|
|
|
|
1051
|
|
|
/** |
1052
|
|
|
* Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name |
1053
|
|
|
* @param string $url the request address |
1054
|
|
|
* @param string $params Paramètres passés au format JSON |
1055
|
|
|
* @param string $method Method use |
1056
|
|
|
* @param string $jsCallback javascript code to execute after the request |
1057
|
|
|
* @param boolean $immediatly |
1058
|
|
|
*/ |
1059
|
|
|
public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
1060
|
|
|
$jsCallback=isset($jsCallback) ? $jsCallback : ""; |
1061
|
|
|
$retour=$this->_getAjaxUrl($url, $attr); |
1062
|
|
|
$retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
1063
|
|
|
$retour.="\tdata=$.parseJSON(data);for(var key in data){" |
1064
|
|
|
."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
1065
|
|
|
$retour.="\t".$jsCallback."\n". |
1066
|
|
|
"\t$(document).trigger('jsonReady',[data]);\n". |
1067
|
|
|
"});\n"; |
1068
|
|
|
if ($immediatly) |
1069
|
|
|
$this->jquery_code_for_compile[]=$retour; |
1070
|
|
|
return $retour; |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
/** |
1074
|
|
|
* Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name when $event fired on $element |
1075
|
|
|
* @param string $element |
1076
|
|
|
* @param string $event |
1077
|
|
|
* @param string $url the request address |
1078
|
|
|
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
1079
|
|
|
*/ |
1080
|
|
View Code Duplication |
public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
|
|
|
1081
|
|
|
$preventDefault=true; |
1082
|
|
|
$stopPropagation=true; |
1083
|
|
|
$jsCallback=null; |
1084
|
|
|
$attr="id"; |
1085
|
|
|
$method="get"; |
1086
|
|
|
$context="document"; |
1087
|
|
|
$params="{}"; |
1088
|
|
|
$immediatly=true; |
1089
|
|
|
extract($parameters); |
1090
|
|
|
return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
1091
|
|
|
} |
1092
|
|
|
|
1093
|
|
|
/** |
1094
|
|
|
* Makes an ajax request and receives a JSON array data types by copying and assigning them to the DOM elements with the same name |
1095
|
|
|
* @param string $url the request address |
1096
|
|
|
* @param string $params Paramètres passés au format JSON |
1097
|
|
|
* @param string $method Method use |
1098
|
|
|
* @param string $jsCallback javascript code to execute after the request |
1099
|
|
|
* @param string $context jquery DOM element, array container. |
1100
|
|
|
* @param boolean $immediatly |
1101
|
|
|
*/ |
1102
|
|
|
public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
1103
|
|
|
$jsCallback=isset($jsCallback) ? $jsCallback : ""; |
1104
|
|
|
$retour=$this->_getAjaxUrl($url, $attr); |
1105
|
|
|
if($context===null){ |
1106
|
|
|
$appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
1107
|
|
|
$newElm = "$('#'+newId)"; |
1108
|
|
|
}else{ |
1109
|
|
|
$appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
1110
|
|
|
$newElm = $context.".find('#'+newId)"; |
1111
|
|
|
} |
1112
|
|
|
$retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
1113
|
|
|
$retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();newElm.attr('id',newId);\n"; |
1114
|
|
|
$retour.= $appendTo; |
1115
|
|
|
$retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
1116
|
|
|
$retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
1117
|
|
|
$retour.="\t".$jsCallback."\n"."});\n"; |
1118
|
|
|
if ($immediatly) |
1119
|
|
|
$this->jquery_code_for_compile[]=$retour; |
1120
|
|
|
return $retour; |
1121
|
|
|
} |
1122
|
|
|
/** |
1123
|
|
|
* Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name when $event fired on $element |
1124
|
|
|
* @param string $element |
1125
|
|
|
* @param string $event |
1126
|
|
|
* @param string $url the request address |
1127
|
|
|
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
1128
|
|
|
*/ |
1129
|
|
View Code Duplication |
public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
|
|
|
1130
|
|
|
$preventDefault=true; |
1131
|
|
|
$stopPropagation=true; |
1132
|
|
|
$jsCallback=null; |
1133
|
|
|
$attr="id"; |
1134
|
|
|
$method="get"; |
1135
|
|
|
$context = null; |
1136
|
|
|
$params="{}"; |
1137
|
|
|
$immediatly=true; |
1138
|
|
|
extract($parameters); |
1139
|
|
|
return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
1143
|
|
|
$jsCallback=isset($jsCallback) ? $jsCallback : ""; |
1144
|
|
|
$retour=$this->_getAjaxUrl($url, $attr); |
1145
|
|
|
$retour.="\nvar params=$('#".$form."').serialize();\n"; |
1146
|
|
|
$responseElement=$this->_getResponseElement($responseElement); |
1147
|
|
|
$retour.="var self=this;\n"; |
1148
|
|
|
if($hasLoader===true){ |
1149
|
|
|
$this->addLoading($retour, $responseElement); |
1150
|
|
|
} |
1151
|
|
|
$retour.="$.post(url,params).done(function( data ) {\n"; |
1152
|
|
|
$retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n"; |
1153
|
|
|
|
1154
|
|
|
if ($validation) { |
1155
|
|
|
$retour="$('#".$form."').validate({submitHandler: function(form) { |
1156
|
|
|
".$retour." |
1157
|
|
|
}});\n"; |
1158
|
|
|
$retour.="$('#".$form."').submit();\n"; |
1159
|
|
|
} |
1160
|
|
|
if ($immediatly) |
1161
|
|
|
$this->jquery_code_for_compile[]=$retour; |
1162
|
|
|
return $retour; |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
/** |
1166
|
|
|
* Effectue un get vers $url sur l'évènement $event de $element en passant les paramètres $params |
1167
|
|
|
* puis affiche le résultat dans $responseElement |
1168
|
|
|
* @param string $element |
1169
|
|
|
* @param string $event |
1170
|
|
|
* @param string $url |
1171
|
|
|
* @param string $params queryString parameters (JSON format). default : {} |
1172
|
|
|
* @param string $responseElement |
1173
|
|
|
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
1174
|
|
|
*/ |
1175
|
|
View Code Duplication |
public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
|
|
|
1176
|
|
|
$preventDefault=true; |
1177
|
|
|
$stopPropagation=true; |
1178
|
|
|
$jsCallback=null; |
1179
|
|
|
$attr="id"; |
1180
|
|
|
$hasLoader=true; |
1181
|
|
|
$immediatly=true; |
1182
|
|
|
extract($parameters); |
1183
|
|
|
return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
/** |
1187
|
|
|
* Effectue un post vers $url sur l'évènement $event de $element en passant les paramètres $params |
1188
|
|
|
* puis affiche le résultat dans $responseElement |
1189
|
|
|
* @param string $element |
1190
|
|
|
* @param string $event |
1191
|
|
|
* @param string $url |
1192
|
|
|
* @param string $params queryString parameters (JSON format). default : {} |
1193
|
|
|
* @param string $responseElement |
1194
|
|
|
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
1195
|
|
|
*/ |
1196
|
|
View Code Duplication |
public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
|
|
|
1197
|
|
|
$preventDefault=true; |
1198
|
|
|
$stopPropagation=true; |
1199
|
|
|
$jsCallback=null; |
1200
|
|
|
$attr="id"; |
1201
|
|
|
$hasLoader=true; |
1202
|
|
|
$immediatly=true; |
1203
|
|
|
extract($parameters); |
1204
|
|
|
return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
/** |
1208
|
|
|
* Effectue un post vers $url sur l'évènement $event de $element en passant les paramètres du formulaire $form |
1209
|
|
|
* puis affiche le résultat dans $responseElement |
1210
|
|
|
* @param string $element |
1211
|
|
|
* @param string $event |
1212
|
|
|
* @param string $url |
1213
|
|
|
* @param string $form |
1214
|
|
|
* @param string $responseElement |
1215
|
|
|
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true) |
1216
|
|
|
*/ |
1217
|
|
View Code Duplication |
public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
|
|
|
1218
|
|
|
$preventDefault=true; |
1219
|
|
|
$stopPropagation=true; |
1220
|
|
|
$validation=false; |
1221
|
|
|
$jsCallback=null; |
1222
|
|
|
$attr="id"; |
1223
|
|
|
$hasLoader=true; |
1224
|
|
|
$immediatly=true; |
1225
|
|
|
extract($parameters); |
1226
|
|
|
return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
/** |
1230
|
|
|
* Call the JQuery method $jqueryCall on $element with parameters $param |
1231
|
|
|
* @param string $element |
1232
|
|
|
* @param string $jqueryCall |
1233
|
|
|
* @param mixed $param |
1234
|
|
|
* @param string $jsCallback javascript code to execute after the jquery call |
1235
|
|
|
* @param boolean $immediatly |
1236
|
|
|
* @return string |
1237
|
|
|
*/ |
1238
|
|
|
public function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
1239
|
|
|
$param=$this->_prep_value($param); |
1240
|
|
|
$callback=""; |
1241
|
|
|
if ($jsCallback!="") |
1242
|
|
|
$callback=", function(event){\n{$jsCallback}\n}"; |
1243
|
|
|
$script="$(".$this->_prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
1244
|
|
|
if ($immediatly) |
1245
|
|
|
$this->jquery_code_for_compile[]=$script; |
1246
|
|
|
return $script; |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
/** |
1250
|
|
|
* |
1251
|
|
|
* @param string $event |
1252
|
|
|
* @param string $element |
1253
|
|
|
* @param string $elementToModify |
1254
|
|
|
* @param string $jqueryCall |
1255
|
|
|
* @param string|array $param |
1256
|
|
|
* @param boolean $preventDefault |
1257
|
|
|
* @param boolean $stopPropagation |
1258
|
|
|
* @param string $jsCallback javascript code to execute after the jquery call |
1259
|
|
|
* @param boolean $immediatly |
1260
|
|
|
* @return string |
1261
|
|
|
*/ |
1262
|
|
|
public function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) { |
1263
|
|
|
return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly); |
1264
|
|
|
} |
1265
|
|
|
|
1266
|
|
|
/** |
1267
|
|
|
* Execute the code $js |
1268
|
|
|
* @param string $js Code to execute |
1269
|
|
|
* @param boolean $immediatly diffère l'exécution si false |
1270
|
|
|
* @return String |
1271
|
|
|
*/ |
1272
|
|
|
public function _exec($js, $immediatly=false) { |
1273
|
|
|
$script=$js."\n"; |
1274
|
|
|
if ($immediatly) |
1275
|
|
|
$this->jquery_code_for_compile[]=$script; |
1276
|
|
|
return $script; |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* |
1281
|
|
|
* @param string $element |
1282
|
|
|
* @param string $event |
1283
|
|
|
* @param string $js Code to execute |
1284
|
|
|
* @param boolean $preventDefault |
1285
|
|
|
* @param boolean $stopPropagation |
1286
|
|
|
* @param boolean $immediatly |
1287
|
|
|
* @return String |
1288
|
|
|
*/ |
1289
|
|
|
public function _execOn($element, $event, $js, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
1290
|
|
|
return $this->_add_event($element, $this->_exec($js), $event, $preventDefault, $stopPropagation,$immediatly); |
1291
|
|
|
} |
1292
|
|
|
|
1293
|
|
|
private function minify($input) { |
1294
|
|
|
if(trim($input) === "") return $input; |
1295
|
|
|
return preg_replace( |
1296
|
|
|
array( |
1297
|
|
|
// Remove comment(s) |
1298
|
|
|
'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
1299
|
|
|
// Remove white-space(s) outside the string and regex |
1300
|
|
|
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
1301
|
|
|
// Remove the last semicolon |
1302
|
|
|
'#;+\}#', |
1303
|
|
|
// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
1304
|
|
|
'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
1305
|
|
|
// --ibid. From `foo['bar']` to `foo.bar` |
1306
|
|
|
'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
1307
|
|
|
), |
1308
|
|
|
array( |
1309
|
|
|
'$1', |
1310
|
|
|
'$1$2', |
1311
|
|
|
'}', |
1312
|
|
|
'$1$3', |
1313
|
|
|
'$1.$3' |
1314
|
|
|
), |
1315
|
|
|
$input); |
1316
|
|
|
} |
1317
|
|
|
} |
1318
|
|
|
/* End of file Jquery.php */ |
1319
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: