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