Passed
Push — master ( 6f80f9...f022dc )
by Jean-Christophe
03:38
created
Ajax/common/traits/JsUtilsActionsTrait.php 1 patch
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 trait JsUtilsActionsTrait {
14 14
 
15
-	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false);
15
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false);
16 16
 
17 17
 	/**
18 18
 	 * show or hide with effect
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
 	 *        	defers the execution if set to false
29 29
 	 * @return string
30 30
 	 */
31
-	protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) {
32
-		$element = Javascript::prep_element ( $element );
33
-		$speed = $this->_validate_speed ( $speed );
34
-		if ($callback != '') {
35
-			$callback = ", function(){\n{$callback}\n}";
31
+	protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) {
32
+		$element=Javascript::prep_element($element);
33
+		$speed=$this->_validate_speed($speed);
34
+		if ($callback!='') {
35
+			$callback=", function(){\n{$callback}\n}";
36 36
 		}
37
-		$str = "$({$element}).{$action}({$speed}{$callback});";
37
+		$str="$({$element}).{$action}({$speed}{$callback});";
38 38
 		if ($immediatly)
39
-			$this->jquery_code_for_compile [] = $str;
39
+			$this->jquery_code_for_compile []=$str;
40 40
 		return $str;
41 41
 	}
42 42
 
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	 * @return string
48 48
 	 */
49 49
 	private function _validate_speed($speed) {
50
-		if (in_array ( $speed, array (
50
+		if (in_array($speed, array(
51 51
 				'slow',
52 52
 				'normal',
53 53
 				'fast'
54
-		) )) {
55
-			$speed = '"' . $speed . '"';
56
-		} elseif (preg_match ( "/[^0-9]/", $speed )) {
57
-			$speed = '';
54
+		))) {
55
+			$speed='"'.$speed.'"';
56
+		} elseif (preg_match("/[^0-9]/", $speed)) {
57
+			$speed='';
58 58
 		}
59 59
 
60 60
 		return $speed;
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
 	 * @param boolean $immediatly
70 70
 	 *        	delayed if false
71 71
 	 */
72
-	public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) {
73
-		$element = Javascript::prep_element ( $element );
74
-		if (isset ( $param )) {
75
-			$param = Javascript::prep_value ( $param );
76
-			$str = "$({$element}).{$jQueryCall}({$param});";
72
+	public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) {
73
+		$element=Javascript::prep_element($element);
74
+		if (isset ($param)) {
75
+			$param=Javascript::prep_value($param);
76
+			$str="$({$element}).{$jQueryCall}({$param});";
77 77
 		} else
78
-			$str = "$({$element}).{$jQueryCall}();";
78
+			$str="$({$element}).{$jQueryCall}();";
79 79
 		if ($immediatly)
80
-			$this->jquery_code_for_compile [] = $str;
80
+			$this->jquery_code_for_compile []=$str;
81 81
 		return $str;
82 82
 	}
83 83
 
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 	 *        	delayed if false
92 92
 	 * @return string
93 93
 	 */
94
-	public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) {
95
-		$to = Javascript::prep_element ( $to );
96
-		$element = Javascript::prep_element ( $element );
97
-		$str = "$({$to}).{$jQueryCall}({$element});";
94
+	public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) {
95
+		$to=Javascript::prep_element($to);
96
+		$element=Javascript::prep_element($element);
97
+		$str="$({$to}).{$jQueryCall}({$element});";
98 98
 		if ($immediatly)
99
-			$this->jquery_code_for_compile [] = $str;
99
+			$this->jquery_code_for_compile []=$str;
100 100
 		return $str;
101 101
 	}
102 102
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 *        	defers the execution if set to false
111 111
 	 * @return string
112 112
 	 */
113
-	public function addClass($element = 'this', $class = '', $immediatly = false) {
114
-		return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly );
113
+	public function addClass($element='this', $class='', $immediatly=false) {
114
+		return $this->_genericCallValue('addClass', $element, $class, $immediatly);
115 115
 	}
116 116
 
117 117
 	/**
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 *        	defers the execution if set to false
124 124
 	 * @return string
125 125
 	 */
126
-	public function after($to, $element, $immediatly = false) {
127
-		return $this->_genericCallElement ( 'after', $to, $element, $immediatly );
126
+	public function after($to, $element, $immediatly=false) {
127
+		return $this->_genericCallElement('after', $to, $element, $immediatly);
128 128
 	}
129 129
 
130 130
 	/**
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	 *        	defers the execution if set to false
137 137
 	 * @return string
138 138
 	 */
139
-	public function before($to, $element, $immediatly = false) {
140
-		return $this->_genericCallElement ( 'before', $to, $element, $immediatly );
139
+	public function before($to, $element, $immediatly=false) {
140
+		return $this->_genericCallElement('before', $to, $element, $immediatly);
141 141
 	}
142 142
 
143 143
 	/**
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
 	 * @param boolean $immediatly
150 150
 	 *        	delayed if false
151 151
 	 */
152
-	public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) {
153
-		$element = Javascript::prep_element ( $element );
154
-		if (isset ( $value )) {
155
-			$value = Javascript::prep_value ( $value );
156
-			$str = "$({$element}).attr(\"$attributeName\",{$value});";
152
+	public function attr($element='this', $attributeName='id', $value="", $immediatly=false) {
153
+		$element=Javascript::prep_element($element);
154
+		if (isset ($value)) {
155
+			$value=Javascript::prep_value($value);
156
+			$str="$({$element}).attr(\"$attributeName\",{$value});";
157 157
 		} else
158
-			$str = "$({$element}).attr(\"$attributeName\");";
158
+			$str="$({$element}).attr(\"$attributeName\");";
159 159
 		if ($immediatly)
160
-			$this->jquery_code_for_compile [] = $str;
160
+			$this->jquery_code_for_compile []=$str;
161 161
 		return $str;
162 162
 	}
163 163
 
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 	 * @param boolean $immediatly
170 170
 	 *        	defers the execution if set to false
171 171
 	 */
172
-	public function val($element = 'this', $value = '', $immediatly = false) {
173
-		return $this->_genericCallValue ( 'val', $element, $value, $immediatly );
172
+	public function val($element='this', $value='', $immediatly=false) {
173
+		return $this->_genericCallValue('val', $element, $value, $immediatly);
174 174
 	}
175 175
 
176 176
 	/**
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 	 * @param boolean $immediatly
182 182
 	 *        	defers the execution if set to false
183 183
 	 */
184
-	public function html($element = 'this', $value = '', $immediatly = false) {
185
-		return $this->_genericCallValue ( 'html', $element, $value, $immediatly );
184
+	public function html($element='this', $value='', $immediatly=false) {
185
+		return $this->_genericCallValue('html', $element, $value, $immediatly);
186 186
 	}
187 187
 
188 188
 	/**
@@ -198,30 +198,30 @@  discard block
 block discarded – undo
198 198
 	 *        	defers the execution if set to false
199 199
 	 * @return string
200 200
 	 */
201
-	public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) {
202
-		$element = Javascript::prep_element ( $element );
203
-		$speed = $this->_validate_speed ( $speed );
201
+	public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) {
202
+		$element=Javascript::prep_element($element);
203
+		$speed=$this->_validate_speed($speed);
204 204
 
205
-		$animations = "\t\t\t";
206
-		if (\is_array ( $params )) {
207
-			foreach ( $params as $param => $value ) {
208
-				$animations .= $param . ': \'' . $value . '\', ';
205
+		$animations="\t\t\t";
206
+		if (\is_array($params)) {
207
+			foreach ($params as $param => $value) {
208
+				$animations.=$param.': \''.$value.'\', ';
209 209
 			}
210 210
 		}
211
-		$animations = substr ( $animations, 0, - 2 ); // remove the last ", "
211
+		$animations=substr($animations, 0, - 2); // remove the last ", "
212 212
 
213
-		if ($speed != '') {
214
-			$speed = ', ' . $speed;
213
+		if ($speed!='') {
214
+			$speed=', '.$speed;
215 215
 		}
216 216
 
217
-		if ($extra != '') {
218
-			$extra = ', ' . $extra;
217
+		if ($extra!='') {
218
+			$extra=', '.$extra;
219 219
 		}
220 220
 
221
-		$str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");";
221
+		$str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
222 222
 
223 223
 		if ($immediatly)
224
-			$this->jquery_code_for_compile [] = $str;
224
+			$this->jquery_code_for_compile []=$str;
225 225
 		return $str;
226 226
 	}
227 227
 
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 	 *        	defers the execution if set to false
235 235
 	 * @return string
236 236
 	 */
237
-	public function append($to, $element, $immediatly = false) {
238
-		return $this->_genericCallElement ( 'append', $to, $element, $immediatly );
237
+	public function append($to, $element, $immediatly=false) {
238
+		return $this->_genericCallElement('append', $to, $element, $immediatly);
239 239
 	}
240 240
 
241 241
 	/**
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
 	 *        	defers the execution if set to false
248 248
 	 * @return string
249 249
 	 */
250
-	public function prepend($to, $element, $immediatly = false) {
251
-		return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly );
250
+	public function prepend($to, $element, $immediatly=false) {
251
+		return $this->_genericCallElement('prepend', $to, $element, $immediatly);
252 252
 	}
253 253
 
254 254
 	/**
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 	 *        	defers the execution if set to false
265 265
 	 * @return string
266 266
 	 */
267
-	public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) {
268
-		return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly );
267
+	public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) {
268
+		return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly);
269 269
 	}
270 270
 
271 271
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 *        	defers the execution if set to false
282 282
 	 * @return string
283 283
 	 */
284
-	public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) {
285
-		return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly );
284
+	public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) {
285
+		return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly);
286 286
 	}
287 287
 
288 288
 	/**
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 	 *        	defers the execution if set to false
299 299
 	 * @return string
300 300
 	 */
301
-	public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) {
302
-		return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly );
301
+	public function slideUp($element='this', $speed='', $callback='', $immediatly=false) {
302
+		return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly);
303 303
 	}
304 304
 
305 305
 	/**
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 	 *        	defers the execution if set to false
314 314
 	 * @return string
315 315
 	 */
316
-	public function removeClass($element = 'this', $class = '', $immediatly = false) {
317
-		return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly );
316
+	public function removeClass($element='this', $class='', $immediatly=false) {
317
+		return $this->_genericCallValue('removeClass', $element, $class, $immediatly);
318 318
 	}
319 319
 
320 320
 	/**
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
 	 *        	defers the execution if set to false
331 331
 	 * @return string
332 332
 	 */
333
-	public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) {
334
-		return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly );
333
+	public function slideDown($element='this', $speed='', $callback='', $immediatly=false) {
334
+		return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly);
335 335
 	}
336 336
 
337 337
 	/**
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 	 *        	defers the execution if set to false
348 348
 	 * @return string
349 349
 	 */
350
-	public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) {
351
-		return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly );
350
+	public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) {
351
+		return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly);
352 352
 	}
