Completed
Push — master ( f9eff0...85f0a8 )
by Jean-Christophe
03:15
created
Ajax/Jquery.php 1 patch
Braces   +98 added lines, -66 removed lines patch added patch discarded remove patch
@@ -424,8 +424,9 @@  discard block
 block discarded – undo
424 424
 		$element=$this->_prep_element($element);
425 425
 		$value=$this->_prep_value($value);
426 426
 		$str="$({$element}).after({$value});";
427
-		if ($immediatly)
428
-			$this->jquery_code_for_compile[]=$str;
427
+		if ($immediatly) {
428
+					$this->jquery_code_for_compile[]=$str;
429
+		}
429 430
 		return $str;
430 431
 	}
431 432
 
@@ -441,10 +442,12 @@  discard block
 block discarded – undo
441 442
 		if (isset($value)) {
442 443
 			$value=$this->_prep_value($value);
443 444
 			$str="$({$element}).attr(\"$attributeName\",{$value});";
444
-		} else
445
-			$str="$({$element}).attr(\"$attributeName\");";
446
-		if ($immediatly)
447
-			$this->jquery_code_for_compile[]=$str;
445
+		} else {
446
+					$str="$({$element}).attr(\"$attributeName\");";
447
+		}
448
+		if ($immediatly) {
449
+					$this->jquery_code_for_compile[]=$str;
450
+		}
448 451
 		return $str;
449 452
 	}
450 453
 
@@ -460,10 +463,12 @@  discard block
 block discarded – undo
460 463
 		if (isset($param)) {
461 464
 			$param=$this->_prep_value($param);
462 465
 			$str="$({$element}).{$jQueryCall}({$param});";
463
-		} else
464
-			$str="$({$element}).{$jQueryCall}();";
465
-			if ($immediatly)
466
-				$this->jquery_code_for_compile[]=$str;
466
+		} else {
467
+					$str="$({$element}).{$jQueryCall}();";
468
+		}
469
+			if ($immediatly) {
470
+							$this->jquery_code_for_compile[]=$str;
471
+			}
467 472
 			return $str;
468 473
 	}
