Passed
Push — master ( b91ed8...b5945e )
by Jean-Christophe
02:03
created
Ajax/common/traits/JsUtilsAjaxTrait.php 1 patch
Spacing   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -15,76 +15,76 @@  discard block
 block discarded – undo
15 15
 
16 16
 	protected $ajaxTransition;
17 17
 
18
-	protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>";
18
+	protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>";
19 19
 
20 20
 	abstract public function getUrl($url);
21 21
 
22
-	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn = false);
22
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false);
23 23
 
24
-	abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true);
24
+	abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true);
25 25
 
26
-	protected function _ajax($method, $url, $responseElement = '', $parameters = []) {
26
+	protected function _ajax($method, $url, $responseElement='', $parameters=[]) {
27 27
 		if (isset($this->params['ajax'])) {
28 28
 			extract($this->params['ajax']);
29 29
 		}
30 30
 		extract($parameters);
31 31
 
32
-		$jsCallback = isset($jsCallback) ? $jsCallback : '';
33
-		$retour = $this->_getAjaxUrl($url, $attr);
34
-		$originalSelector = $responseElement;
35
-		$responseElement = $this->_getResponseElement($responseElement);
36
-		$retour .= "var self=this;\n";
37
-		$before = isset($before) ? $before : "";
38
-		$retour .= $before;
39
-		if ($hasLoader === true && JString::isNotNull($responseElement)) {
32
+		$jsCallback=isset($jsCallback) ? $jsCallback : '';
33
+		$retour=$this->_getAjaxUrl($url, $attr);
34
+		$originalSelector=$responseElement;
35
+		$responseElement=$this->_getResponseElement($responseElement);
36
+		$retour.="var self=this;\n";
37
+		$before=isset($before) ? $before : "";
38
+		$retour.=$before;
39
+		if ($hasLoader===true && JString::isNotNull($responseElement)) {
40 40
 			$this->addLoading($retour, $responseElement, $ajaxLoader);
41
-		} elseif ($hasLoader === 'response') {
41
+		} elseif ($hasLoader==='response') {
42 42
 			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
43
-		} elseif ($hasLoader === 'internal-x') {
43
+		} elseif ($hasLoader==='internal-x') {
44 44
 			$this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader);
45
-		} elseif ($hasLoader === 'internal') {
46
-			$retour .= "\n$(this).addClass('loading');";
45
+		} elseif ($hasLoader==='internal') {
46
+			$retour.="\n$(this).addClass('loading');";
47 47
 		} elseif (\is_string($hasLoader)) {
48 48
 			$this->addLoading($retour, $hasLoader, $ajaxLoader);
49 49
 		}
50
-		$ajaxParameters = [
50
+		$ajaxParameters=[
51 51
 			"url" => "url",
52
-			"method" => "'" . \strtoupper($method) . "'"
52
+			"method" => "'".\strtoupper($method)."'"
53 53
 		];
54 54
 
55
-		$ajaxParameters["async"] = ($async ? "true" : "false");
55
+		$ajaxParameters["async"]=($async ? "true" : "false");
56 56
 
57 57
 		if (isset($params)) {
58
-			$ajaxParameters["data"] = self::_correctParams($params, $parameters);
58
+			$ajaxParameters["data"]=self::_correctParams($params, $parameters);
59 59
 		}
60 60
 		if (isset($headers)) {
61
-			$ajaxParameters["headers"] = $headers;
61
+			$ajaxParameters["headers"]=$headers;
62 62
 		}
63 63
 		if ($csrf) {
64
-			$csrf = (is_string($csrf)) ? $csrf : 'csrf-token';
65
-			$parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));";
64
+			$csrf=(is_string($csrf)) ? $csrf : 'csrf-token';
65
+			$parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));";
66 66
 		}
67 67
 		if (isset($partial)) {
68
-			$ajaxParameters["xhr"] = "xhrProvider";
69
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
68
+			$ajaxParameters["xhr"]="xhrProvider";
69
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
70 70
 		}
71 71
 		$this->createAjaxParameters($ajaxParameters, $parameters);
72
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n";
73
-		$retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null)) . "})";
72
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n";
73
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null))."})";
74 74
 		if (isset($error)) {
75
-			$retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})';
75
+			$retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})';
76 76
 		}
77
-		$retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})';
78
-		$retour .= ";\n";
79
-		$retour = $this->_addJsCondition($jsCondition, $retour);
77
+		$retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})';
78
+		$retour.=";\n";
79
+		$retour=$this->_addJsCondition($jsCondition, $retour);
80 80
 		if ($immediatly) {
81
-			$this->jquery_code_for_compile[] = $retour;
81
+			$this->jquery_code_for_compile[]=$retour;
82 82
 		}