353 353
 
354 354
 	/**
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 	 *        	defers the execution if set to false
365 365
 	 * @return string
366 366
 	 */
367
-	public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) {
368
-		return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly );
367
+	public function hide($element='this', $speed='', $callback='', $immediatly=false) {
368
+		return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly);
369 369
 	}
370 370
 
371 371
 	/**
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 	 *        	defers the execution if set to false
382 382
 	 * @return string
383 383
 	 */
384
-	public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) {
385
-		return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly );
384
+	public function toggle($element='this', $speed='', $callback='', $immediatly=false) {
385
+		return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly);
386 386
 	}
387 387
 
388 388
 	/**
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 	 *        	defers the execution if set to false
396 396
 	 * @return string
397 397
 	 */
398
-	public function toggleClass($element = 'this', $class = '', $immediatly = false) {
399
-		return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly );
398
+	public function toggleClass($element='this', $class='', $immediatly=false) {
399
+		return $this->_genericCallValue('toggleClass', $element, $class, $immediatly);
400 400
 	}
401 401
 
402 402
 	/**
@@ -407,12 +407,12 @@  discard block
 block discarded – undo
407 407
 	 * @param boolean $immediatly
408 408
 	 *        	defers the execution if set to false
409 409
 	 */
410
-	public function trigger($element = 'this', $event = 'click', $immediatly = false) {
411
-		$element = Javascript::prep_element ( $element );
412
-		$str = "$({$element}).trigger(\"$event\");";
410
+	public function trigger($element='this', $event='click', $immediatly=false) {
411
+		$element=Javascript::prep_element($element);
412
+		$str="$({$element}).trigger(\"$event\");";
413 413
 
414 414
 		if ($immediatly)
415
-			$this->jquery_code_for_compile [] = $str;
415
+			$this->jquery_code_for_compile []=$str;
416 416
 		return $str;
417 417
 	}
418 418
 
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
 	 *        	defers the execution if set to false
430 430
 	 * @return string
431 431
 	 */
432
-	public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) {
433
-		return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly );
432
+	public function show($element='this', $speed='', $callback='', $immediatly=false) {
433
+		return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly);
434 434
 	}
435 435
 
436 436
 	/**
@@ -440,18 +440,18 @@  discard block
 block discarded – undo
440 440
 	 * @param array $options
441 441
 	 * @return string
442 442
 	 */
443
-	public function sortable($element, $options = array ()) {
444
-		if (count ( $options ) > 0) {
445
-			$sort_options = array ();
446
-			foreach ( $options as $k => $v ) {
447
-				$sort_options [] = "\n\t\t" . $k . ': ' . $v . "";
443
+	public function sortable($element, $options=array()) {
444
+		if (count($options)>0) {
445
+			$sort_options=array();
446
+			foreach ($options as $k => $v) {
447
+				$sort_options []="\n\t\t".$k.': '.$v."";
448 448
 			}
449
-			$sort_options = implode ( ",", $sort_options );
449
+			$sort_options=implode(",", $sort_options);
450 450
 		} else {
451
-			$sort_options = '';
451
+			$sort_options='';
452 452
 		}
453 453
 
454
-		return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});";
454
+		return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});";
455 455
 	}
456 456
 
457 457
 	/**
@@ -463,8 +463,8 @@  discard block
 block discarded – undo
463 463
 	 *        	plugin location
464 464
 	 * @return string
465 465
 	 */
466
-	public function tablesorter($table = '', $options = '') {
467
-		$this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n";
466
+	public function tablesorter($table='', $options='') {
467
+		$this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n";
468 468
 	}
469 469
 
470 470
 	/**
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 	 * @param boolean $immediatly
477 477
 	 *        	defers the execution if set to false
478 478
 	 */
479
-	public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) {
480
-		$str = "if(" . $condition . "){" . $jsCodeIfTrue . "}";
481
-		if (isset ( $jsCodeIfFalse )) {
482
-			$str .= "else{" . $jsCodeIfFalse . "}";
479
+	public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) {
480
+		$str="if(".$condition."){".$jsCodeIfTrue."}";
481
+		if (isset ($jsCodeIfFalse)) {
482
+			$str.="else{".$jsCodeIfFalse."}";
483 483
 		}
484 484
 
485 485
 		if ($immediatly)
486
-			$this->jquery_code_for_compile [] = $str;
486
+			$this->jquery_code_for_compile []=$str;
487 487
 		return $str;
488 488
 	}
489 489
 
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 	 * @param boolean $immediatly
499 499
 	 * @return string
500 500
 	 */
501
-	private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) {
502
-		$param = Javascript::prep_value ( $param );
503
-		$callback = "";
504
-		if ($jsCallback != "")
505
-			$callback = ", function(event){\n{$jsCallback}\n}";
506
-		$script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n";
501
+	private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) {
502
+		$param=Javascript::prep_value($param);
503
+		$callback="";
504
+		if ($jsCallback!="")
505
+			$callback=", function(event){\n{$jsCallback}\n}";
506
+		$script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n";
507 507
 		if ($immediatly)
508
-			$this->jquery_code_for_compile [] = $script;
508
+			$this->jquery_code_for_compile []=$script;
509 509
 		return $script;
510 510
 	}
511 511
 
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
 	 *        	javascript code to execute after the jquery call
523 523
 	 * @return mixed
524 524
 	 */
525
-	public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") {
526
-		return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true );
525
+	public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") {
526
+		return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true);
527 527
 	}
528 528
 
529 529
 	/**
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
 	 *        	javascript code to execute after the jquery call
540 540
 	 * @return mixed
541 541
 	 */
542
-	public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") {
543
-		return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false );
542
+	public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") {
543
+		return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false);
544 544
 	}
545 545
 
546 546
 	/**
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
 	 * @param boolean $immediatly
558 558
 	 * @return string
559 559
 	 */
560
-	private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) {
561
-		return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly );
560
+	private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) {
561
+		return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly);
562 562
 	}
563 563
 
564 564
 	/**
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
 	 * @param array $parameters
573 573
 	 *        	default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true)
574 574
 	 */
575
-	public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) {
576
-		$jsCallback = "";
577
-		$stopPropagation = false;
578
-		$preventDefault = false;
579
-		$immediatly = true;
580
-		extract ( $parameters );
581
-		return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly );
575
+	public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) {
576
+		$jsCallback="";
577
+		$stopPropagation=false;
578
+		$preventDefault=false;
579
+		$immediatly=true;
580
+		extract($parameters);
581
+		return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly);
582 582
 	}
583 583
 
584 584
 	/**
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
 	 *        	delayed if false
591 591
 	 * @return String
592 592
 	 */
593
-	public function exec($js, $immediatly = false) {
594
-		$script = $js . "\n";
593
+	public function exec($js, $immediatly=false) {
594
+		$script=$js."\n";
595 595
 		if ($immediatly)
596
-			$this->jquery_code_for_compile [] = $script;
596
+			$this->jquery_code_for_compile []=$script;
597 597
 		return $script;
598 598
 	}
599 599
 
@@ -607,8 +607,8 @@  discard block
 block discarded – undo
607 607
 	 * @return String
608 608
 	 */
609 609
 	public function execAtLast($js) {
610
-		$script = $js . "\n";
611
-		$this->jquery_code_for_compile_at_last [] = $script;
610
+		$script=$js."\n";
611
+		$this->jquery_code_for_compile_at_last []=$script;
612 612
 		return $script;
613 613
 	}
614 614
 
@@ -623,18 +623,18 @@  discard block
 block discarded – undo
623 623
 	 *        	default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true)
