Passed
Push — master ( 82c0ff...8e3dfb )
by Jean-Christophe
01:38
created
Ajax/common/traits/JsUtilsActionsTrait.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 trait JsUtilsActionsTrait {
13 13
 
14
-	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true);
14
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true);
15 15
 	/**
16 16
 	 * show or hide with effect
17 17
 	 *
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * @param boolean $immediatly defers the execution if set to false
23 23
 	 * @return string
24 24
 	 */
25
-	protected function _showHideWithEffect($action,$element='this', $speed='', $callback='', $immediatly=false) {
25
+	protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) {
26 26
 		$element=Javascript::prep_element($element);
27 27
 		$speed=$this->_validate_speed($speed);
28 28
 		if ($callback!='') {
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	 * @return string
40 40
 	 */
41 41
 	private function _validate_speed($speed) {
42
-		if (in_array($speed, array (
43
-				'slow','normal','fast'
42
+		if (in_array($speed, array(
43
+				'slow', 'normal', 'fast'
44 44
 		))) {
45 45
 			$speed='"'.$speed.'"';
46 46
 		} elseif (preg_match("/[^0-9]/", $speed)) {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param string $param
58 58
 	 * @param boolean $immediatly delayed if false
59 59
 	 */
60
-	public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) {
60
+	public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) {
61 61
 		$element=Javascript::prep_element($element);
62 62
 		if (isset($param)) {
63 63
 			$param=Javascript::prep_value($param);
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @param boolean $immediatly delayed if false
78 78
 	 * @return string
79 79
 	 */
80
-	public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) {
80
+	public function _genericCallElement($jQueryCall, $to='this', $element, $immediatly=false) {
81 81
 		$to=Javascript::prep_element($to);
82 82
 		$element=Javascript::prep_element($element);
83 83
 		$str="$({$to}).{$jQueryCall}({$element});";
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @return string
95 95
 	 */
96 96
 	public function addClass($element='this', $class='', $immediatly=false) {
97
-		return $this->_genericCallValue('addClass',$element, $class, $immediatly);
97
+		return $this->_genericCallValue('addClass', $element, $class, $immediatly);
98 98
 	}
99 99
 
100 100
 	/**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * @param boolean $immediatly defers the execution if set to false
105 105
 	 * @return string
106 106
 	 */
107
-	public function after($to, $element, $immediatly=false){
108
-		return $this->_genericCallElement('after',$to, $element, $immediatly);
107
+	public function after($to, $element, $immediatly=false) {
108
+		return $this->_genericCallElement('after', $to, $element, $immediatly);
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 * @param boolean $immediatly defers the execution if set to false
116 116
 	 * @return string
117 117
 	 */
118
-	public function before($to, $element, $immediatly=false){
119
-		return $this->_genericCallElement('before',$to, $element, $immediatly);
118
+	public function before($to, $element, $immediatly=false) {
119
+		return $this->_genericCallElement('before', $to, $element, $immediatly);
120 120
 	}
121 121
 
122 122
 	/**
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param string $value
145 145
 	 * @param boolean $immediatly defers the execution if set to false
146 146
 	 */
147
-	public function val($element='this',$value='',$immediatly=false){
148
-		return $this->_genericCallValue('val',$element,$value,$immediatly);
147
+	public function val($element='this', $value='', $immediatly=false) {
148
+		return $this->_genericCallValue('val', $element, $value, $immediatly);
149 149
 	}
150 150
 
151 151
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @param boolean $immediatly defers the execution if set to false
156 156
 	 */
157 157
 	public function html($element='this', $value='', $immediatly=false) {
158
-		return $this->_genericCallValue('html',$element, $value, $immediatly);
158
+		return $this->_genericCallValue('html', $element, $value, $immediatly);
159 159
 	}
160 160
 
161 161
 	/**
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 
175 175
 		$animations="\t\t\t";
176 176
 		if (\is_array($params)) {
177
-			foreach ( $params as $param => $value ) {
177
+			foreach ($params as $param => $value) {
178 178
 				$animations.=$param.': \''.$value.'\', ';
179 179
 			}
180 180
 		}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @return string
204 204
 	 */
205 205
 	public function append($to, $element, $immediatly=false) {
206
-		return $this->_genericCallElement('append',$to, $element, $immediatly);
206
+		return $this->_genericCallElement('append', $to, $element, $immediatly);
207 207
 	}
208 208
 
209 209
 	/**
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 * @return string
215 215
 	 */
216 216
 	public function prepend($to, $element, $immediatly=false) {
217
-		return $this->_genericCallElement('prepend',$to, $element, $immediatly);
217
+		return $this->_genericCallElement('prepend', $to, $element, $immediatly);
218 218
 	}
219 219
 
220 220
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @return string
228 228
 	 */
229 229
 	public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) {
230
-		return $this->_showHideWithEffect("fadeIn",$element,$speed,$callback,$immediatly);
230
+		return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly);
231 231
 	}
232 232
 
233 233
 	/**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @return string
241 241
 	 */
242 242
 	public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) {
243
-		return $this->_showHideWithEffect("fadeOut",$element,$speed,$callback,$immediatly);
243
+		return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly);
244 244
 	}
245 245
 
246 246
 	/**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @return string
254 254
 	 */
255 255
 	public function slideUp($element='this', $speed='', $callback='', $immediatly=false) {
256
-		return $this->_showHideWithEffect("slideUp",$element,$speed,$callback,$immediatly);
256
+		return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly);
257 257
 	}
258 258
 
259 259
 	/**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 * @return string
266 266
 	 */
267 267
 	public function removeClass($element='this', $class='', $immediatly=false) {
268
-		return $this->_genericCallValue('removeClass',$element, $class, $immediatly);
268
+		return $this->_genericCallValue('removeClass', $element, $class, $immediatly);
269 269
 	}
270 270
 
271 271
 	/**
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @return string
279 279
 	 */
280 280
 	public function slideDown($element='this', $speed='', $callback='', $immediatly=false) {
281
-		return $this->_showHideWithEffect("slideDown",$element,$speed,$callback,$immediatly);
281
+		return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly);
282 282
 	}
283 283
 
284 284
 	/**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return string
292 292
 	 */
293 293
 	public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) {
294
-		return $this->_showHideWithEffect("slideToggle",$element,$speed,$callback,$immediatly);
294
+		return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly);
295 295
 	}
296 296
 
297 297
 	/**
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @return string
305 305
 	 */
306 306
 	public function hide($element='this', $speed='', $callback='', $immediatly=false) {
307
-		return $this->_showHideWithEffect("hide",$element,$speed,$callback,$immediatly);
307
+		return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly);
308 308
 	}
309 309
 
310 310
 	/**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 	 * @return string
318 318
 	 */
319 319
 	public function toggle($element='this', $speed='', $callback='', $immediatly=false) {
320
-		return $this->_showHideWithEffect("toggle",$element,$speed,$callback,$immediatly);
320
+		return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly);
321 321
 	}
322 322
 
323 323
 	/**
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	 * @return string
330 330
 	 */
331 331
 	public function toggleClass($element='this', $class='', $immediatly=false) {
332
-		return $this->_genericCallValue('toggleClass',$element, $class, $immediatly);
332
+		return $this->_genericCallValue('toggleClass', $element, $class, $immediatly);
333 333
 	}
334 334
 
335 335
 	/**
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	 * @return string
358 358
 	 */
359 359
 	public function show($element='this', $speed='', $callback='', $immediatly=false) {
360
-		return $this->_showHideWithEffect("show",$element,$speed,$callback,$immediatly);
360
+		return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly);
361 361
 	}
362 362
 
363 363
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 */
370 370
 	public function sortable($element, $options=array()) {
371 371
 		if (count($options)>0) {
372
-			$sort_options=array ();
373
-			foreach ( $options as $k => $v ) {
372
+			$sort_options=array();
373
+			foreach ($options as $k => $v) {
374 374
 				$sort_options[]="\n\t\t".$k.': '.$v."";
375 375
 			}
376 376
 			$sort_options=implode(",", $sort_options);
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 	 * @param boolean $immediatly
468 468
 	 * @return string
469 469
 	 */
470
-	private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) {
471
-		return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly);
470
+	private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) {
471
+		return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly);
472 472
 	}
473 473
 
474 474
 	/**
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		$preventDefault=false;
487 487
 		$immediatly=true;
488 488
 		extract($parameters);
489
-		return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback,$immediatly);
489
+		return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly);
490 490
 	}
491 491
 
492 492
 	/**
@@ -527,11 +527,11 @@  discard block
 block discarded – undo
527 527
 		$preventDefault=false;
528 528
 		$immediatly=true;
529 529
 		extract($parameters);
530
-		$script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation,$immediatly);
530
+		$script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly);
531 531
 		return $script;
532 532
 	}
533 533
 	
534
-	public function setJsonToElement($json,$elementClass="_element",$immediatly=true){
534
+	public function setJsonToElement($json, $elementClass="_element", $immediatly=true) {
535 535
 		$retour="var data={$json};"
536 536
 				."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);"
537 537
 				."\n\tvar pk=data['pk'];var object=data['object'];"
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 				."\n\t});"
543 543
 				."\n}};\n";
544 544
 		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
545
-		return $this->exec($retour,$immediatly);
545
+		return $this->exec($retour, $immediatly);
546 546
 	}
547 547
 	
548 548
 	/**
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
 	 * @param string $element The element selector
551 551
 	 * @param array $parameters default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true)
552 552
 	 */
553
-	public function setDraggable($element,$parameters=[]){
553
+	public function setDraggable($element, $parameters=[]) {
554 554
 		$attr="id";
555 555
 		extract($parameters);
556
-		$script=$this->_add_event($element, Javascript::draggable($attr), "dragstart",$parameters);
556
+		$script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $parameters);
557 557
 		return $script;
558 558
 	}
559 559
 	
@@ -563,13 +563,13 @@  discard block
 block discarded – undo
563 563
 	 * @param array $parameters default : array("attr"=>"id","stopPropagation"=>false,"immediatly"=>true,"jqueryDone"=>"append")
564 564
 	 * @param string $jsCallback the js script to call when element is dropped
565 565
 	 */
566
-	public function asDropZone($element,$jsCallback="",$parameters=[]){
566
+	public function asDropZone($element, $jsCallback="", $parameters=[]) {
567 567
 		$stopPropagation=false;
568 568
 		$immediatly=true;
569 569
 		$jqueryDone="append";
570
-		$script=$this->_add_event($element, '', "dragover",true,$stopPropagation,$immediatly);
570
+		$script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly);
571 571
 		extract($parameters);
572
-		$script.=$this->_add_event($element, Javascript::dropZone($jqueryDone,$jsCallback), "drop",true,$stopPropagation,$immediatly);
572
+		$script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly);
573 573
 		return $script;
574 574
 	}
575 575
 	
@@ -581,16 +581,16 @@  discard block
 block discarded – undo
581 581
 	 * @param boolean $immediatly delayed if false
582 582
 	 * @return string
583 583
 	 */
584
-	public function interval($jsCode,$time,$globalName=null,$immediatly=true){
585
-		if(!Javascript::isFunction($jsCode)){
584
+	public function interval($jsCode, $time, $globalName=null, $immediatly=true) {
585
+		if (!Javascript::isFunction($jsCode)) {
586 586
 			$jsCode="function(){\n".$jsCode."\n}";
587 587
 		}
588
-		if(isset($globalName)){
588
+		if (isset($globalName)) {
589 589
 			$script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});";
590
-		}else{
590
+		} else {
591 591
 			$script="setInterval({$jsCode},{$time});";
592 592
 		}
593
-		return $this->exec($script,$immediatly);
593
+		return $this->exec($script, $immediatly);
594 594
 	}
595 595
 	
596 596
 	/**
@@ -599,8 +599,8 @@  discard block
 block discarded – undo
599 599
 	 * @param boolean $immediatly delayed if false
600 600
 	 * @return string
601 601
 	 */
602
-	public function clearInterval($globalName,$immediatly=true){
603
-		return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}",$immediatly);
602
+	public function clearInterval($globalName, $immediatly=true) {
603
+		return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly);
604 604
 	}
605 605
 	
606 606
 	/**
@@ -613,17 +613,17 @@  discard block
 block discarded – undo
613 613
 	 * @param boolean $immediatly delayed if false
614 614
 	 * @return string
615 615
 	 */
616
-	public function counter($counterSelector,$value=0,$limit=0,$globalName=null,$countDown=true,$immediatly=true){
616
+	public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) {
617 617
 		$stop="";
618
-		if($countDown){
618
+		if ($countDown) {
619 619
 			$stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}";
620
-		}else{
621
-			if($limit!=0){
620
+		} else {
621
+			if ($limit!=0) {
622 622
 				$stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}";
623 623
 			}
624 624
 		}
625 625
 		$global="";
626
-		if(isset($globalName)){
626
+		if (isset($globalName)) {
627 627
 			$global="\nwindow.{$globalName}=interval;";
628 628
 		}
629 629
 		$timer="var startTimer=function(duration, display) {var timer = duration, minutes, seconds;
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 										".$global."
640 640
 										}";
641 641
 		$element='$("'.$counterSelector.'")';
642
-		return $this->exec($timer."\nstartTimer(".$value.",".$element.");",$immediatly);
642
+		return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly);
643 643
 	}
644 644
 	
645 645
 	/**
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 * @param boolean $countDown count down if true or elapse if false
654 654
 	 * @return string
655 655
 	 */
656
-	public function counterOn($element,$event,$counterSelector,$value=0,$limit=0,$globalName=null,$countDown=true){
657
-		return $this->execOn($event, $element, $this->counter($counterSelector,$value,$limit,$globalName,$countDown,false));
656
+	public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) {
657
+		return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false));
658 658
 	}
659 659
 }
Please login to merge, or discard this patch.