83 83
 		return $retour;
84 84
 	}
85 85
 
86 86
 	protected function createAjaxParameters(&$original, $parameters) {
87
-		$validParameters = [
87
+		$validParameters=[
88 88
 			"contentType" => "%value%",
89 89
 			"dataType" => "'%value%'",
90 90
 			"beforeSend" => "function(jqXHR,settings){%value%}",
@@ -93,21 +93,21 @@  discard block
 block discarded – undo
93 93
 		];
94 94
 		foreach ($validParameters as $param => $mask) {
95 95
 			if (isset($parameters[$param])) {
96
-				$original[$param] = \str_replace("%value%", $parameters[$param], $mask);
96
+				$original[$param]=\str_replace("%value%", $parameters[$param], $mask);
97 97
 			}
98 98
 		}
99 99
 	}
100 100
 
101 101
 	protected function implodeAjaxParameters($ajaxParameters) {
102
-		$s = '';
102
+		$s='';
103 103
 		foreach ($ajaxParameters as $k => $v) {
104
-			if ($s !== '') {
105
-				$s .= ',';
104
+			if ($s!=='') {
105
+				$s.=',';
106 106
 			}
107 107
 			if (is_array($v)) {
108
-				$s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}";
108
+				$s.="'{$k}':{".self::implodeAjaxParameters($v)."}";
109 109
 			} else {
110
-				$s .= "'{$k}':{$v}";
110
+				$s.="'{$k}':{$v}";
111 111
 			}
112 112
 		}
113 113
 		return $s;
@@ -115,29 +115,29 @@  discard block
 block discarded – undo
115 115
 
116 116
 	protected function _addJsCondition($jsCondition, $jsSource) {
117 117
 		if (isset($jsCondition)) {
118
-			return "if(" . $jsCondition . "){\n" . $jsSource . "\n}";
118
+			return "if(".$jsCondition."){\n".$jsSource."\n}";
119 119
 		}
120 120
 		return $jsSource;
121 121
 	}
122 122
 
123 123
 	protected function _getAjaxUrl($url, $attr) {
124
-		$url = $this->_correctAjaxUrl($url);
125
-		$retour = "url='" . $url . "';";
126
-		$slash = "/";
127
-		if (JString::endswith($url, "/") === true) {
128
-			$slash = "";
124
+		$url=$this->_correctAjaxUrl($url);
125
+		$retour="url='".$url."';";
126
+		$slash="/";
127
+		if (JString::endswith($url, "/")===true) {
128
+			$slash="";
129 129
 		}
130 130
 
131 131
 		if (JString::isNotNull($attr)) {
132
-			if ($attr === "value") {
133
-				$retour .= "url=url+'" . $slash . "'+$(this).val();\n";
134
-			} elseif ($attr === "html") {
135
-				$retour .= "url=url+'" . $slash . "'+$(this).html();\n";
136
-			} elseif (\substr($attr, 0, 3) === "js:") {
137
-				$retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n";
138
-			} elseif ($attr !== null && $attr !== "") {
139
-				$retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';";
140
-				$retour .= "url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'" . $slash . "'+elmUrl:elmUrl;\n";
132
+			if ($attr==="value") {
133
+				$retour.="url=url+'".$slash."'+$(this).val();\n";
134
+			} elseif ($attr==="html") {
135
+				$retour.="url=url+'".$slash."'+$(this).html();\n";
136
+			} elseif (\substr($attr, 0, 3)==="js:") {
137
+				$retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n";
138
+			} elseif ($attr!==null && $attr!=="") {
139
+				$retour.="let elmUrl=$(this).attr('".$attr."')||'';";
140
+				$retour.="url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'".$slash."'+elmUrl:elmUrl;\n";
141 141
 			}
142 142
 		}
143 143
 		return $retour;
@@ -147,41 +147,41 @@  discard block
 block discarded – undo
147 147
 		return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};";
148 148
 	}
149 149
 
150
-	protected function autoActiveLinks($previousURL = "window.location.href") {
151
-		$result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
152
-		$result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
150
+	protected function autoActiveLinks($previousURL="window.location.href") {
151
+		$result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
152
+		$result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
153 153
 		return $result;
154 154
 	}
155 155
 
156
-	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history = null) {
157
-		$retour = "";
158
-		$call = null;
156
+	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history=null) {
157
+		$retour="";
158
+		$call=null;
159 159
 		if (JString::isNotNull($responseElement)) {
160 160
 			if (isset($ajaxTransition)) {
161
-				$call = $this->setAjaxDataCall($ajaxTransition);
161
+				$call=$this->setAjaxDataCall($ajaxTransition);
162 162
 			} elseif (isset($this->ajaxTransition)) {
163
-				$call = $this->ajaxTransition;
163
+				$call=$this->ajaxTransition;
164 164
 			}
165 165
 			if (\is_callable($call))
166
-				$retour = "\t" . $call($responseElement, $jqueryDone) . ";\n";
166
+				$retour="\t".$call($responseElement, $jqueryDone).";\n";
167 167
 			else
168
-				$retour = "\t{$responseElement}.{$jqueryDone}( data );\n";
168
+				$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
169 169
 		}
170 170
 		if (isset($history)) {
171 171
 			if ($this->params["autoActiveLinks"]) {
172
-				$retour .= $this->autoActiveLinks("url");
172
+				$retour.=$this->autoActiveLinks("url");
173 173
 			}
174
-			$retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);";
174
+			$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
175 175
 		}
176
-		$retour .= "\t" . $jsCallback . "\n";
176
+		$retour.="\t".$jsCallback."\n";
177 177
 		return $retour;
178 178
 	}
179 179
 
180 180
 	protected function removeLoader($hasLoader) {
181
-		if ($hasLoader === 'internal') {
181
+		if ($hasLoader==='internal') {
182 182
 			return "\n$(self).removeClass('loading');";
183 183
 		}
184
-		if ($hasLoader === 'internal-x') {
184
+		if ($hasLoader==='internal-x') {
185 185
 			return "\n$(self).children('.ajax-loader').remove();";
186 186
 		}
187 187
 		return "\n$(self).find('.loading').removeClass('loading');";
@@ -189,71 +189,71 @@  discard block
 block discarded – undo
189 189
 
190 190
 	protected function _getResponseElement($responseElement) {
191 191
 		if (JString::isNotNull($responseElement)) {
192
-			$responseElement = Javascript::prep_jquery_selector($responseElement);
192
+			$responseElement=Javascript::prep_jquery_selector($responseElement);
193 193
 		}
194 194
 		return $responseElement;
195 195
 	}
196 196
 
197 197
 	protected function _getFormElement($formElement) {
198 198
 		if (JString::isNotNull($formElement)) {
199
-			$formElement = Javascript::prep_value($formElement);
199
+			$formElement=Javascript::prep_value($formElement);
200 200
 		}
201 201
 		return $formElement;
202 202
 	}
203 203
 
204 204
 	protected function _correctAjaxUrl($url) {
205
-		if ($url !== "/" && JString::endsWith($url, "/") === true)
206
-			$url = substr($url, 0, strlen($url) - 1);
207
-		if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) {
208
-			$url = $this->getUrl($url);
205
+		if ($url!=="/" && JString::endsWith($url, "/")===true)
206
+			$url=substr($url, 0, strlen($url)-1);
207
+		if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) {
208
+			$url=$this->getUrl($url);
209 209
 		}
210 210
 		return $url;
211 211
 	}
212 212
 
213
-	public static function _correctParams($params, $ajaxParameters = []) {
213
+	public static function _correctParams($params, $ajaxParameters=[]) {
214 214
 		if (JString::isNull($params)) {
215 215
 			return "";
216 216
 		}
217 217
 		if (\preg_match("@^\{.*?\}$@", $params)) {
218
-			if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) {
219
-				return '$.param(' . $params . ')';
218
+			if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) {
219
+				return '$.param('.$params.')';
220 220
 			} else {
221
-				return 'JSON.stringify(' . $params . ')';
221
+				return 'JSON.stringify('.$params.')';
222 222
 			}
223 223
 		}
224 224
 		return $params;
225 225
 	}
226 226
 
227 227
 	public static function _implodeParams($parameters) {
228
-		$allParameters = [];
228
+		$allParameters=[];
229 229
 		foreach ($parameters as $params) {
230 230
 			if (isset($params))
231
-				$allParameters[] = self::_correctParams($params);
231
+				$allParameters[]=self::_correctParams($params);
232 232
 		}
233 233
 		return \implode("+'&'+", $allParameters);
234 234
 	}
235 235
 
236
-	protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) {
237
-		if (! isset($ajaxLoader)) {
238
-			$ajaxLoader = $this->ajaxLoader;
236
+	protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) {
237
+		if (!isset($ajaxLoader)) {
238
+			$ajaxLoader=$this->ajaxLoader;
239 239
 		}
240
-		$loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>';
241
-		$retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n";
240
+		$loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>';
241
+		$retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n";
242 242
 	}
243 243
 
244
-	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) {
245
-		if (! isset($ajaxLoader)) {
246
-			$ajaxLoader = $this->ajaxLoader;
244
+	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) {
245
+		if (!isset($ajaxLoader)) {
246
+			$ajaxLoader=$this->ajaxLoader;
247 247
 		}
248
-		$loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>';
249
-		$retour .= "{$responseElement}.empty();\n";
250
-		$retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
248
+		$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
249
+		$retour.="{$responseElement}.empty();\n";
250
+		$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
251 251
 	}
252 252
 
253 253
 	protected function setAjaxDataCall($params) {
254
-		$result = null;
255
-		if (! \is_callable($params)) {
256
-			$result = function ($responseElement, $jqueryDone = 'html') use ($params) {
254
+		$result=null;
255
+		if (!\is_callable($params)) {
256
+			$result=function($responseElement, $jqueryDone='html') use ($params) {
257 257
 				return AjaxTransition::{$params}($responseElement, $jqueryDone);
258 258
 			};
259 259
 		}
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 
263 263
 	protected function setDefaultParameters(&$parameters, $default) {
264 264
 		foreach ($default as $k => $v) {
265
-			if (! isset($parameters[$k]))
266
-				$parameters[$k] = $v;
265
+			if (!isset($parameters[$k]))
266
+				$parameters[$k]=$v;
267 267
 		}
268 268
 	}
269 269
 
270 270
 	public function setAjaxLoader($loader) {
271
-		$this->ajaxLoader = $loader;
271
+		$this->ajaxLoader=$loader;
272 272
 	}
273 273
 
274 274
 	/**
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 * @param string $responseElement
280 280
 	 *        	selector of the HTML element displaying the answer
281 281
 	 */
282
-	private function _get($url, $responseElement = '', $parameters = []) {
282
+	private function _get($url, $responseElement='', $parameters=[]) {
283 283
 		return $this->_ajax('get', $url, $responseElement, $parameters);
284 284
 	}
285 285
 
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
 	 * @param array $parameters
294 294
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
295 295
 	 */
296
-	public function get($url, $responseElement = '', $parameters = []) {
297
-		$parameters['immediatly'] = true;
296
+	public function get($url, $responseElement='', $parameters=[]) {
297
+		$parameters['immediatly']=true;
298 298
 		return $this->_get($url, $responseElement, $parameters);
299 299
 	}
300 300
 
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
 	 * @param array $parameters
311 311
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
312 312
 	 */
313
-	public function ajax($method, $url, $responseElement = '', $parameters = []) {
314
-		$parameters['immediatly'] = true;
313
+	public function ajax($method, $url, $responseElement='', $parameters=[]) {
314
+		$parameters['immediatly']=true;
315 315
 		return $this->_ajax($method, $url, $responseElement, $parameters);
316 316
 	}
317 317
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 *        	$immediatly
334 334
 	 * @return string
335 335
 	 */
336
-	public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) {
336
+	public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) {
337 337
 		return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly);
338 338
 	}
339 339
 
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
 	 * @param array $parameters
350 350
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
351 351
 	 */
352
-	public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) {
353
-		$parameters['immediatly'] = false;
352
+	public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) {
353
+		$parameters['immediatly']=false;
354 354
 		return $this->_ajax($method, $url, $responseElement, $parameters);
355 355
 	}
356 356
 
@@ -364,15 +364,15 @@  discard block
 block discarded – undo
364 364
 	 * @param array $parameters
365 365
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
366 366
 	 */
367
-	private function _json($url, $method = "get", $parameters = []) {
368
-		$parameters = \array_merge($parameters, [
367
+	private function _json($url, $method="get", $parameters=[]) {
368
+		$parameters=\array_merge($parameters, [
369 369
 			"hasLoader" => false
370 370
 		]);
371
-		$jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
372
-		$context = isset($parameters['context']) ? $parameters['context'] : "document";
373
-		$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";
374
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
375
-		$parameters["jsCallback"] = $retour;
371
+		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
372
+		$context=isset($parameters['context']) ? $parameters['context'] : "document";
373
+		$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";
374
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
375
+		$parameters["jsCallback"]=$retour;
376 376
 		return $this->_ajax($method, $url, null, $parameters);
377 377
 	}
378 378
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 	 * @param array $parameters
387 387
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
388 388
 	 */
389
-	public function json($url, $method = "get", $parameters = []) {
389
+	public function json($url, $method="get", $parameters=[]) {
390 390
 		return $this->_json($url, $method, $parameters);
391 391
 	}
392 392
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	 * @param array $parameters
403 403
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false)
404 404
 	 */
405
-	public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) {
405
+	public function jsonOn($event, $element, $url, $method='get', $parameters=array()) {
406 406
 		$this->setDefaultParameters($parameters, [
407 407
 			'preventDefault' => true,
408 408
 			'stopPropagation' => true,
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	 * @param array $parameters
423 423
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
424 424
 	 */
425
-	public function jsonDeferred($url, $method = 'get', $parameters = []) {
426
-		$parameters['immediatly'] = false;
425
+	public function jsonDeferred($url, $method='get', $parameters=[]) {
426
+		$parameters['immediatly']=false;
427 427
 		return $this->_json($url, $method, $parameters);
428 428
 	}
429 429
 
@@ -438,29 +438,29 @@  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,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
440 440
 	 */
441
-	private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) {
442
-		$parameters = \array_merge($parameters, [
441
+	private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) {
442
+		$parameters=\array_merge($parameters, [
443 443
 			"hasLoader" => false
444 444
 		]);
445
-		$rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json";
446
-		$jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
447
-		$context = isset($parameters['context']) ? $parameters['context'] : null;
448
-		if ($context === null) {
449
-			$parent = "$('" . $maskSelector . "').parent()";
450
-			$newElm = "$('#'+newId)";
445
+		$rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json";
446
+		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
447
+		$context=isset($parameters['context']) ? $parameters['context'] : null;
448
+		if ($context===null) {
449
+			$parent="$('".$maskSelector."').parent()";
450
+			$newElm="$('#'+newId)";
451 451
 		} else {
452
-			$parent = $context;
453
-			$newElm = $context . ".find('#'+newId)";
452
+			$parent=$context;
453
+			$newElm=$context.".find('#'+newId)";
454 454
 		}
455
-		$appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n";
456
-		$retour = $parent . ".find('.{$rowClass}').remove();";
457
-		$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();
455
+		$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
456
+		$retour=$parent.".find('.{$rowClass}').remove();";
457
+		$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();
458 458
 		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";
459
-		$retour .= $appendTo;
460
-		$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";
461
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
462
-		$retour .= "\t" . $jsCallback;
463
-		$parameters["jsCallback"] = $retour;
459
+		$retour.=$appendTo;
460
+		$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";
461
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
462
+		$retour.="\t".$jsCallback;
463
+		$parameters["jsCallback"]=$retour;
464 464
 		return $this->_ajax($method, $url, null, $parameters);
465 465
 	}
466 466
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 	 * @param array $parameters
476 476
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
477 477
 	 */
478
-	public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) {
478
+	public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) {
479 479
 		return $this->_jsonArray($maskSelector, $url, $method, $parameters);
480 480
 	}
481 481
 
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 	 * @param array $parameters
491 491
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null)
492 492
 	 */
493
-	public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) {
494
-		$parameters['immediatly'] = false;
493
+	public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) {
494
+		$parameters['immediatly']=false;
495 495
 		return $this->jsonArray($maskSelector, $url, $method, $parameters);
496 496
 	}
497 497
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 	 * @param array $parameters
508 508
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false)
509 509
 	 */
510
-	public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) {
510
+	public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) {
511 511
 		$this->setDefaultParameters($parameters, [
512 512
 			'preventDefault' => true,
513 513
 			'stopPropagation' => true,
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
 	 * @param array $parameters
529 529
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
530 530
 	 */
531
-	public function getDeferred($url, $responseElement = "", $parameters = []) {
532
-		$parameters['immediatly'] = false;
531
+	public function getDeferred($url, $responseElement="", $parameters=[]) {
532
+		$parameters['immediatly']=false;
533 533
 		return $this->_get($url, $responseElement, $parameters);
534 534
 	}
535 535
 
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param array $parameters
549 549
 	 *        	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)
550 550
 	 */
551
-	public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) {
552
-		$parameters['method'] = 'get';
551
+	public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
552
+		$parameters['method']='get';
553 553
 		return $this->ajaxOn($event, $element, $url, $responseElement, $parameters);
554 554
 	}
555 555
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 	 * @param array $parameters
569 569
 	 *        	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)
570 570
 	 */
571
-	public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) {
571
+	public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) {
572 572
 		$this->setDefaultParameters($parameters, [
573 573
 			'preventDefault' => true,
574 574
 			'stopPropagation' => true,
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 	 * @param array $parameters
593 593
 	 *        	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)
594 594
 	 */
595
-	public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) {
595
+	public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) {
596 596
 		return $this->ajaxOn('click', $element, $url, $responseElement, $parameters);
597 597
 	}
598 598
 
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 	 * @param array $parameters
610 610
 	 *        	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)
611 611
 	 */
612
-	public function getOnClick($element, $url, $responseElement = '', $parameters = array()) {
612
+	public function getOnClick($element, $url, $responseElement='', $parameters=array()) {
613 613
 		return $this->getOn('click', $element, $url, $responseElement, $parameters);
614 614
 	}
615 615
 
@@ -624,18 +624,18 @@  discard block
 block discarded – undo
624 624
 	 *        	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,"listenerOn"=>false)
625 625
 	 * @return $this
626 626
 	 */
627
-	public function getHref($element, $responseElement = "", $parameters = array()) {
628
-		$parameters['attr'] = 'href';
627
+	public function getHref($element, $responseElement="", $parameters=array()) {
628
+		$parameters['attr']='href';
629 629
 		if (JString::isNull($responseElement)) {
630
-			$responseElement = '%$(self).attr("data-target")%';
630
+			$responseElement='%$(self).attr("data-target")%';
631 631
 		} else {
632
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
632
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
633 633
 		}
634
-		if (! isset($parameters['historize'])) {
635
-			$parameters['historize'] = true;
634
+		if (!isset($parameters['historize'])) {
635
+			$parameters['historize']=true;
636 636
 		}
637
-		if (! isset($parameters['jsCallback'])) {
638
-			$parameters['jsCallback'] = 'var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);';
637
+		if (!isset($parameters['jsCallback'])) {
638
+			$parameters['jsCallback']='var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);';
639 639
 		}
640 640
 		return $this->getOnClick($element, "", $responseElement, $parameters);
641 641
 	}
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 	 *        	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,"listenerOn"=>false)
652 652
 	 * @return $this
653 653
 	 */
654
-	public function postHref($element, $responseElement = "", $parameters = array()) {
655
-		$parameters['attr'] = 'href';
654
+	public function postHref($element, $responseElement="", $parameters=array()) {
655
+		$parameters['attr']='href';
656 656
 		if (JString::isNull($responseElement)) {
657
-			$responseElement = '%$(this).attr("data-target")%';
657
+			$responseElement='%$(this).attr("data-target")%';
658 658
 		} else {
659
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
659
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
660 660
 		}
661
-		if (! isset($parameters['historize'])) {
662
-			$parameters['historize'] = true;
661
+		if (!isset($parameters['historize'])) {
662
+			$parameters['historize']=true;
663 663
 		}
664 664
 		return $this->postOnClick($element, '', '{}', $responseElement, $parameters);
665 665
 	}
@@ -675,29 +675,29 @@  discard block
 block discarded – undo
675 675
 	 *        	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,"listenerOn"=>false)
676 676
 	 * @return $this
677 677
 	 */
678
-	public function postFormAction($element, $responseElement = "", $parameters = array()) {
679
-		$parameters['attr'] = 'action';
678
+	public function postFormAction($element, $responseElement="", $parameters=array()) {
679
+		$parameters['attr']='action';
680 680
 		if (JString::isNull($responseElement)) {
681
-			$responseElement = '%$(self).attr("data-target")%';
681
+			$responseElement='%$(self).attr("data-target")%';
682 682
 		} else {
683
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
683
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
684 684
 		}
685
-		$formId = '%$(this).attr("id")%';
686
-		if (! isset($parameters['historize'])) {
687
-			$parameters['historize'] = true;
685
+		$formId='%$(this).attr("id")%';
686
+		if (!isset($parameters['historize'])) {
687
+			$parameters['historize']=true;
688 688
 		}
689
-		$parameters['preventDefault'] = true;
690
-		if (! isset($parameters['hasLoader'])) {
691
-			$parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")';
689
+		$parameters['preventDefault']=true;
690
+		if (!isset($parameters['hasLoader'])) {
691
+			$parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")';
692 692
 		}
693
-		if (! isset($parameters['jsCallback'])) {
694
-			$parameters['jsCallback'] = 'var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);';
693
+		if (!isset($parameters['jsCallback'])) {
694
+			$parameters['jsCallback']='var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);';
695 695
 		}
696 696
 		return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters);
697 697
 	}
698 698
 
699
-	private function _post($url, $params = '{}', $responseElement = '', $parameters = []) {
700
-		$parameters['params'] = $params;
699
+	private function _post($url, $params='{}', $responseElement='', $parameters=[]) {
700
+		$parameters['params']=$params;
701 701
 		return $this->_ajax('POST', $url, $responseElement, $parameters);
702 702
 	}
703 703
 
@@ -713,8 +713,8 @@  discard block
 block discarded – undo
713 713
 	 * @param array $parameters
714 714
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
715 715
 	 */
716
-	public function post($url, $params = "{}", $responseElement = "", $parameters = []) {
717
-		$parameters['immediatly'] = true;
716
+	public function post($url, $params="{}", $responseElement="", $parameters=[]) {
717
+		$parameters['immediatly']=true;
718 718
 		return $this->_post($url, $params, $responseElement, $parameters);
719 719
 	}
720 720
 
@@ -731,8 +731,8 @@  discard block
 block discarded – undo
731 731
 	 * @param array $parameters
732 732
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
733 733
 	 */
734
-	public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) {
735
-		$parameters['immediatly'] = false;
734
+	public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) {
735
+		$parameters['immediatly']=false;
736 736
 		return $this->_post($url, $params, $responseElement, $parameters);
737 737
 	}
738 738
 
@@ -751,9 +751,9 @@  discard block
 block discarded – undo
751 751
 	 * @param array $parameters
752 752
 	 *        	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)
753 753
 	 */
754
-	public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) {
755
-		$parameters['method'] = 'post';
756
-		$parameters['params'] = $params;
754
+	public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
755
+		$parameters['method']='post';
756
+		$parameters['params']=$params;
757 757
 		return $this->ajaxOn($event, $element, $url, $responseElement, $parameters);
758 758
 	}
759 759
 
@@ -771,75 +771,75 @@  discard block
 block discarded – undo
771 771
 	 * @param array $parameters
772 772
 	 *        	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)
773 773
 	 */
774
-	public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) {
774
+	public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) {
775 775
 		return $this->postOn('click', $element, $url, $params, $responseElement, $parameters);
776 776
 	}
777 777
 
778
-	private function _postForm($url, $form, $responseElement, $parameters = []) {
778
+	private function _postForm($url, $form, $responseElement, $parameters=[]) {
779 779
 		if (isset($this->params['ajax'])) {
780 780
 			extract($this->params['ajax']);
781 781
 		}
782
-		$params = '{}';
783
-		$validation = false;
782
+		$params='{}';
783
+		$validation=false;
784 784
 		\extract($parameters);
785
-		$async = ($async) ? 'true' : 'false';
786
-		$jsCallback = isset($jsCallback) ? $jsCallback : "";
787
-		$retour = $this->_getAjaxUrl($url, $attr);
788
-		$form = $this->_getFormElement($form);
789
-		$retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');";
790
-		if (! isset($contentType) || $contentType != 'false') {
791
-			$retour .= "\nvar params=$('#'+" . $form . ").serialize();\n";
785
+		$async=($async) ? 'true' : 'false';
786
+		$jsCallback=isset($jsCallback) ? $jsCallback : "";
787
+		$retour=$this->_getAjaxUrl($url, $attr);
788
+		$form=$this->_getFormElement($form);
789
+		$retour.="\n$('#'+".$form.").trigger('ajaxSubmit');";
790
+		if (!isset($contentType) || $contentType!='false') {
791
+			$retour.="\nvar params=$('#'+".$form.").serialize();\n";
792 792
 			if (isset($params)) {
793
-				$retour .= "params+='&'+" . self::_correctParams($params) . ";\n";
793
+				$retour.="params+='&'+".self::_correctParams($params).";\n";
794 794
 			}
795 795
 		} else {
796
-			$retour .= "\nvar params=new FormData($('#'+" . $form . ")[0]);\n";
796
+			$retour.="\nvar params=new FormData($('#'+".$form.")[0]);\n";
797 797
 		}
798
-		$responseElement = $this->_getResponseElement($responseElement);
799
-		$retour .= "var self=this;\n";
800
-		$before = isset($before) ? $before : "";
801
-		$retour .= $before;
802
-		if ($hasLoader === true) {
798
+		$responseElement=$this->_getResponseElement($responseElement);
799
+		$retour.="var self=this;\n";
800
+		$before=isset($before) ? $before : "";
801
+		$retour.=$before;
802
+		if ($hasLoader===true) {
803 803
 			$this->addLoading($retour, $responseElement, $ajaxLoader);
804
-		} elseif ($hasLoader === 'response') {
804
+		} elseif ($hasLoader==='response') {
805 805
 			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
806
-		} elseif ($hasLoader === 'internal-x') {
806
+		} elseif ($hasLoader==='internal-x') {
807 807
 			$this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader);
808
-		} elseif ($hasLoader === 'internal') {
809
-			$retour .= "\n$(this).addClass('loading');";
808
+		} elseif ($hasLoader==='internal') {
809
+			$retour.="\n$(this).addClass('loading');";
810 810
 		} elseif (\is_string($hasLoader)) {
811
-			$retour .= "\n$hasLoader.addClass('loading');";
811
+			$retour.="\n$hasLoader.addClass('loading');";
812 812
 		}
813
-		$ajaxParameters = [
813
+		$ajaxParameters=[
814 814
 			"url" => "url",
815 815
 			"method" => "'POST'",
816 816
 			"data" => "params",
817 817
 			"async" => $async
818 818
 		];
819 819
 		if (isset($headers)) {
820
-			$ajaxParameters["headers"] = $headers;
820
+			$ajaxParameters["headers"]=$headers;
821 821
 		}
822 822
 		if (isset($partial)) {
823
-			$ajaxParameters["xhr"] = "xhrProvider";
824
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
823
+			$ajaxParameters["xhr"]="xhrProvider";
824
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
825 825
 		}
826 826
 		$this->createAjaxParameters($ajaxParameters, $parameters);
827
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n";
828
-		$retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) . "})";
827
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n";
828
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."})";
829 829
 		if (isset($error)) {
830
-			$retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})';
830
+			$retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})';
831 831
 		}
832
-		$retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})';
833
-		$retour .= ";\n";
832
+		$retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})';
833
+		$retour.=";\n";
834 834
 		if ($validation) {
835
-			$retour = "$('#'+" . $form . ").validate({submitHandler: function(form) {
836
-			" . $retour . "
835
+			$retour="$('#'+".$form.").validate({submitHandler: function(form) {
836
+			" . $retour."
837 837
 			}});\n";
838
-			$retour .= "$('#'+" . $form . ").submit();\n";
838
+			$retour.="$('#'+".$form.").submit();\n";
839 839
 		}
840
-		$retour = $this->_addJsCondition($jsCondition, $retour);
840
+		$retour=$this->_addJsCondition($jsCondition, $retour);
841 841
 		if ($immediatly)
842
-			$this->jquery_code_for_compile[] = $retour;
842
+			$this->jquery_code_for_compile[]=$retour;
843 843
 		return $retour;
844 844
 	}
845 845
 
@@ -855,8 +855,8 @@  discard block
 block discarded – undo
855 855
 	 * @param array $parameters
856 856
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
857 857
 	 */
858
-	public function postForm($url, $form, $responseElement, $parameters = []) {
859
-		$parameters['immediatly'] = true;
858
+	public function postForm($url, $form, $responseElement, $parameters=[]) {
859
+		$parameters['immediatly']=true;
860 860
 		return $this->_postForm($url, $form, $responseElement, $parameters);
861 861
 	}
862 862
 
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
 	 * @param array $parameters
874 874
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
875 875
 	 */
876
-	public function postFormDeferred($url, $form, $responseElement, $parameters = []) {
877
-		$parameters['immediatly'] = false;
876
+	public function postFormDeferred($url, $form, $responseElement, $parameters=[]) {
877
+		$parameters['immediatly']=false;
878 878
 		return $this->_postForm($url, $form, $responseElement, $parameters);
879 879
 	}
880 880
 
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 	 * @param array $parameters
892 892
 	 *        	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)
893 893
 	 */
894
-	public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) {
894
+	public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
895 895
 		$this->setDefaultParameters($parameters, [
896 896
 			'preventDefault' => true,
897 897
 			'stopPropagation' => true,
@@ -913,11 +913,11 @@  discard block
 block discarded – undo
913 913
 	 * @param array $parameters
914 914
 	 *        	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)
915 915
 	 */
916
-	public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) {
916
+	public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) {
917 917
 		return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters);
918 918
 	}
919 919
 
920
-	public function addCsrf($name = 'csrf-token') {
920
+	public function addCsrf($name='csrf-token') {
921 921
 		return "
922 922
 		$.ajaxSetup({
923 923
 			beforeSend: function(xhr, settings) {
Please login to merge, or discard this patch.