624 624
 	 * @return String
625 625
 	 */
626
-	public function execOn($event, $element, $js, $parameters = array ()) {
627
-		$stopPropagation = false;
628
-		$preventDefault = false;
629
-		$immediatly = true;
630
-		extract ( $parameters );
631
-		$script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly );
626
+	public function execOn($event, $element, $js, $parameters=array()) {
627
+		$stopPropagation=false;
628
+		$preventDefault=false;
629
+		$immediatly=true;
630
+		extract($parameters);
631
+		$script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly);
632 632
 		return $script;
633 633
 	}
634
-	public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) {
635
-		$retour = "var data={$json};" . "\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);" . "\n\tvar pk=data['pk'];var object=data['object'];" . "\n\tfor(var field in object){" . "\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){" . "\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){" . "\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }" . "\n\t});" . "\n}};\n";
636
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
637
-		return $this->exec ( $retour, $immediatly );
634
+	public function setJsonToElement($json, $elementClass="_element", $immediatly=true) {
635
+		$retour="var data={$json};"."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);"."\n\tvar pk=data['pk'];var object=data['object'];"."\n\tfor(var field in object){"."\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){"."\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){"."\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }"."\n\t});"."\n}};\n";
636
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
637
+		return $this->exec($retour, $immediatly);
638 638
 	}
639 639
 
640 640
 	/**
@@ -645,13 +645,13 @@  discard block
 block discarded – undo
645 645
 	 * @param array $parameters
646 646
 	 *        	default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true)
647 647
 	 */
648
-	public function setDraggable($element, $parameters = [ ]) {
649
-		$attr = "id";
650
-		$preventDefault = false;
651
-		$stopPropagation = false;
652
-		$immediatly = true;
653
-		extract ( $parameters );
654
-		$script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly );
648
+	public function setDraggable($element, $parameters=[]) {
649
+		$attr="id";
650
+		$preventDefault=false;
651
+		$stopPropagation=false;
652
+		$immediatly=true;
653
+		extract($parameters);
654
+		$script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly);
655 655
 		return $script;
656 656
 	}
657 657
 
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
 	 * @param string $jsCallback
666 666
 	 *        	the js script to call when element is dropped
667 667
 	 */
668
-	public function asDropZone($element, $jsCallback = "", $parameters = [ ]) {
669
-		$stopPropagation = false;
670
-		$immediatly = true;
671
-		$jqueryDone = "append";
672
-		$script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly );
673
-		extract ( $parameters );
674
-		$script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly );
668
+	public function asDropZone($element, $jsCallback="", $parameters=[]) {
669
+		$stopPropagation=false;
670
+		$immediatly=true;
671
+		$jqueryDone="append";
672
+		$script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly);
673
+		extract($parameters);
674
+		$script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly);
675 675
 		return $script;
676 676
 	}
677 677
 
@@ -688,16 +688,16 @@  discard block
 block discarded – undo
688 688
 	 *        	delayed if false
689 689
 	 * @return string
690 690
 	 */
691
-	public function interval($jsCode, $time, $globalName = null, $immediatly = true) {
692
-		if (! Javascript::isFunction ( $jsCode )) {
693
-			$jsCode = "function(){\n" . $jsCode . "\n}";
691
+	public function interval($jsCode, $time, $globalName=null, $immediatly=true) {
692
+		if (!Javascript::isFunction($jsCode)) {
693
+			$jsCode="function(){\n".$jsCode."\n}";
694 694
 		}
695
-		if (isset ( $globalName )) {
696
-			$script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});";
695
+		if (isset ($globalName)) {
696
+			$script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});";
697 697
 		} else {
698
-			$script = "setInterval({$jsCode},{$time});";
698
+			$script="setInterval({$jsCode},{$time});";
699 699
 		}
700
-		return $this->exec ( $script, $immediatly );
700
+		return $this->exec($script, $immediatly);
701 701
 	}
702 702
 
703 703
 	/**
@@ -709,8 +709,8 @@  discard block
 block discarded – undo
709 709
 	 *        	delayed if false
710 710
 	 * @return string
711 711
 	 */
712
-	public function clearInterval($globalName, $immediatly = true) {
713
-		return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly );
712
+	public function clearInterval($globalName, $immediatly=true) {
713
+		return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly);
714 714
 	}
715 715
 
716 716
 	/**
@@ -731,20 +731,20 @@  discard block
 block discarded – undo
731 731
 	 *        	delayed if false
732 732
 	 * @return string
733 733
 	 */
734
-	public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) {
735
-		$stop = "";
734
+	public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) {
735
+		$stop="";
736 736
 		if ($countDown) {
737
-			$stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}";
737
+			$stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}";
738 738
 		} else {
739
-			if ($limit != 0) {
740
-				$stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}";
739
+			if ($limit!=0) {
740
+				$stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}";
741 741
 			}
742 742
 		}
743
-		$global = "";
744
-		if (isset ( $globalName )) {
745
-			$global = "\nwindow.{$globalName}=interval;";
743
+		$global="";
744
+		if (isset ($globalName)) {
745
+			$global="\nwindow.{$globalName}=interval;";
746 746
 		}
747
-		$timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds;
747
+		$timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds;
748 748
 											var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};};
749 749
 											var shHide=function(v,k,kBefore){if(v==0 && display.find(k).closest('.timer').is(':visible') && (!kBefore || !display.find(kBefore).closest('.timer').is(':visible'))){display.find(k).closest('.timer').hide();}else{sh(display.find(k),v);}};
750 750
 											var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';};
@@ -760,12 +760,12 @@  discard block
 block discarded – undo
760 760
 												minutes = d0(parseInt((timer%3600) / 60, 10));
761 761
 												seconds = d0(parseInt(timer%60, 10));
762 762
 												mainSh(days,hours,minutes,seconds);
763
-												" . $stop . "
763
+												" . $stop."
764 764
     										}, 1000);
765
-										" . $global . "
765
+										" . $global."
766 766
 										}";
767
-		$element = '$("' . $counterSelector . '")';
768
-		return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly );
767
+		$element='$("'.$counterSelector.'")';
768
+		return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly);
769 769
 	}
770 770
 
771 771
 	/**
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
 	 *        	count down if true or elapse if false
788 788
 	 * @return string
789 789
 	 */
790
-	public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) {
791
-		return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) );
790
+	public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) {
791
+		return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false));
792 792
 	}
793 793
 
794 794
 	/**
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
 	 *        	the active href (if null, window.location.href is used)
803 803
 	 * @return string
804 804
 	 */
805
-	public function activateLink($target, $property = 'href', $href = null) {
806
-		return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) );
805
+	public function activateLink($target, $property='href', $href=null) {
806
+		return $this->execAtLast($this->_activateLink($target, $property, $href));
807 807
 	}
808 808
 
809 809
 	/**
@@ -817,14 +817,14 @@  discard block
 block discarded – undo
817 817
 	 *        	the active href (if null, window.location.href is used)
818 818
 	 * @return string
819 819
 	 */
820
-	public function _activateLink($target, $property = 'href', $href = null) {
821
-		$js = '$("' . $target . ' [' . $property . ']").removeClass("active");';
822
-		if (isset ( $href )) {
823
-			$js .= 'var href="' . $href . '";';
820
+	public function _activateLink($target, $property='href', $href=null) {
821
+		$js='$("'.$target.' ['.$property.']").removeClass("active");';
822
+		if (isset ($href)) {
823
+			$js.='var href="'.$href.'";';
824 824
 		} else {
825
-			$js .= 'var href=window.location.href;';
825
+			$js.='var href=window.location.href;';
826 826
 		}
827
-		$js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});';
827
+		$js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});';
828 828
 		return $js;
829 829
 	}
830 830
 }
Please login to merge, or discard this patch.
Ajax/common/traits/JsUtilsEventsTrait.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @property array $jquery_code_for_compile
11 11
  */
12 12
 trait JsUtilsEventsTrait {
13
-	protected $jquery_events = array (
13
+	protected $jquery_events=array(
14 14
 			"bind",
15 15
 			"blur",
16 16
 			"change",
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 			"unload"
52 52
 	);
53 53
 
54
-	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false);
54
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false);
55 55
 
56 56
 	/**
57 57
 	 * Outputs a javascript library blur event
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 *        	code to execute
63 63
 	 * @return string
64 64
 	 */