469 474
 	/**
@@ -478,8 +483,9 @@  discard block
 block discarded – undo
478 483
 		$to=$this->_prep_element($to);
479 484
 		$element=$this->_prep_element($element);
480 485
 		$str="$({$to}).{$jQueryCall}({$element});";
481
-		if ($immediatly)
482
-			$this->jquery_code_for_compile[]=$str;
486
+		if ($immediatly) {
487
+					$this->jquery_code_for_compile[]=$str;
488
+		}
483 489
 			return $str;
484 490
 	}
485 491
 	// --------------------------------------------------------------------
@@ -516,8 +522,9 @@  discard block
 block discarded – undo
516 522
 
517 523
 		$str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
518 524
 
519
-		if ($immediatly)
520
-			$this->jquery_code_for_compile[]=$str;
525
+		if ($immediatly) {
526
+					$this->jquery_code_for_compile[]=$str;
527
+		}
521 528
 		return $str;
522 529
 	}
523 530
 
@@ -542,8 +549,9 @@  discard block
 block discarded – undo
542 549
 
543 550
 		$str="$({$element}).fadeIn({$speed}{$callback});";
544 551
 
545
-		if ($immediatly)
546
-			$this->jquery_code_for_compile[]=$str;
552
+		if ($immediatly) {
553
+					$this->jquery_code_for_compile[]=$str;
554
+		}
547 555
 		return $str;
548 556
 	}
549 557
 
@@ -568,8 +576,9 @@  discard block
 block discarded – undo
568 576
 
569 577
 		$str="$({$element}).fadeOut({$speed}{$callback});";
570 578
 
571
-		if ($immediatly)
572
-			$this->jquery_code_for_compile[]=$str;
579
+		if ($immediatly) {
580
+					$this->jquery_code_for_compile[]=$str;
581
+		}
573 582
 		return $str;
574 583
 	}
575 584
 
@@ -594,8 +603,9 @@  discard block
 block discarded – undo
594 603
 
595 604
 		$str="$({$element}).hide({$speed}{$callback});";
596 605
 
597
-		if ($immediatly)
598
-			$this->jquery_code_for_compile[]=$str;
606
+		if ($immediatly) {
607
+					$this->jquery_code_for_compile[]=$str;
608
+		}
599 609
 		return $str;
600 610
 	}
601 611
 
@@ -622,8 +632,9 @@  discard block
 block discarded – undo
622 632
 
623 633
 		$str="$({$element}).slideUp({$speed}{$callback});";
624 634
 
625
-		if ($immediatly)
626
-			$this->jquery_code_for_compile[]=$str;
635
+		if ($immediatly) {
636
+					$this->jquery_code_for_compile[]=$str;
637
+		}
627 638
 		return $str;
628 639
 	}
629 640
 
@@ -648,8 +659,9 @@  discard block
 block discarded – undo
648 659
 
649 660
 		$str="$({$element}).slideDown({$speed}{$callback});";
650 661
 
651
-		if ($immediatly)
652
-			$this->jquery_code_for_compile[]=$str;
662
+		if ($immediatly) {
663
+					$this->jquery_code_for_compile[]=$str;
664
+		}
653 665
 		return $str;
654 666
 	}
655 667
 
@@ -674,8 +686,9 @@  discard block
 block discarded – undo
674 686
 
675 687
 		$str="$({$element}).slideToggle({$speed}{$callback});";
676 688
 
677
-		if ($immediatly)
678
-			$this->jquery_code_for_compile[]=$str;
689
+		if ($immediatly) {
690
+					$this->jquery_code_for_compile[]=$str;
691
+		}
679 692
 		return $str;
680 693
 	}
681 694
 
@@ -692,8 +705,9 @@  discard block
 block discarded – undo
692 705
 		$element=$this->_prep_element($element);
693 706
 		$str="$({$element}).toggle();";
694 707
 
695
-		if ($immediatly)
696
-			$this->jquery_code_for_compile[]=$str;
708
+		if ($immediatly) {
709
+					$this->jquery_code_for_compile[]=$str;
710
+		}
697 711
 		return $str;
698 712
 	}
699 713
 
@@ -709,8 +723,9 @@  discard block
 block discarded – undo
709 723
 		$element=$this->_prep_element($element);
710 724
 		$str="$({$element}).trigger(\"$event\");";
711 725
 
712
-		if ($immediatly)
713
-			$this->jquery_code_for_compile[]=$str;
726
+		if ($immediatly) {
727
+					$this->jquery_code_for_compile[]=$str;
728
+		}
714 729
 		return $str;
715 730
 	}
716 731
 
@@ -735,8 +750,9 @@  discard block
 block discarded – undo
735 750
 
736 751
 		$str="$({$element}).show({$speed}{$callback});";
737 752
 
738
-		if ($immediatly)
739
-			$this->jquery_code_for_compile[]=$str;
753
+		if ($immediatly) {
754
+					$this->jquery_code_for_compile[]=$str;
755
+		}
740 756
 		return $str;
741 757
 	}
742 758
 
@@ -754,8 +770,9 @@  discard block
 block discarded – undo
754 770
 			$str.="else{".$jsCodeIfFalse."}";
755 771
 		}
756 772
 
757
-		if ($immediatly)
758
-			$this->jquery_code_for_compile[]=$str;
773
+		if ($immediatly) {
774
+					$this->jquery_code_for_compile[]=$str;
775
+		}
759 776
 		return $str;
760 777
 	}
761 778
 
@@ -821,12 +838,14 @@  discard block
 block discarded – undo
821 838
 		if ($stopPropagation===true) {
822 839
 			$js="event.stopPropagation();\n".$js;
823 840
 		}
824
-		if (array_search($event, $this->jquery_events)===false)
825
-			$event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n";
826
-		else
827
-			$event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n";
828
-		if($immediatly)
829
-			$this->jquery_code_for_compile[]=$event;
841
+		if (array_search($event, $this->jquery_events)===false) {
842
+					$event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n";
843
+		} else {
844
+					$event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n";
845
+		}
846
+		if($immediatly) {
847
+					$this->jquery_code_for_compile[]=$event;
848
+		}
830 849
 		return $event;
831 850
 	}
832 851
 
@@ -879,8 +898,9 @@  discard block
 block discarded – undo
879 898
 		}
880 899
 		$output=($script_tags===FALSE) ? $script : $this->inline($script);
881 900
 
882
-		if ($view!=NULL)
883
-			$view->setVar($view_var, $output);
901
+		if ($view!=NULL) {
902
+					$view->setVar($view_var, $output);
903
+		}
884 904
 		return $output;
885 905
 	}
886 906
 
@@ -1003,8 +1023,9 @@  discard block
 block discarded – undo
1003 1023
 		}
1004 1024
 		$retour.="$.".$method."(url,".$params.").done(function( data ) {\n";
1005 1025
 		$retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n";
1006
-		if ($immediatly)
1007
-			$this->jquery_code_for_compile[]=$retour;
1026
+		if ($immediatly) {
1027
+					$this->jquery_code_for_compile[]=$retour;
1028
+		}
1008 1029
 		return $retour;
1009 1030
 	}
1010 1031
 
@@ -1012,13 +1033,15 @@  discard block
 block discarded – undo
1012 1033
 		$url=$this->_correctAjaxUrl($url);
1013 1034
 		$retour="url='".$url."';\n";
1014 1035
 		$slash="/";
1015
-		if(PhalconUtils::endsWith($url, "/"))
1016
-			$slash="";
1036
+		if(PhalconUtils::endsWith($url, "/")) {
1037
+					$slash="";
1038
+		}
1017 1039
 		if(JString::isNotNull($attr)){
1018
-			if ($attr=="value")
1019
-				$retour.="url=url+'".$slash."'+$(this).val();\n";
1020
-			else if($attr!=null && $attr!=="")
1021
-				$retour.="url=url+'".$slash."'+$(this).attr('".$attr."');\n";
1040
+			if ($attr=="value") {
1041
+							$retour.="url=url+'".$slash."'+$(this).val();\n";
1042
+			} else if($attr!=null && $attr!=="") {
1043
+							$retour.="url=url+'".$slash."'+$(this).attr('".$attr."');\n";
1044
+			}
1022 1045
 		}
1023 1046
 		return $retour;
1024 1047
 	}
@@ -1040,8 +1063,9 @@  discard block
 block discarded – undo
1040 1063
 	}
1041 1064
 
1042 1065
 	protected function _correctAjaxUrl($url) {
1043
-		if (PhalconUtils::endsWith($url, "/"))
1044
-			$url=substr($url, 0, strlen($url)-1);
1066
+		if (PhalconUtils::endsWith($url, "/")) {
1067
+					$url=substr($url, 0, strlen($url)-1);
1068
+		}
1045 1069
 		if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) {
1046 1070
 			$url=$this->_di->get("url")->get($url);
1047 1071
 		}
@@ -1065,8 +1089,9 @@  discard block
 block discarded – undo
1065 1089
 		$retour.="\t".$jsCallback."\n".
1066 1090
 				"\t$(document).trigger('jsonReady',[data]);\n".
1067 1091
 		"});\n";
1068
-		if ($immediatly)
1069
-			$this->jquery_code_for_compile[]=$retour;
1092
+		if ($immediatly) {
1093
+					$this->jquery_code_for_compile[]=$retour;
1094
+		}
1070 1095
 		return $retour;
1071 1096
 	}
1072 1097
 
@@ -1105,7 +1130,7 @@  discard block
 block discarded – undo
1105 1130
 		if($context===null){
1106 1131
 			$appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n";
1107 1132
 			$newElm = "$('#'+newId)";
1108
-		}else{
1133
+		} else{
1109 1134
 			$appendTo="\t\tnewElm.appendTo(".$context.");\n";
1110 1135
 			$newElm = $context.".find('#'+newId)";
1111 1136
 		}
@@ -1115,8 +1140,9 @@  discard block
 block discarded – undo
1115 1140
 		$retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n";
1116 1141
 		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
1117 1142
 		$retour.="\t".$jsCallback."\n"."});\n";
1118
-		if ($immediatly)
1119
-			$this->jquery_code_for_compile[]=$retour;
1143
+		if ($immediatly) {
1144
+					$this->jquery_code_for_compile[]=$retour;
1145
+		}
1120 1146
 		return $retour;
1121 1147
 	}
1122 1148
 	/**
@@ -1157,8 +1183,9 @@  discard block
 block discarded – undo
1157 1183
 			}});\n";
1158 1184
 			$retour.="$('#".$form."').submit();\n";
1159 1185
 		}
1160
-		if ($immediatly)
1161
-			$this->jquery_code_for_compile[]=$retour;
1186
+		if ($immediatly) {
1187
+					$this->jquery_code_for_compile[]=$retour;
1188
+		}
1162 1189
 		return $retour;
1163 1190
 	}
1164 1191
 
@@ -1238,11 +1265,13 @@  discard block
 block discarded – undo
1238 1265
 	public function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) {
1239 1266
 		$param=$this->_prep_value($param);
1240 1267
 		$callback="";
1241
-		if ($jsCallback!="")
1242
-			$callback=", function(event){\n{$jsCallback}\n}";
1268
+		if ($jsCallback!="") {
1269
+					$callback=", function(event){\n{$jsCallback}\n}";
1270
+		}
1243 1271
 		$script="$(".$this->_prep_element($element).").".$jqueryCall."(".$param.$callback.");\n";
1244
-		if ($immediatly)
1245
-			$this->jquery_code_for_compile[]=$script;
1272
+		if ($immediatly) {
1273
+					$this->jquery_code_for_compile[]=$script;
1274
+		}
1246 1275
 		return $script;
1247 1276
 	}
1248 1277
 
@@ -1271,8 +1300,9 @@  discard block
 block discarded – undo
1271 1300
 	 */
1272 1301
 	public function _exec($js, $immediatly=false) {
1273 1302
 		$script=$js."\n";
1274
-		if ($immediatly)
1275
-			$this->jquery_code_for_compile[]=$script;
1303
+		if ($immediatly) {
1304
+					$this->jquery_code_for_compile[]=$script;
1305
+		}
1276 1306
 		return $script;
1277 1307
 	}
1278 1308
 
@@ -1291,7 +1321,9 @@  discard block
 block discarded – undo
1291 1321
 	}
1292 1322
 
1293 1323
 	private function minify($input) {
1294
-	if(trim($input) === "") return $input;
1324
+	if(trim($input) === "") {
1325
+		return $input;
1326
+	}
1295 1327
 	return preg_replace(
1296 1328
 			array(
1297 1329
 					// Remove comment(s)
Please login to merge, or discard this patch.