Passed
Push — master ( 33a902...128edc )
by Jean-Christophe
01:57
created
Ajax/common/traits/JsUtilsAjaxTrait.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 	protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>";
18 18
 
19 19
 	abstract public function getUrl($url);
20
-	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true);
20
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true);
21 21
 
22
-	protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
23
-		if(isset($this->params["ajax"])){
22
+	protected function _ajax($method, $url, $responseElement="", $parameters=[]) {
23
+		if (isset($this->params["ajax"])) {
24 24
 			extract($this->params["ajax"]);
25 25
 		}
26 26
 		extract($parameters);
@@ -30,100 +30,100 @@  discard block
 block discarded – undo
30 30
 		$originalSelector=$responseElement;
31 31
 		$responseElement=$this->_getResponseElement($responseElement);
32 32
 		$retour.="var self=this;\n";
33
-		if($hasLoader===true && JString::isNotNull($responseElement)){
34
-			$this->addLoading($retour, $responseElement,$ajaxLoader);
35
-		}elseif($hasLoader==="internal"){
33
+		if ($hasLoader===true && JString::isNotNull($responseElement)) {
34
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
35
+		}elseif ($hasLoader==="internal") {
36 36
 			$retour.="\n$(this).addClass('loading');";
37 37
 		}
38
-		$ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"];
38
+		$ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"];
39 39
 		
40
-		$ajaxParameters["async"]=($async?"true":"false");
40
+		$ajaxParameters["async"]=($async ? "true" : "false");
41 41
 		
42
-		if(isset($params)){
42
+		if (isset($params)) {
43 43
 			$ajaxParameters["data"]=self::_correctParams($params);
44 44
 		}
45
-		if(isset($headers)){
45
+		if (isset($headers)) {
46 46
 			$ajaxParameters["headers"]=$headers;
47 47
 		}
48 48
 		$this->createAjaxParameters($ajaxParameters, $parameters);
49 49
 		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n";
50
-		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n";
51
-		$retour=$this->_addJsCondition($jsCondition,$retour);
50
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n";
51
+		$retour=$this->_addJsCondition($jsCondition, $retour);
52 52
 		if ($immediatly)
53 53
 			$this->jquery_code_for_compile[]=$retour;
54 54
 		return $retour;
55 55
 	}
56 56
 
57
-	protected function createAjaxParameters(&$original,$parameters){
58
-		$validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"];
59
-		foreach ($validParameters as $param=>$mask){
60
-			if(isset($parameters[$param])){
57
+	protected function createAjaxParameters(&$original, $parameters) {
58
+		$validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"];
59
+		foreach ($validParameters as $param=>$mask) {
60
+			if (isset($parameters[$param])) {
61 61
 				$original[$param]=\str_replace("%value%", $parameters[$param], $mask);
62 62
 			}
63 63
 		}
64 64
 	}
65 65
 
66
-	protected function implodeAjaxParameters($ajaxParameters){
67
-		$s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; }
66
+	protected function implodeAjaxParameters($ajaxParameters) {
67
+		$s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; }
68 68
 		return $s;
69 69
 	}
70 70
 
71
-	protected function _addJsCondition($jsCondition,$jsSource){
72
-		if(isset($jsCondition)){
71
+	protected function _addJsCondition($jsCondition, $jsSource) {
72
+		if (isset($jsCondition)) {
73 73
 			return "if(".$jsCondition."){\n".$jsSource."\n}";
74 74
 		}
75 75
 		return $jsSource;
76 76
 	}
77 77
 
78 78
 
79
-	protected function _getAjaxUrl($url,$attr){
79
+	protected function _getAjaxUrl($url, $attr) {
80 80
 		$url=$this->_correctAjaxUrl($url);
81 81
 		$retour="url='".$url."';";
82 82
 		$slash="/";
83
-		if(JString::endswith($url, "/")===true){
83
+		if (JString::endswith($url, "/")===true) {
84 84
 			$slash="";
85 85
 		}
86
-		if(JString::isNotNull($attr)){
87
-			if ($attr==="value"){
86
+		if (JString::isNotNull($attr)) {
87
+			if ($attr==="value") {
88 88
 				$retour.="url=url+'".$slash."'+$(this).val();\n";
89
-			}elseif ($attr==="html"){
89
+			}elseif ($attr==="html") {
90 90
 				$retour.="url=url+'".$slash."'+$(this).html();\n";
91
-			}elseif(\substr($attr, 0,3)==="js:"){
91
+			}elseif (\substr($attr, 0, 3)==="js:") {
92 92
 				$retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n";
93
-			}elseif($attr!==null && $attr!=="")
93
+			}elseif ($attr!==null && $attr!=="")
94 94
 				$retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n";
95 95
 		}
96 96
 		return $retour;
97 97
 	}
98 98
 	
99
-	protected function onPopstate(){
99
+	protected function onPopstate() {
100 100
 		return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};";
101 101
 	}
102 102
 
103
-	protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){
104
-		$retour="";$call=null;
103
+	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) {
104
+		$retour=""; $call=null;
105 105
 		if (JString::isNotNull($responseElement)) {
106
-			if(isset($ajaxTransition)){
106
+			if (isset($ajaxTransition)) {
107 107
 				$call=$this->setAjaxDataCall($ajaxTransition);
108
-			}elseif(isset($this->ajaxTransition)){
108
+			}elseif (isset($this->ajaxTransition)) {
109 109
 				$call=$this->ajaxTransition;
110 110
 			}
111
-			if(\is_callable($call))
112
-				$retour="\t".$call($responseElement,$jqueryDone).";\n";
111
+			if (\is_callable($call))
112
+				$retour="\t".$call($responseElement, $jqueryDone).";\n";
113 113
 			else
114 114
 				$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
115 115
 		}
116
-		if(isset($history)){
116
+		if (isset($history)) {
117 117
 			$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
118 118
 		}
119
-		if($hasLoader==="internal"){
119
+		if ($hasLoader==="internal") {
120 120
 			$retour.="\n$(self).removeClass('loading');";
121 121
 		}
122 122
 		$retour.="\t".$jsCallback."\n";
123 123
 		return $retour;
124 124
 	}
125 125
 
126
-	protected function _getResponseElement($responseElement){
126
+	protected function _getResponseElement($responseElement) {
127 127
 		if (JString::isNotNull($responseElement)) {
128 128
 			$responseElement=Javascript::prep_value($responseElement);
129 129
 			$responseElement=Javascript::prep_jquery_selector($responseElement);
@@ -134,33 +134,33 @@  discard block
 block discarded – undo
134 134
 	protected function _correctAjaxUrl($url) {
135 135
 		if ($url!=="/" && JString::endsWith($url, "/")===true)
136 136
 			$url=substr($url, 0, strlen($url)-1);
137
-			if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) {
137
+			if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) {
138 138
 				$url=$this->getUrl($url);
139 139
 			}
140 140
 			return $url;
141 141
 	}
142 142
 
143
-	public static function _correctParams($params){
144
-		if(JString::isNull($params)){
143
+	public static function _correctParams($params) {
144
+		if (JString::isNull($params)) {
145 145
 			return "";
146 146
 		}
147
-		if(\preg_match("@^\{.*?\}$@", $params)){
147
+		if (\preg_match("@^\{.*?\}$@", $params)) {
148 148
 			return '$.param('.$params.')';
149 149
 		}
150 150
 		return $params;
151 151
 	}
152 152
 
153
-	public static function _implodeParams($parameters){
153
+	public static function _implodeParams($parameters) {
154 154
 		$allParameters=[];
155
-		foreach ($parameters as $params){
156
-			if(isset($params))
155
+		foreach ($parameters as $params) {
156
+			if (isset($params))
157 157
 				$allParameters[]=self::_correctParams($params);
158 158
 		}
159 159
 		return \implode("+'&'+", $allParameters);
160 160
 	}
161 161
 
162
-	protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) {
163
-		if(!isset($ajaxLoader)){
162
+	protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) {
163
+		if (!isset($ajaxLoader)) {
164 164
 			$ajaxLoader=$this->ajaxLoader;
165 165
 		}
166 166
 		$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
 		$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
169 169
 	}
170 170
 
171
-	protected function setAjaxDataCall($params){
171
+	protected function setAjaxDataCall($params) {
172 172
 		$result=null;
173
-		if(!\is_callable($params)){
174
-			$result=function ($responseElement,$jqueryDone="html") use($params){
175
-				return AjaxTransition::{$params}($responseElement,$jqueryDone);
173
+		if (!\is_callable($params)) {
174
+			$result=function($responseElement, $jqueryDone="html") use($params){
175
+				return AjaxTransition::{$params}($responseElement, $jqueryDone);
176 176
 			};
177 177
 		}
178 178
 		return $result;
179 179
 	}
180 180
 
181
-	protected function setDefaultParameters(&$parameters,$default){
182
-		foreach ($default as $k=>$v){
183
-			if(!isset($parameters[$k]))
181
+	protected function setDefaultParameters(&$parameters, $default) {
182
+		foreach ($default as $k=>$v) {
183
+			if (!isset($parameters[$k]))
184 184
 				$parameters[$k]=$v;
185 185
 		}
186 186
 	}
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 	 * @param string $url The url of the request
195 195
 	 * @param string $responseElement selector of the HTML element displaying the answer
196 196
 	 */
197
-	private function _get($url, $responseElement="",$parameters=[]) {
198
-		return $this->_ajax("get", $url,$responseElement,$parameters);
197
+	private function _get($url, $responseElement="", $parameters=[]) {
198
+		return $this->_ajax("get", $url, $responseElement, $parameters);
199 199
 	}
200 200
 
201 201
 	/**
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	 * @param string $responseElement selector of the HTML element displaying the answer
205 205
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
206 206
 	 */
207
-	public function get($url, $responseElement="",$parameters=[]) {
207
+	public function get($url, $responseElement="", $parameters=[]) {
208 208
 		$parameters["immediatly"]=true;
209
-		return $this->_get($url,$responseElement,$parameters);
209
+		return $this->_get($url, $responseElement, $parameters);
210 210
 	}
211 211
 
212 212
 	/**
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @param string $responseElement selector of the HTML element displaying the answer
217 217
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
218 218
 	 */
219
-	public function ajax($method,$url, $responseElement="", $parameters=[]) {
219
+	public function ajax($method, $url, $responseElement="", $parameters=[]) {
220 220
 		$parameters["immediatly"]=true;
221
-		return $this->_ajax($method,$url,$responseElement,$parameters);
221
+		return $this->_ajax($method, $url, $responseElement, $parameters);
222 222
 	}
223 223
 
224 224
 	/**
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
 	 * @param string $responseElement selector of the HTML element displaying the answer
229 229
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
230 230
 	 */
231
-	public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) {
231
+	public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) {
232 232
 		$parameters["immediatly"]=false;
233
-		return $this->_ajax($method,$url,$responseElement,$parameters);
233
+		return $this->_ajax($method, $url, $responseElement, $parameters);
234 234
 	}
235 235
 
236 236
 	/**
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
 	 * @param string $method Method used
240 240
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
241 241
 	 */
242
-	private function _json($url, $method="get",$parameters=[]) {
243
-		$parameters=\array_merge($parameters,["hasLoader"=>false]);
242
+	private function _json($url, $method="get", $parameters=[]) {
243
+		$parameters=\array_merge($parameters, ["hasLoader"=>false]);
244 244
 		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
245 245
 		$context=isset($parameters['context']) ? $parameters['context'] : "document";
246 246
 		$retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){"
247 247
 				."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n";
248 248
 				$retour.="\t$(document).trigger('jsonReady',[data]);\n";
249 249
 		$parameters["jsCallback"]=$retour;
250
-		return $this->_ajax($method, $url,null,$parameters);
250
+		return $this->_ajax($method, $url, null, $parameters);
251 251
 	}
252 252
 
253 253
 	/**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
258 258
 	 */
259 259
 	public function json($url, $method="get", $parameters=[]) {
260
-		return $this->_json($url,$method,$parameters);
260
+		return $this->_json($url, $method, $parameters);
261 261
 	}
262 262
 
263 263
 	/**
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
 	 * @param string $method default get
269 269
 	 * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true)
270 270
 	 */
271
-	public function jsonOn($event,$element, $url,$method="get",$parameters=array()) {
272
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
273
-		return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
271
+	public function jsonOn($event, $element, $url, $method="get", $parameters=array()) {
272
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
273
+		return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
274 274
 	}
275 275
 
276 276
 	/**
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 */
282 282
 	public function jsonDeferred($url, $method="get", $parameters=[]) {
283 283
 		$parameters["immediatly"]=false;
284
-		return $this->_json($url,$method,$parameters);
284
+		return $this->_json($url, $method, $parameters);
285 285
 	}
286 286
 
287 287
 	/**
@@ -292,26 +292,26 @@  discard block
 block discarded – undo
292 292
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
293 293
 	 */
294 294
 	private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
295
-		$parameters=\array_merge($parameters,["hasLoader"=>false]);
295
+		$parameters=\array_merge($parameters, ["hasLoader"=>false]);
296 296
 		$rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json";
297 297
 		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
298 298
 		$context=isset($parameters['context']) ? $parameters['context'] : null;
299
-		if($context===null){
299
+		if ($context===null) {
300 300
 			$parent="$('".$maskSelector."').parent()";
301
-			$newElm = "$('#'+newId)";
302
-		}else{
301
+			$newElm="$('#'+newId)";
302
+		} else {
303 303
 			$parent=$context;
304
-			$newElm = $context.".find('#'+newId)";
304
+			$newElm=$context.".find('#'+newId)";
305 305
 		}
306 306
 		$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
307 307
 		$retour=$parent.".find('.{$rowClass}').remove();";
308 308
 		$retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\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();
309 309
 		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";
310
-		$retour.= $appendTo;
310
+		$retour.=$appendTo;
311 311
 		$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";
312 312
 		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
313 313
 		$parameters["jsCallback"]=$retour;
314
-		return $this->_ajax($method, $url,null,$parameters);
314
+		return $this->_ajax($method, $url, null, $parameters);
315 315
 	}
316 316
 
317 317
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
323 323
 	 */
324 324
 	public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
325
-		return $this->_jsonArray($maskSelector, $url,$method,$parameters);
325
+		return $this->_jsonArray($maskSelector, $url, $method, $parameters);
326 326
 	}
327 327
 
328 328
 	/**
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 	 * @param string $method Method used, default : get
346 346
 	 * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true)
347 347
 	 */
348
-	public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) {
349
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
350
-		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
348
+	public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) {
349
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
350
+		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
351 351
 	}
352 352
 
353 353
 	/**
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	public function getDeferred($url, $responseElement="", $parameters=[]) {
361 361
 		$parameters["immediatly"]=false;
362
-		return $this->_get($url, $responseElement,$parameters);
362
+		return $this->_get($url, $responseElement, $parameters);
363 363
 	}
364 364
 
365 365
 	/**
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 	 * @param array $parameters 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)
373 373
 	 */
374 374
 	public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
375
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
376
-		return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
375
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
376
+		return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
377 377
 	}
378 378
 
379 379
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @param array $parameters 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)
387 387
 	 */
388 388
 	public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) {
389
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]);
390
-		return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
389
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]);
390
+		return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
391 391
 	}
392 392
 
393 393
 	/**
@@ -414,9 +414,9 @@  discard block
 block discarded – undo
414 414
 		return $this->getOn("click", $element, $url, $responseElement, $parameters);
415 415
 	}
416 416
 
417
-	private function _post($url, $params="{}",$responseElement="", $parameters=[]) {
417
+	private function _post($url, $params="{}", $responseElement="", $parameters=[]) {
418 418
 		$parameters["params"]=$params;
419
-		return $this->_ajax("POST", $url,$responseElement,$parameters);
419
+		return $this->_ajax("POST", $url, $responseElement, $parameters);
420 420
 	}
421 421
 
422 422
 	/**
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 	 * @param string $params JSON parameters
427 427
 	 * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
428 428
 	 */
429
-	public function post($url, $params="{}",$responseElement="", $parameters=[]) {
430
-		return $this->_post($url, $params,$responseElement, $parameters);
429
+	public function post($url, $params="{}", $responseElement="", $parameters=[]) {
430
+		return $this->_post($url, $params, $responseElement, $parameters);
431 431
 	}
432 432
 
433 433
 	/**
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 	 * @param string $responseElement selector of the HTML element displaying the answer
439 439
 	 * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
440 440
 	 */
441
-	public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) {
441
+	public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) {
442 442
 		$parameters["immediatly"]=false;
443 443
 		return $this->_post($url, $params, $responseElement, $parameters);
444 444
 	}
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param array $parameters 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)
455 455
 	 */
456 456
 	public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
457
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
458
-		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
457
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
458
+		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
459 459
 	}
460 460
 
461 461
 	/**
@@ -472,33 +472,33 @@  discard block
 block discarded – undo
472 472
 	}
473 473
 
474 474
 	private function _postForm($url, $form, $responseElement, $parameters=[]) {
475
-		if(isset($this->params["ajax"])){
475
+		if (isset($this->params["ajax"])) {
476 476
 			extract($this->params["ajax"]);
477 477
 		}
478
-		$params="{}";$validation=false;
478
+		$params="{}"; $validation=false;
479 479
 		\extract($parameters);
480
-		$async=($async)?"true":"false";
480
+		$async=($async) ? "true" : "false";
481 481
 		$jsCallback=isset($jsCallback) ? $jsCallback : "";
482 482
 		$retour=$this->_getAjaxUrl($url, $attr);
483 483
 		$retour.="\n$('#".$form."').trigger('ajaxSubmit');";
484 484
 		$retour.="\nvar params=$('#".$form."').serialize();\n";
485
-		if(isset($params)){
485
+		if (isset($params)) {
486 486
 			$retour.="params+='&'+".self::_correctParams($params).";\n";
487 487
 		}
488 488
 		$responseElement=$this->_getResponseElement($responseElement);
489 489
 		$retour.="var self=this;\n";
490
-		if($hasLoader===true){
491
-			$this->addLoading($retour, $responseElement,$ajaxLoader);
492
-		}elseif($hasLoader==="internal"){
490
+		if ($hasLoader===true) {
491
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
492
+		}elseif ($hasLoader==="internal") {
493 493
 			$retour.="\n$(this).addClass('loading');";
494 494
 		}
495
-		$ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async];
496
-		if(isset($headers)){
495
+		$ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async];
496
+		if (isset($headers)) {
497 497
 			$ajaxParameters["headers"]=$headers;
498 498
 		}
499 499
 		$this->createAjaxParameters($ajaxParameters, $parameters);
500 500
 		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n";
501
-		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n";
501
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n";
502 502
 
503 503
 		if ($validation) {
504 504
 			$retour="$('#".$form."').validate({submitHandler: function(form) {
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param array $parameters 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)
549 549
 	 */
550 550
 	public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
551
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
552
-		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
551
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
552
+		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
553 553
 	}
554 554
 
555 555
 	/**
Please login to merge, or discard this patch.