65
-	public function blur($element = 'this', $js = '') {
66
-		return $this->_add_event ( $element, $js, 'blur' );
65
+	public function blur($element='this', $js='') {
66
+		return $this->_add_event($element, $js, 'blur');
67 67
 	}
68 68
 
69 69
 	/**
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	 * @param boolean $stopPropagation
78 78
 	 * @return string
79 79
 	 */
80
-	public function change($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
81
-		return $this->_add_event ( $element, $js, 'change', $preventDefault, $stopPropagation );
80
+	public function change($element='this', $js='', $preventDefault=false, $stopPropagation=false) {
81
+		return $this->_add_event($element, $js, 'change', $preventDefault, $stopPropagation);
82 82
 	}
83 83
 
84 84
 	/**
@@ -94,18 +94,18 @@  discard block
 block discarded – undo
94 94
 	 * @param boolean $stopPropagation
95 95
 	 * @return string
96 96
 	 */
97
-	public function click($element = 'this', $js = '', $ret_false = TRUE, $preventDefault = false, $stopPropagation = false) {
98
-		if (! is_array ( $js )) {
99
-			$js = array (
97
+	public function click($element='this', $js='', $ret_false=TRUE, $preventDefault=false, $stopPropagation=false) {
98
+		if (!is_array($js)) {
99
+			$js=array(
100 100
 					$js
101 101
 			);
102 102
 		}
103 103
 
104 104
 		if ($ret_false) {
105
-			$js [] = "return false;";
105
+			$js []="return false;";
106 106
 		}
107 107
 
108
-		return $this->_add_event ( $element, $js, 'click', $preventDefault, $stopPropagation );
108
+		return $this->_add_event($element, $js, 'click', $preventDefault, $stopPropagation);
109 109
 	}
110 110
 
111 111
 	/**
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *        	code to execute
118 118
 	 * @return string
119 119
 	 */
120
-	public function contextmenu($element = 'this', $js = '') {
121
-		return $this->_add_event ( $element, $js, 'contextmenu' );
120
+	public function contextmenu($element='this', $js='') {
121
+		return $this->_add_event($element, $js, 'contextmenu');
122 122
 	}
123 123
 
124 124
 	/**
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 *        	code to execute
131 131
 	 * @return string
132 132
 	 */
133
-	public function dblclick($element = 'this', $js = '') {
134
-		return $this->_add_event ( $element, $js, 'dblclick' );
133
+	public function dblclick($element='this', $js='') {
134
+		return $this->_add_event($element, $js, 'dblclick');
135 135
 	}
136 136
 
137 137
 	/**
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
 	 *        	code to execute
144 144
 	 * @return string
145 145
 	 */
146
-	public function error($element = 'this', $js = '') {
147
-		return $this->_add_event ( $element, $js, 'error' );
146
+	public function error($element='this', $js='') {
147
+		return $this->_add_event($element, $js, 'error');
148 148
 	}
149 149
 
150 150
 	/**
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	 *        	code to execute
157 157
 	 * @return string
158 158
 	 */
159
-	public function focus($element = 'this', $js = '') {
160
-		return $this->_add_event ( $element, $js, 'focus' );
159
+	public function focus($element='this', $js='') {
160
+		return $this->_add_event($element, $js, 'focus');
161 161
 	}
162 162
 
163 163
 	/**
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 *        	code for mouse out
171 171
 	 * @return string
172 172
 	 */
173
-	public function hover($element = 'this', $over = '', $out = '') {
174
-		$event = "\n\t$(" . Javascript::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";
175
-		$this->jquery_code_for_compile [] = $event;
173
+	public function hover($element='this', $over='', $out='') {
174
+		$event="\n\t$(".Javascript::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";
175
+		$this->jquery_code_for_compile []=$event;
176 176
 		return $event;
177 177
 	}
178 178
 
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 *        	code to execute
186 186
 	 * @return string
187 187
 	 */
188
-	public function keydown($element = 'this', $js = '') {
189
-		return $this->_add_event ( $element, $js, 'keydown' );
188
+	public function keydown($element='this', $js='') {
189
+		return $this->_add_event($element, $js, 'keydown');
190 190
 	}
191 191
 
192 192
 	/**
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 *        	code to execute
199 199
 	 * @return string
200 200
 	 */
201
-	public function keypress($element = 'this', $js = '') {
202
-		return $this->_add_event ( $element, $js, 'keypress' );
201
+	public function keypress($element='this', $js='') {
202
+		return $this->_add_event($element, $js, 'keypress');
203 203
 	}
204 204
 
205 205
 	/**
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	 *        	code to execute
212 212
 	 * @return string
213 213
 	 */
214
-	public function keyup($element = 'this', $js = '') {
215
-		return $this->_add_event ( $element, $js, 'keyup' );
214
+	public function keyup($element='this', $js='') {
215
+		return $this->_add_event($element, $js, 'keyup');
216 216
 	}
217 217
 
218 218
 	/**
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 *        	code to execute
225 225
 	 * @return string
226 226
 	 */
227
-	public function load($element = 'this', $js = '') {
228
-		return $this->_add_event ( $element, $js, 'load' );
227
+	public function load($element='this', $js='') {
228
+		return $this->_add_event($element, $js, 'load');
229 229
 	}
230 230
 
231 231
 	/**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 *        	code to execute
238 238
 	 * @return string
239 239
 	 */
240
-	public function mousedown($element = 'this', $js = '') {
241
-		return $this->_add_event ( $element, $js, 'mousedown' );
240
+	public function mousedown($element='this', $js='') {
241
+		return $this->_add_event($element, $js, 'mousedown');
242 242
 	}
243 243
 
244 244
 	/**
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	 *        	code to execute
251 251
 	 * @return string
252 252
 	 */
253
-	public function mouseout($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
254
-		return $this->_add_event ( $element, $js, 'mouseout', $preventDefault, $stopPropagation );
253
+	public function mouseout($element='this', $js='', $preventDefault=false, $stopPropagation=false) {
254
+		return $this->_add_event($element, $js, 'mouseout', $preventDefault, $stopPropagation);
255 255
 	}
256 256
 
257 257
 	/**
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 *        	code to execute
264 264
 	 * @return string
265 265
 	 */
266
-	public function mouseleave($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
267
-		return $this->_add_event ( $element, $js, 'mouseleave', $preventDefault, $stopPropagation );
266
+	public function mouseleave($element='this', $js='', $preventDefault=false, $stopPropagation=false) {
267
+		return $this->_add_event($element, $js, 'mouseleave', $preventDefault, $stopPropagation);
268 268
 	}
269 269
 
270 270
 	/**
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 	 *        	code to execute
277 277
 	 * @return string
278 278
 	 */
279
-	public function mouseenter($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
280
-		return $this->_add_event ( $element, $js, 'mouseenter', $preventDefault, $stopPropagation );
279
+	public function mouseenter($element='this', $js='', $preventDefault=false, $stopPropagation=false) {
280
+		return $this->_add_event($element, $js, 'mouseenter', $preventDefault, $stopPropagation);
281 281
 	}
282 282
 
283 283
 	/**
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	 *        	code to execute
290 290
 	 * @return string
291 291
 	 */
292
-	public function mouseover($element = 'this', $js = '') {
293
-		return $this->_add_event ( $element, $js, 'mouseover' );
292
+	public function mouseover($element='this', $js='') {
293
+		return $this->_add_event($element, $js, 'mouseover');
294 294
 	}
295 295
 
296 296
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 *        	code to execute
303 303
 	 * @return string
304 304
 	 */
305
-	public function mouseup($element = 'this', $js = '') {
306
-		return $this->_add_event ( $element, $js, 'mouseup' );
305
+	public function mouseup($element='this', $js='') {
306
+		return $this->_add_event($element, $js, 'mouseup');
307 307
 	}
308 308
 
309 309
 	/**
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
 	 *        	code to execute
316 316
 	 * @return string
317 317
 	 */
318
-	public function unload($element = 'this', $js = '') {
319
-		return $this->_add_event ( $element, $js, 'unload' );
318
+	public function unload($element='this', $js='') {
319
+		return $this->_add_event($element, $js, 'unload');
320 320
 	}
321 321
 
322 322
 	// --------------------------------------------------------------------
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 	 *        	code to execute
330 330
 	 * @return string
331 331
 	 */
332
-	public function resize($element = 'this', $js = '') {
333
-		return $this->_add_event ( $element, $js, 'resize' );
332
+	public function resize($element='this', $js='') {
333
+		return $this->_add_event($element, $js, 'resize');
334 334
 	}
335 335
 
336 336
 	// --------------------------------------------------------------------
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	 *        	code to execute
344 344
 	 * @return string
345 345
 	 */
346
-	public function scroll($element = 'this', $js = '') {
347
-		return $this->_add_event ( $element, $js, 'scroll' );
346
+	public function scroll($element='this', $js='') {
347
+		return $this->_add_event($element, $js, 'scroll');
348 348
 	}
349 349
 }
Please login to merge, or discard this patch.
Ajax/common/traits/JsUtilsAjaxTrait.php 1 patch
Spacing   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -14,210 +14,210 @@  discard block
 block discarded – undo
14 14
  */
15 15
 trait JsUtilsAjaxTrait {
16 16
 	protected $ajaxTransition;
17
-	protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>";
17
+	protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>";
18 18
 	abstract public function getUrl($url);
19
-	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false);
20
-	abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true);
21
-	protected function _ajax($method, $url, $responseElement = "", $parameters = [ ]) {
22
-		if (isset ( $this->params ["ajax"] )) {
23
-			extract ( $this->params ["ajax"] );
24
-		}
25
-		extract ( $parameters );
26
-
27
-		$jsCallback = isset ( $jsCallback ) ? $jsCallback : "";
28
-		$retour = $this->_getAjaxUrl ( $url, $attr );
29
-		$originalSelector = $responseElement;
30
-		$responseElement = $this->_getResponseElement ( $responseElement );
31
-		$retour .= "var self=this;\n";
32
-		$before = isset ( $before ) ? $before : "";
33
-		$retour .= $before;
34
-		if ($hasLoader === true && JString::isNotNull ( $responseElement )) {
35
-			$this->addLoading ( $retour, $responseElement, $ajaxLoader );
36
-		} elseif ($hasLoader === 'response') {
37
-			$this->addResponseLoading ( $retour, $responseElement, $ajaxLoader );
38
-		} elseif ($hasLoader === 'internal') {
39
-			$retour .= "\n$(this).addClass('loading');";
40
-		}
41
-		$ajaxParameters = [ 
19
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false);
20
+	abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true);
21
+	protected function _ajax($method, $url, $responseElement="", $parameters=[]) {
22
+		if (isset ($this->params ["ajax"])) {
23
+			extract($this->params ["ajax"]);
24
+		}
25
+		extract($parameters);
26
+
27
+		$jsCallback=isset ($jsCallback) ? $jsCallback : "";
28
+		$retour=$this->_getAjaxUrl($url, $attr);
29
+		$originalSelector=$responseElement;
30
+		$responseElement=$this->_getResponseElement($responseElement);
31
+		$retour.="var self=this;\n";
32
+		$before=isset ($before) ? $before : "";
33
+		$retour.=$before;
34
+		if ($hasLoader===true && JString::isNotNull($responseElement)) {
35
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
36
+		} elseif ($hasLoader==='response') {
37
+			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
38
+		} elseif ($hasLoader==='internal') {
39
+			$retour.="\n$(this).addClass('loading');";
40
+		}
41
+		$ajaxParameters=[ 
42 42
 				"url" => "url",
43
-				"method" => "'" . \strtoupper ( $method ) . "'"
43
+				"method" => "'".\strtoupper($method)."'"
44 44
 		];
45 45
 
46
-		$ajaxParameters ["async"] = ($async ? "true" : "false");
46
+		$ajaxParameters ["async"]=($async ? "true" : "false");
47 47
 
48
-		if (isset ( $params )) {
49
-			$ajaxParameters ["data"] = self::_correctParams ( $params, $parameters );
48
+		if (isset ($params)) {
49
+			$ajaxParameters ["data"]=self::_correctParams($params, $parameters);
50 50
 		}
51
-		if (isset ( $headers )) {
52
-			$ajaxParameters ["headers"] = $headers;
51
+		if (isset ($headers)) {
52
+			$ajaxParameters ["headers"]=$headers;
53 53
 		}
54
-		if (isset ( $partial )) {
55
-			$ajaxParameters ["xhr"] = "xhrProvider";
56
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
54
+		if (isset ($partial)) {
55
+			$ajaxParameters ["xhr"]="xhrProvider";
56
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
57 57
 		}
58
-		$this->createAjaxParameters ( $ajaxParameters, $parameters );
59
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) {\n";
60
-		$retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n";
58
+		$this->createAjaxParameters($ajaxParameters, $parameters);
59
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n";
60
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n";
61 61
 
62
-		$retour = $this->_addJsCondition ( $jsCondition, $retour );
62
+		$retour=$this->_addJsCondition($jsCondition, $retour);
63 63
 		if ($immediatly)
64
-			$this->jquery_code_for_compile [] = $retour;
64
+			$this->jquery_code_for_compile []=$retour;
65 65
 		return $retour;
66 66
 	}
67 67
 	protected function createAjaxParameters(&$original, $parameters) {
68
-		$validParameters = [ 
68
+		$validParameters=[ 
69 69
 				"contentType" => "%value%",
70 70
 				"dataType" => "'%value%'",
71 71
 				"beforeSend" => "function(jqXHR,settings){%value%}",
72 72
 				"complete" => "function(jqXHR){%value%}",
73 73
 				"processData" => "%value%"
74 74
 		];
75
-		foreach ( $validParameters as $param => $mask ) {
76
-			if (isset ( $parameters [$param] )) {
77
-				$original [$param] = \str_replace ( "%value%", $parameters [$param], $mask );
75
+		foreach ($validParameters as $param => $mask) {
76
+			if (isset ($parameters [$param])) {
77
+				$original [$param]=\str_replace("%value%", $parameters [$param], $mask);
78 78
 			}
79 79
 		}
80 80
 	}
81 81
 	protected function implodeAjaxParameters($ajaxParameters) {
82
-		$s = '';
83
-		foreach ( $ajaxParameters as $k => $v ) {
84
-			if ($s !== '') {
85
-				$s .= ',';
82
+		$s='';
83
+		foreach ($ajaxParameters as $k => $v) {
84
+			if ($s!=='') {
85
+				$s.=',';
86 86
 			}
87
-			if (is_array ( $v )) {
88
-				$s .= "'{$k}':{" . self::implodeAjaxParameters ( $v ) . "}";
87
+			if (is_array($v)) {
88
+				$s.="'{$k}':{".self::implodeAjaxParameters($v)."}";
89 89
 			} else {
90
-				$s .= "'{$k}':{$v}";
90
+				$s.="'{$k}':{$v}";
91 91
 			}
92 92
 		}
93 93
 		return $s;
94 94
 	}
95 95
 	protected function _addJsCondition($jsCondition, $jsSource) {
96
-		if (isset ( $jsCondition )) {
97
-			return "if(" . $jsCondition . "){\n" . $jsSource . "\n}";
96
+		if (isset ($jsCondition)) {
97
+			return "if(".$jsCondition."){\n".$jsSource."\n}";
98 98
 		}
99 99
 		return $jsSource;
100 100
 	}
101 101
 	protected function _getAjaxUrl($url, $attr) {
102
-		$url = $this->_correctAjaxUrl ( $url );
103
-		$retour = "url='" . $url . "';";
104
-		$slash = "/";
105
-		if (JString::endswith ( $url, "/" ) === true) {
106
-			$slash = "";
107
-		}
108
-		if (JString::isNotNull ( $attr )) {
109
-			if ($attr === "value") {
110
-				$retour .= "url=url+'" . $slash . "'+$(this).val();\n";
111
-			} elseif ($attr === "html") {
112
-				$retour .= "url=url+'" . $slash . "'+$(this).html();\n";
113
-			} elseif (\substr ( $attr, 0, 3 ) === "js:") {
114
-				$retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n";
115
-			} elseif ($attr !== null && $attr !== "")
116
-				$retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n";
102
+		$url=$this->_correctAjaxUrl($url);
103
+		$retour="url='".$url."';";
104
+		$slash="/";
105
+		if (JString::endswith($url, "/")===true) {
106
+			$slash="";
107
+		}
108
+		if (JString::isNotNull($attr)) {
109
+			if ($attr==="value") {
110
+				$retour.="url=url+'".$slash."'+$(this).val();\n";
111
+			} elseif ($attr==="html") {
112
+				$retour.="url=url+'".$slash."'+$(this).html();\n";
113
+			} elseif (\substr($attr, 0, 3)==="js:") {
114
+				$retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n";
115
+			} elseif ($attr!==null && $attr!=="")
116
+				$retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n";
117 117
 		}
118 118
 		return $retour;
119 119
 	}
120 120
 	protected function onPopstate() {
121 121
 		return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};";
122 122
 	}
123
-	protected function autoActiveLinks($previousURL = "window.location.href") {
124
-		$result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
125
-		$result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
123
+	protected function autoActiveLinks($previousURL="window.location.href") {
124
+		$result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
125
+		$result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
126 126
 		return $result;
127 127
 	}
128
-	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) {
129
-		$retour = "";
130
-		$call = null;
131
-		if (JString::isNotNull ( $responseElement )) {
132
-			if (isset ( $ajaxTransition )) {
133
-				$call = $this->setAjaxDataCall ( $ajaxTransition );
134
-			} elseif (isset ( $this->ajaxTransition )) {
135
-				$call = $this->ajaxTransition;
128
+	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) {
129
+		$retour="";
130
+		$call=null;
131
+		if (JString::isNotNull($responseElement)) {
132
+			if (isset ($ajaxTransition)) {
133
+				$call=$this->setAjaxDataCall($ajaxTransition);
134
+			} elseif (isset ($this->ajaxTransition)) {
135
+				$call=$this->ajaxTransition;
136 136
 			}
137
-			if (\is_callable ( $call ))
138
-				$retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n";
137
+			if (\is_callable($call))
138
+				$retour="\t".$call($responseElement, $jqueryDone).";\n";
139 139
 			else
140
-				$retour = "\t{$responseElement}.{$jqueryDone}( data );\n";
140
+				$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
141 141
 		}
142
-		if (isset ( $history )) {
142
+		if (isset ($history)) {
143 143
 			if ($this->params ["autoActiveLinks"]) {
144
-				$retour .= $this->autoActiveLinks ( "url" );
144
+				$retour.=$this->autoActiveLinks("url");
145 145
 			}
146
-			$retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value ( $history ) . ",'jqueryDone':'{$jqueryDone}'},'', url);";
146
+			$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
147 147
 		}
148
-		if ($hasLoader === "internal") {
149
-			$retour .= "\n$(self).removeClass('loading');";
148
+		if ($hasLoader==="internal") {
149
+			$retour.="\n$(self).removeClass('loading');";
150 150
 		}
151
-		$retour .= "\t" . $jsCallback . "\n";
151
+		$retour.="\t".$jsCallback."\n";
152 152
 		return $retour;
153 153
 	}
154 154
 	protected function _getResponseElement($responseElement) {
155
-		if (JString::isNotNull ( $responseElement )) {
156
-			$responseElement = Javascript::prep_jquery_selector ( $responseElement );
155
+		if (JString::isNotNull($responseElement)) {
156
+			$responseElement=Javascript::prep_jquery_selector($responseElement);
157 157
 		}
158 158
 		return $responseElement;
159 159
 	}
160 160
 	protected function _correctAjaxUrl($url) {
161
-		if ($url !== "/" && JString::endsWith ( $url, "/" ) === true)
162
-			$url = substr ( $url, 0, strlen ( $url ) - 1 );
163
-		if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) {
164
-			$url = $this->getUrl ( $url );
161
+		if ($url!=="/" && JString::endsWith($url, "/")===true)
162
+			$url=substr($url, 0, strlen($url)-1);
163
+		if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) {
164
+			$url=$this->getUrl($url);
165 165
 		}
166 166
 		return $url;
167 167
 	}
168
-	public static function _correctParams($params, $ajaxParameters = [ ]) {
169
-		if (JString::isNull ( $params )) {
168
+	public static function _correctParams($params, $ajaxParameters=[]) {
169
+		if (JString::isNull($params)) {
170 170
 			return "";
171 171
 		}
172
-		if (\preg_match ( "@^\{.*?\}$@", $params )) {
173
-			if (! isset ( $ajaxParameters ['contentType'] ) || ! JString::contains ( $ajaxParameters ['contentType'], 'json' )) {
174
-				return '$.param(' . $params . ')';
172
+		if (\preg_match("@^\{.*?\}$@", $params)) {
173
+			if (!isset ($ajaxParameters ['contentType']) || !JString::contains($ajaxParameters ['contentType'], 'json')) {
174
+				return '$.param('.$params.')';
175 175
 			} else {
176
-				return 'JSON.stringify(' . $params . ')';
176
+				return 'JSON.stringify('.$params.')';
177 177
 			}
178 178
 		}
179 179
 		return $params;
180 180
 	}
181 181
 	public static function _implodeParams($parameters) {
182
-		$allParameters = [ ];
183
-		foreach ( $parameters as $params ) {
184
-			if (isset ( $params ))
185
-				$allParameters [] = self::_correctParams ( $params );
182
+		$allParameters=[];
183
+		foreach ($parameters as $params) {
184
+			if (isset ($params))
185
+				$allParameters []=self::_correctParams($params);
186 186
 		}
187
-		return \implode ( "+'&'+", $allParameters );
187
+		return \implode("+'&'+", $allParameters);
188 188
 	}
189
-	protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) {
190
-		if (! isset ( $ajaxLoader )) {
191
-			$ajaxLoader = $this->ajaxLoader;
189
+	protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) {
190
+		if (!isset ($ajaxLoader)) {
191
+			$ajaxLoader=$this->ajaxLoader;
192 192
 		}
193
-		$loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>';
194
-		$retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n";
193
+		$loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>';
194
+		$retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n";
195 195
 	}
196
-	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) {
197
-		if (! isset ( $ajaxLoader )) {
198
-			$ajaxLoader = $this->ajaxLoader;
196
+	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) {
197
+		if (!isset ($ajaxLoader)) {
198
+			$ajaxLoader=$this->ajaxLoader;
199 199
 		}
200
-		$loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>';
201
-		$retour .= "{$responseElement}.empty();\n";
202
-		$retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
200
+		$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
201
+		$retour.="{$responseElement}.empty();\n";
202
+		$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
203 203
 	}
204 204
 	protected function setAjaxDataCall($params) {
205
-		$result = null;
206
-		if (! \is_callable ( $params )) {
207
-			$result = function ($responseElement, $jqueryDone = "html") use ($params) {
208
-				return AjaxTransition::{$params} ( $responseElement, $jqueryDone );
205
+		$result=null;
206
+		if (!\is_callable($params)) {
207
+			$result=function($responseElement, $jqueryDone="html") use ($params) {
208
+				return AjaxTransition::{$params} ($responseElement, $jqueryDone);
209 209
 			};
210 210
 		}
211 211
 		return $result;
212 212
 	}
213 213
 	protected function setDefaultParameters(&$parameters, $default) {
214
-		foreach ( $default as $k => $v ) {
215
-			if (! isset ( $parameters [$k] ))
216
-				$parameters [$k] = $v;
214
+		foreach ($default as $k => $v) {
215
+			if (!isset ($parameters [$k]))
216
+				$parameters [$k]=$v;
217 217
 		}
218 218
 	}
219 219
 	public function setAjaxLoader($loader) {
220
-		$this->ajaxLoader = $loader;
220
+		$this->ajaxLoader=$loader;
221 221
 	}
222 222
 
223 223
 	/**
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 	 * @param string $responseElement
229 229
 	 *        	selector of the HTML element displaying the answer
230 230
 	 */
231
-	private function _get($url, $responseElement = "", $parameters = [ ]) {
232
-		return $this->_ajax ( "get", $url, $responseElement, $parameters );
231
+	private function _get($url, $responseElement="", $parameters=[]) {
232
+		return $this->_ajax("get", $url, $responseElement, $parameters);
233 233
 	}
234 234
 
235 235
 	/**
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 	 * @param array $parameters
243 243
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
244 244
 	 */
245
-	public function get($url, $responseElement = "", $parameters = [ ]) {
246
-		$parameters ["immediatly"] = true;
247
-		return $this->_get ( $url, $responseElement, $parameters );
245
+	public function get($url, $responseElement="", $parameters=[]) {
246
+		$parameters ["immediatly"]=true;
247
+		return $this->_get($url, $responseElement, $parameters);
248 248
 	}
249 249
 
250 250
 	/**
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 	 * @param array $parameters
260 260
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
261 261
 	 */
262
-	public function ajax($method, $url, $responseElement = "", $parameters = [ ]) {
263
-		$parameters ["immediatly"] = true;
264
-		return $this->_ajax ( $method, $url, $responseElement, $parameters );
262
+	public function ajax($method, $url, $responseElement="", $parameters=[]) {
263
+		$parameters ["immediatly"]=true;
264
+		return $this->_ajax($method, $url, $responseElement, $parameters);
265 265
 	}
266 266
 
267 267
 	/**
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 *        	$immediatly
283 283
 	 * @return string
284 284
 	 */
285
-	public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [ ], $immediatly = true) {
286
-		return $this->interval ( $this->ajaxDeferred ( $method, $url, $responseElement, $parameters ), $interval, $globalName, $immediatly );
285
+	public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) {
286
+		return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly);
287 287
 	}
288 288
 
289 289
 	/**
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 	 * @param array $parameters
299 299
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
300 300
 	 */
301
-	public function ajaxDeferred($method, $url, $responseElement = "", $parameters = [ ]) {
302
-		$parameters ["immediatly"] = false;
303
-		return $this->_ajax ( $method, $url, $responseElement, $parameters );
301
+	public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) {
302
+		$parameters ["immediatly"]=false;
303
+		return $this->_ajax($method, $url, $responseElement, $parameters);
304 304
 	}
305 305
 
306 306
 	/**
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 	 * @param array $parameters
314 314
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
315 315
 	 */
316
-	private function _json($url, $method = "get", $parameters = [ ]) {
317
-		$parameters = \array_merge ( $parameters, [ 
316
+	private function _json($url, $method="get", $parameters=[]) {
317
+		$parameters=\array_merge($parameters, [ 
318 318
 				"hasLoader" => false
319
-		] );
320
-		$jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : "";
321
-		$context = isset ( $parameters ['context'] ) ? $parameters ['context'] : "document";
322
-		$retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(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";
323
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
324
-		$parameters ["jsCallback"] = $retour;
325
-		return $this->_ajax ( $method, $url, null, $parameters );
319
+		]);
320
+		$jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : "";
321
+		$context=isset ($parameters ['context']) ? $parameters ['context'] : "document";
322
+		$retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(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";
323
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
324
+		$parameters ["jsCallback"]=$retour;
325
+		return $this->_ajax($method, $url, null, $parameters);
326 326
 	}
327 327
 
328 328
 	/**
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 	 * @param array $parameters
336 336
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
337 337
 	 */
338
-	public function json($url, $method = "get", $parameters = [ ]) {
339
-		return $this->_json ( $url, $method, $parameters );
338
+	public function json($url, $method="get", $parameters=[]) {
339
+		return $this->_json($url, $method, $parameters);
340 340
 	}
341 341
 
342 342
 	/**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
 	 * @param array $parameters
352 352
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false)
353 353
 	 */
354
-	public function jsonOn($event, $element, $url, $method = "get", $parameters = array ()) {
355
-		$this->setDefaultParameters ( $parameters, [ 
354
+	public function jsonOn($event, $element, $url, $method="get", $parameters=array()) {
355
+		$this->setDefaultParameters($parameters, [ 
356 356
 				"preventDefault" => true,
357 357
 				"stopPropagation" => true,
358 358
 				"immediatly" => true
359
-		] );
360
-		return $this->_add_event ( $element, $this->jsonDeferred ( $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
359
+		]);
360
+		return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
361 361
 	}
362 362
 
363 363
 	/**
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 * @param array $parameters
371 371
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
372 372
 	 */
373
-	public function jsonDeferred($url, $method = "get", $parameters = [ ]) {
374
-		$parameters ["immediatly"] = false;
375
-		return $this->_json ( $url, $method, $parameters );
373
+	public function jsonDeferred($url, $method="get", $parameters=[]) {
374
+		$parameters ["immediatly"]=false;
375
+		return $this->_json($url, $method, $parameters);
376 376
 	}
377 377
 
378 378
 	/**
@@ -386,30 +386,30 @@  discard block
 block discarded – undo
386 386
 	 * @param array $parameters
387 387
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
388 388
 	 */
389
-	private function _jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) {
390
-		$parameters = \array_merge ( $parameters, [ 
389
+	private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
390
+		$parameters=\array_merge($parameters, [ 
391 391
 				"hasLoader" => false
392
-		] );
393
-		$rowClass = isset ( $parameters ['rowClass'] ) ? $parameters ['rowClass'] : "_json";
394
-		$jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : "";
395
-		$context = isset ( $parameters ['context'] ) ? $parameters ['context'] : null;
396
-		if ($context === null) {
397
-			$parent = "$('" . $maskSelector . "').parent()";
398
-			$newElm = "$('#'+newId)";
392
+		]);
393
+		$rowClass=isset ($parameters ['rowClass']) ? $parameters ['rowClass'] : "_json";
394
+		$jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : "";
395
+		$context=isset ($parameters ['context']) ? $parameters ['context'] : null;
396
+		if ($context===null) {
397
+			$parent="$('".$maskSelector."').parent()";
398
+			$newElm="$('#'+newId)";
399 399
 		} else {
400
-			$parent = $context;
401
-			$newElm = $context . ".find('#'+newId)";
400
+			$parent=$context;
401
+			$newElm=$context.".find('#'+newId)";
402 402
 		}
403
-		$appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n";
404
-		$retour = $parent . ".find('.{$rowClass}').remove();";
405
-		$retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.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();
403
+		$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
404
+		$retour=$parent.".find('.{$rowClass}').remove();";
405
+		$retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.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();
406 406
 		newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n";
407
-		$retour .= $appendTo;
408
-		$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";
409
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
410
-		$retour .= "\t" . $jsCallback;
411
-		$parameters ["jsCallback"] = $retour;
412
-		return $this->_ajax ( $method, $url, null, $parameters );
407
+		$retour.=$appendTo;
408
+		$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";
409
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
410
+		$retour.="\t".$jsCallback;
411
+		$parameters ["jsCallback"]=$retour;
412
+		return $this->_ajax($method, $url, null, $parameters);
413 413
 	}
414 414
 
415 415
 	/**
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
 	 * @param array $parameters
424 424
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
425 425
 	 */
426
-	public function jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) {
427
-		return $this->_jsonArray ( $maskSelector, $url, $method, $parameters );
426
+	public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
427
+		return $this->_jsonArray($maskSelector, $url, $method, $parameters);
428 428
 	}
429 429
 
430 430
 	/**
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
 	 * @param array $parameters
439 439
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null)
440 440
 	 */
441
-	public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters = [ ]) {
442
-		$parameters ["immediatly"] = false;
443
-		return $this->jsonArray ( $maskSelector, $url, $method, $parameters );
441
+	public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters=[]) {
442
+		$parameters ["immediatly"]=false;
443
+		return $this->jsonArray($maskSelector, $url, $method, $parameters);
444 444
 	}
445 445
 
446 446
 	/**
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 	 * @param array $parameters
456 456
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false)
457 457
 	 */
458
-	public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array ()) {
459
-		$this->setDefaultParameters ( $parameters, [ 
458
+	public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) {
459
+		$this->setDefaultParameters($parameters, [ 
460 460
 				"preventDefault" => true,
461 461
 				"stopPropagation" => true,
462 462
 				"immediatly" => true
463
-		] );
464
-		return $this->_add_event ( $element, $this->jsonArrayDeferred ( $maskSelector, $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
463
+		]);
464
+		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
465 465
 	}
466 466
 
467 467
 	/**
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
 	 * @param array $parameters
476 476
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
477 477
 	 */
478
-	public function getDeferred($url, $responseElement = "", $parameters = [ ]) {
479
-		$parameters ["immediatly"] = false;
480
-		return $this->_get ( $url, $responseElement, $parameters );
478
+	public function getDeferred($url, $responseElement="", $parameters=[]) {
479
+		$parameters ["immediatly"]=false;
480
+		return $this->_get($url, $responseElement, $parameters);
481 481
 	}
482 482
 
483 483
 	/**
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
 	 * @param array $parameters
496 496
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
497 497
 	 */
498
-	public function getOn($event, $element, $url, $responseElement = "", $parameters = array ()) {
499
-		$this->setDefaultParameters ( $parameters, [ 
498
+	public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
499
+		$this->setDefaultParameters($parameters, [ 
500 500
 				"preventDefault" => true,
501 501
 				"stopPropagation" => true,
502 502
 				"immediatly" => true
503
-		] );
504
-		return $this->_add_event ( $element, $this->getDeferred ( $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
503
+		]);
504
+		return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
505 505
 	}
506 506
 
507 507
 	/**
@@ -519,14 +519,14 @@  discard block
 block discarded – undo
519 519
 	 * @param array $parameters
520 520
 	 *        	default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
521 521
 	 */
522
-	public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array ()) {
523
-		$this->setDefaultParameters ( $parameters, [ 
522
+	public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) {
523
+		$this->setDefaultParameters($parameters, [ 
524 524
 				"preventDefault" => true,
525 525
 				"stopPropagation" => true,
526 526
 				"immediatly" => true,
527 527
 				"method" => "get"
528
-		] );
529
-		return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ["method"], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
528
+		]);
529
+		return $this->_add_event($element, $this->ajaxDeferred($parameters ["method"], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
530 530
 	}
531 531
 
532 532
 	/**
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
 	 * @param array $parameters
543 543
 	 *        	default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
544 544
 	 */
545
-	public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array ()) {
546
-		return $this->ajaxOn ( "click", $element, $url, $responseElement, $parameters );
545
+	public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) {
546
+		return $this->ajaxOn("click", $element, $url, $responseElement, $parameters);
547 547
 	}
548 548
 
549 549
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @param array $parameters
560 560
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
561 561
 	 */
562
-	public function getOnClick($element, $url, $responseElement = "", $parameters = array ()) {
563
-		return $this->getOn ( "click", $element, $url, $responseElement, $parameters );
562
+	public function getOnClick($element, $url, $responseElement="", $parameters=array()) {
563
+		return $this->getOn("click", $element, $url, $responseElement, $parameters);
564 564
 	}
565 565
 
566 566
 	/**
@@ -574,17 +574,17 @@  discard block
 block discarded – undo
574 574
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null)
575 575
 	 * @return $this
576 576
 	 */
577
-	public function getHref($element, $responseElement = "", $parameters = array ()) {
578
-		$parameters ["attr"] = "href";
579
-		if (JString::isNull ( $responseElement )) {
580
-			$responseElement = '%$(self).attr("data-target")%';
577
+	public function getHref($element, $responseElement="", $parameters=array()) {
578
+		$parameters ["attr"]="href";
579
+		if (JString::isNull($responseElement)) {
580
+			$responseElement='%$(self).attr("data-target")%';
581 581
 		} else {
582
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
582
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
583 583
 		}
584
-		if (! isset ( $parameters ["historize"] )) {
585
-			$parameters ["historize"] = true;
584
+		if (!isset ($parameters ["historize"])) {
585
+			$parameters ["historize"]=true;
586 586
 		}
587
-		return $this->getOnClick ( $element, "", $responseElement, $parameters );
587
+		return $this->getOnClick($element, "", $responseElement, $parameters);
588 588
 	}
589 589
 
590 590
 	/**
@@ -598,21 +598,21 @@  discard block
 block discarded – undo
598 598
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null)
599 599
 	 * @return $this
600 600
 	 */
601
-	public function postHref($element, $responseElement = "", $parameters = array ()) {
602
-		$parameters ["attr"] = "href";
603
-		if (JString::isNull ( $responseElement )) {
604
-			$responseElement = '%$(this).attr("data-target")%';
601
+	public function postHref($element, $responseElement="", $parameters=array()) {
602
+		$parameters ["attr"]="href";
603
+		if (JString::isNull($responseElement)) {
604
+			$responseElement='%$(this).attr("data-target")%';
605 605
 		} else {
606
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
606
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
607 607
 		}
608
-		if (! isset ( $parameters ["historize"] )) {
609
-			$parameters ["historize"] = true;
608
+		if (!isset ($parameters ["historize"])) {
609
+			$parameters ["historize"]=true;
610 610
 		}
611
-		return $this->postOnClick ( $element, "", "{}", $responseElement, $parameters );
611
+		return $this->postOnClick($element, "", "{}", $responseElement, $parameters);
612 612
 	}
613
-	private function _post($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
614
-		$parameters ["params"] = $params;
615
-		return $this->_ajax ( "POST", $url, $responseElement, $parameters );
613
+	private function _post($url, $params="{}", $responseElement="", $parameters=[]) {
614
+		$parameters ["params"]=$params;
615
+		return $this->_ajax("POST", $url, $responseElement, $parameters);
616 616
 	}
617 617
 
618 618
 	/**
@@ -627,9 +627,9 @@  discard block
 block discarded – undo
627 627
 	 * @param array $parameters
628 628
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
629 629
 	 */
630
-	public function post($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
631
-		$parameters ['immediatly'] = true;
632
-		return $this->_post ( $url, $params, $responseElement, $parameters );
630
+	public function post($url, $params="{}", $responseElement="", $parameters=[]) {
631
+		$parameters ['immediatly']=true;
632
+		return $this->_post($url, $params, $responseElement, $parameters);
633 633
 	}
634 634
 
635 635
 	/**
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 	 * @param array $parameters
646 646
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
647 647
 	 */
648
-	public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
649
-		$parameters ["immediatly"] = false;
650
-		return $this->_post ( $url, $params, $responseElement, $parameters );
648
+	public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) {
649
+		$parameters ["immediatly"]=false;
650
+		return $this->_post($url, $params, $responseElement, $parameters);
651 651
 	}
652 652
 
653 653
 	/**
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
 	 * @param array $parameters
666 666
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
667 667
 	 */
668
-	public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) {
669
-		$this->setDefaultParameters ( $parameters, [ 
668
+	public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
669
+		$this->setDefaultParameters($parameters, [ 
670 670
 				"preventDefault" => true,
671 671
 				"stopPropagation" => true,
672 672
 				"immediatly" => true
673
-		] );
674
-		return $this->_add_event ( $element, $this->postDeferred ( $url, $params, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
673
+		]);
674
+		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
675 675
 	}
676 676
 
677 677
 	/**
@@ -688,65 +688,65 @@  discard block
 block discarded – undo
688 688
 	 * @param array $parameters
689 689
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"before"=>null,"listenerOn"=>false)
690 690
 	 */
691
-	public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array ()) {
692
-		return $this->postOn ( "click", $element, $url, $params, $responseElement, $parameters );
693
-	}
694
-	private function _postForm($url, $form, $responseElement, $parameters = [ ]) {
695
-		if (isset ( $this->params ["ajax"] )) {
696
-			extract ( $this->params ["ajax"] );
697
-		}
698
-		$params = "{}";
699
-		$validation = false;
700
-		\extract ( $parameters );
701
-		$async = ($async) ? "true" : "false";
702
-		$jsCallback = isset ( $jsCallback ) ? $jsCallback : "";
703
-		$retour = $this->_getAjaxUrl ( $url, $attr );
704
-		$retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');";
705
-		if (! isset ( $contentType ) || $contentType != 'false') {
706
-			$retour .= "\nvar params=$('#" . $form . "').serialize();\n";
707
-			if (isset ( $params )) {
708
-				$retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n";
691
+	public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) {
692
+		return $this->postOn("click", $element, $url, $params, $responseElement, $parameters);
693
+	}
694
+	private function _postForm($url, $form, $responseElement, $parameters=[]) {
695
+		if (isset ($this->params ["ajax"])) {
696
+			extract($this->params ["ajax"]);
697
+		}
698
+		$params="{}";
699
+		$validation=false;
700
+		\extract($parameters);
701
+		$async=($async) ? "true" : "false";
702
+		$jsCallback=isset ($jsCallback) ? $jsCallback : "";
703
+		$retour=$this->_getAjaxUrl($url, $attr);
704
+		$retour.="\n$('#".$form."').trigger('ajaxSubmit');";
705
+		if (!isset ($contentType) || $contentType!='false') {
706
+			$retour.="\nvar params=$('#".$form."').serialize();\n";
707
+			if (isset ($params)) {
708
+				$retour.="params+='&'+".self::_correctParams($params).";\n";
709 709
 			}
710 710
 		} else {
711
-			$retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n";
712
-		}
713
-		$responseElement = $this->_getResponseElement ( $responseElement );
714
-		$retour .= "var self=this;\n";
715
-		$before = isset ( $before ) ? $before : "";
716
-		$retour .= $before;
717
-		if ($hasLoader === true) {
718
-			$this->addLoading ( $retour, $responseElement, $ajaxLoader );
719
-		} elseif ($hasLoader === 'response') {
720
-			$this->addResponseLoading ( $retour, $responseElement, $ajaxLoader );
721
-		} elseif ($hasLoader === 'internal') {
722
-			$retour .= "\n$(this).addClass('loading');";
723
-		}
724
-		$ajaxParameters = [ 
711
+			$retour.="\nvar params=new FormData($('#".$form."')[0]);\n";
712
+		}
713
+		$responseElement=$this->_getResponseElement($responseElement);
714
+		$retour.="var self=this;\n";
715
+		$before=isset ($before) ? $before : "";
716
+		$retour.=$before;
717
+		if ($hasLoader===true) {
718
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
719
+		} elseif ($hasLoader==='response') {
720
+			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
721
+		} elseif ($hasLoader==='internal') {
722
+			$retour.="\n$(this).addClass('loading');";
723
+		}
724
+		$ajaxParameters=[ 
725 725
 				"url" => "url",
726 726
 				"method" => "'POST'",
727 727
 				"data" => "params",
728 728
 				"async" => $async
729 729
 		];
730
-		if (isset ( $headers )) {
731
-			$ajaxParameters ["headers"] = $headers;
730
+		if (isset ($headers)) {
731
+			$ajaxParameters ["headers"]=$headers;
732 732
 		}
733
-		if (isset ( $partial )) {
734
-			$ajaxParameters ["xhr"] = "xhrProvider";
735
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
733
+		if (isset ($partial)) {
734
+			$ajaxParameters ["xhr"]="xhrProvider";
735
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
736 736
 		}
737
-		$this->createAjaxParameters ( $ajaxParameters, $parameters );
738
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n";
739
-		$retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n";
737
+		$this->createAjaxParameters($ajaxParameters, $parameters);
738
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n";
739
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n";
740 740
 
741 741
 		if ($validation) {
742
-			$retour = "$('#" . $form . "').validate({submitHandler: function(form) {
743
-			" . $retour . "
742
+			$retour="$('#".$form."').validate({submitHandler: function(form) {
743
+			" . $retour."
744 744
 			}});\n";
745
-			$retour .= "$('#" . $form . "').submit();\n";
745
+			$retour.="$('#".$form."').submit();\n";
746 746
 		}
747
-		$retour = $this->_addJsCondition ( $jsCondition, $retour );
747
+		$retour=$this->_addJsCondition($jsCondition, $retour);
748 748
 		if ($immediatly)
749
-			$this->jquery_code_for_compile [] = $retour;
749
+			$this->jquery_code_for_compile []=$retour;
750 750
 		return $retour;
751 751
 	}
752 752
 
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 	 * @param array $parameters
763 763
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
764 764
 	 */
765
-	public function postForm($url, $form, $responseElement, $parameters = [ ]) {
766
-		$parameters ["immediatly"] = true;
767
-		return $this->_postForm ( $url, $form, $responseElement, $parameters );
765
+	public function postForm($url, $form, $responseElement, $parameters=[]) {
766
+		$parameters ["immediatly"]=true;
767
+		return $this->_postForm($url, $form, $responseElement, $parameters);
768 768
 	}
769 769
 
770 770
 	/**
@@ -780,9 +780,9 @@  discard block
 block discarded – undo
780 780
 	 * @param array $parameters
781 781
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
782 782
 	 */
783
-	public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) {
784
-		$parameters ["immediatly"] = false;
785
-		return $this->_postForm ( $url, $form, $responseElement, $parameters );
783
+	public function postFormDeferred($url, $form, $responseElement, $parameters=[]) {
784
+		$parameters ["immediatly"]=false;
785
+		return $this->_postForm($url, $form, $responseElement, $parameters);
786 786
 	}
787 787
 
788 788
 	/**
@@ -798,13 +798,13 @@  discard block
 block discarded – undo
798 798
 	 * @param array $parameters
799 799
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
800 800
 	 */
801
-	public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) {
802
-		$this->setDefaultParameters ( $parameters, [ 
801
+	public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
802
+		$this->setDefaultParameters($parameters, [ 
803 803
 				"preventDefault" => true,
804 804
 				"stopPropagation" => true,
805 805
 				"immediatly" => true
806
-		] );
807
-		return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
806
+		]);
807
+		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
808 808
 	}
809 809
 
810 810
 	/**
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	 * @param array $parameters
820 820
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
821 821
 	 */
822
-	public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) {
823
-		return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters );
822
+	public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) {
823
+		return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters);
824 824
 	}
825 825
 }
Please login to merge, or discard this patch.