Passed
Push — master ( f022dc...ec835f )
by Jean-Christophe
02:32
created
Ajax/common/traits/JsUtilsAjaxTrait.php 1 patch
Spacing   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -14,210 +14,210 @@  discard block
 block discarded – undo
14 14
  */
15 15
 trait JsUtilsAjaxTrait {
16 16
 	protected $ajaxTransition;
17
-	protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>";
17
+	protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>";
18 18
 	abstract public function getUrl($url);
19
-	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false);
20
-	abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true);
21
-	protected function _ajax($method, $url, $responseElement = "", $parameters = [ ]) {
22
-		if (isset ( $this->params ["ajax"] )) {
23
-			extract ( $this->params ["ajax"] );
24
-		}
25
-		extract ( $parameters );
26
-
27
-		$jsCallback = isset ( $jsCallback ) ? $jsCallback : "";
28
-		$retour = $this->_getAjaxUrl ( $url, $attr );
29
-		$originalSelector = $responseElement;
30
-		$responseElement = $this->_getResponseElement ( $responseElement );
31
-		$retour .= "var self=this;\n";
32
-		$before = isset ( $before ) ? $before : "";
33
-		$retour .= $before;
34
-		if ($hasLoader === true && JString::isNotNull ( $responseElement )) {
35
-			$this->addLoading ( $retour, $responseElement, $ajaxLoader );
36
-		} elseif ($hasLoader === 'response') {
37
-			$this->addResponseLoading ( $retour, $responseElement, $ajaxLoader );
38
-		} elseif ($hasLoader === 'internal') {
39
-			$retour .= "\n$(this).addClass('loading');";
40
-		}
41
-		$ajaxParameters = [ 
19
+	abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false);
20
+	abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true);
21
+	protected function _ajax($method, $url, $responseElement="", $parameters=[]) {
22
+		if (isset ($this->params ["ajax"])) {
23
+			extract($this->params ["ajax"]);
24
+		}
25
+		extract($parameters);
26
+
27
+		$jsCallback=isset ($jsCallback) ? $jsCallback : "";
28
+		$retour=$this->_getAjaxUrl($url, $attr);
29
+		$originalSelector=$responseElement;
30
+		$responseElement=$this->_getResponseElement($responseElement);
31
+		$retour.="var self=this;\n";
32
+		$before=isset ($before) ? $before : "";
33
+		$retour.=$before;
34
+		if ($hasLoader===true && JString::isNotNull($responseElement)) {
35
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
36
+		} elseif ($hasLoader==='response') {
37
+			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
38
+		} elseif ($hasLoader==='internal') {
39
+			$retour.="\n$(this).addClass('loading');";
40
+		}
41
+		$ajaxParameters=[ 
42 42
 				"url" => "url",
43
-				"method" => "'" . \strtoupper ( $method ) . "'"
43
+				"method" => "'".\strtoupper($method)."'"
44 44
 		];
45 45
 
46
-		$ajaxParameters ["async"] = ($async ? "true" : "false");
46
+		$ajaxParameters ["async"]=($async ? "true" : "false");
47 47
 
48
-		if (isset ( $params )) {
49
-			$ajaxParameters ["data"] = self::_correctParams ( $params, $parameters );
48
+		if (isset ($params)) {
49
+			$ajaxParameters ["data"]=self::_correctParams($params, $parameters);
50 50
 		}
51
-		if (isset ( $headers )) {
52
-			$ajaxParameters ["headers"] = $headers;
51
+		if (isset ($headers)) {
52
+			$ajaxParameters ["headers"]=$headers;
53 53
 		}
54
-		if (isset ( $partial )) {
55
-			$ajaxParameters ["xhr"] = "xhrProvider";
56
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
54
+		if (isset ($partial)) {
55
+			$ajaxParameters ["xhr"]="xhrProvider";
56
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
57 57
 		}
58
-		$this->createAjaxParameters ( $ajaxParameters, $parameters );
59
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) {\n";
60
-		$retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n";
58
+		$this->createAjaxParameters($ajaxParameters, $parameters);
59
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n";
60
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n";
61 61
 
62
-		$retour = $this->_addJsCondition ( $jsCondition, $retour );
62
+		$retour=$this->_addJsCondition($jsCondition, $retour);
63 63
 		if ($immediatly)
64
-			$this->jquery_code_for_compile [] = $retour;
64
+			$this->jquery_code_for_compile []=$retour;
65 65
 		return $retour;
66 66
 	}
67 67
 	protected function createAjaxParameters(&$original, $parameters) {
68
-		$validParameters = [ 
68
+		$validParameters=[ 
69 69
 				"contentType" => "%value%",
70 70
 				"dataType" => "'%value%'",
71 71
 				"beforeSend" => "function(jqXHR,settings){%value%}",
72 72
 				"complete" => "function(jqXHR){%value%}",
73 73
 				"processData" => "%value%"
74 74
 		];
75
-		foreach ( $validParameters as $param => $mask ) {
76
-			if (isset ( $parameters [$param] )) {
77
-				$original [$param] = \str_replace ( "%value%", $parameters [$param], $mask );
75
+		foreach ($validParameters as $param => $mask) {
76
+			if (isset ($parameters [$param])) {
77
+				$original [$param]=\str_replace("%value%", $parameters [$param], $mask);
78 78
 			}
79 79
 		}
80 80
 	}
81 81
 	protected function implodeAjaxParameters($ajaxParameters) {
82
-		$s = '';
83
-		foreach ( $ajaxParameters as $k => $v ) {
84
-			if ($s !== '') {
85
-				$s .= ',';
82
+		$s='';
83
+		foreach ($ajaxParameters as $k => $v) {
84
+			if ($s!=='') {
85
+				$s.=',';
86 86
 			}
87
-			if (is_array ( $v )) {
88
-				$s .= "'{$k}':{" . self::implodeAjaxParameters ( $v ) . "}";
87
+			if (is_array($v)) {
88
+				$s.="'{$k}':{".self::implodeAjaxParameters($v)."}";
89 89
 			} else {
90
-				$s .= "'{$k}':{$v}";
90
+				$s.="'{$k}':{$v}";
91 91
 			}
92 92
 		}
93 93
 		return $s;
94 94
 	}
95 95
 	protected function _addJsCondition($jsCondition, $jsSource) {
96
-		if (isset ( $jsCondition )) {
97
-			return "if(" . $jsCondition . "){\n" . $jsSource . "\n}";
96
+		if (isset ($jsCondition)) {
97
+			return "if(".$jsCondition."){\n".$jsSource."\n}";
98 98
 		}
99 99
 		return $jsSource;
100 100
 	}
101 101
 	protected function _getAjaxUrl($url, $attr) {
102
-		$url = $this->_correctAjaxUrl ( $url );
103
-		$retour = "url='" . $url . "';";
104
-		$slash = "/";
105
-		if (JString::endswith ( $url, "/" ) === true) {
106
-			$slash = "";
107
-		}
108
-		if (JString::isNotNull ( $attr )) {
109
-			if ($attr === "value") {
110
-				$retour .= "url=url+'" . $slash . "'+$(this).val();\n";
111
-			} elseif ($attr === "html") {
112
-				$retour .= "url=url+'" . $slash . "'+$(this).html();\n";
113
-			} elseif (\substr ( $attr, 0, 3 ) === "js:") {
114
-				$retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n";
115
-			} elseif ($attr !== null && $attr !== "")
116
-				$retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n";
102
+		$url=$this->_correctAjaxUrl($url);
103
+		$retour="url='".$url."';";
104
+		$slash="/";
105
+		if (JString::endswith($url, "/")===true) {
106
+			$slash="";
107
+		}
108
+		if (JString::isNotNull($attr)) {
109
+			if ($attr==="value") {
110
+				$retour.="url=url+'".$slash."'+$(this).val();\n";
111
+			} elseif ($attr==="html") {
112
+				$retour.="url=url+'".$slash."'+$(this).html();\n";
113
+			} elseif (\substr($attr, 0, 3)==="js:") {
114
+				$retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n";
115
+			} elseif ($attr!==null && $attr!=="")
116
+				$retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n";
117 117
 		}
118 118
 		return $retour;
119 119
 	}
120 120
 	protected function onPopstate() {
121 121
 		return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};";
122 122
 	}
123
-	protected function autoActiveLinks($previousURL = "window.location.href") {
124
-		$result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
125
-		$result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
123
+	protected function autoActiveLinks($previousURL="window.location.href") {
124
+		$result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
125
+		$result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;";
126 126
 		return $result;
127 127
 	}
128
-	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) {
129
-		$retour = "";
130
-		$call = null;
131
-		if (JString::isNotNull ( $responseElement )) {
132
-			if (isset ( $ajaxTransition )) {
133
-				$call = $this->setAjaxDataCall ( $ajaxTransition );
134
-			} elseif (isset ( $this->ajaxTransition )) {
135
-				$call = $this->ajaxTransition;
128
+	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) {
129
+		$retour="";
130
+		$call=null;
131
+		if (JString::isNotNull($responseElement)) {
132
+			if (isset ($ajaxTransition)) {
133
+				$call=$this->setAjaxDataCall($ajaxTransition);
134
+			} elseif (isset ($this->ajaxTransition)) {
135
+				$call=$this->ajaxTransition;
136 136
 			}
137
-			if (\is_callable ( $call ))
138
-				$retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n";
137
+			if (\is_callable($call))
138
+				$retour="\t".$call($responseElement, $jqueryDone).";\n";
139 139
 			else
140
-				$retour = "\t{$responseElement}.{$jqueryDone}( data );\n";
140
+				$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
141 141
 		}
142
-		if (isset ( $history )) {
142
+		if (isset ($history)) {
143 143
 			if ($this->params ["autoActiveLinks"]) {
144
-				$retour .= $this->autoActiveLinks ( "url" );
144
+				$retour.=$this->autoActiveLinks("url");
145 145
 			}
146
-			$retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value ( $history ) . ",'jqueryDone':'{$jqueryDone}'},'', url);";
146
+			$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
147 147
 		}
148
-		if ($hasLoader === "internal") {
149
-			$retour .= "\n$(self).removeClass('loading');";
148
+		if ($hasLoader==="internal") {
149
+			$retour.="\n$(self).removeClass('loading');";
150 150
 		}
151
-		$retour .= "\t" . $jsCallback . "\n";
151
+		$retour.="\t".$jsCallback."\n";
152 152
 		return $retour;
153 153
 	}
154 154
 	protected function _getResponseElement($responseElement) {
155
-		if (JString::isNotNull ( $responseElement )) {
156
-			$responseElement = Javascript::prep_jquery_selector ( $responseElement );
155
+		if (JString::isNotNull($responseElement)) {
156
+			$responseElement=Javascript::prep_jquery_selector($responseElement);
157 157
 		}
158 158
 		return $responseElement;
159 159
 	}
160 160
 	protected function _correctAjaxUrl($url) {
161
-		if ($url !== "/" && JString::endsWith ( $url, "/" ) === true)
162
-			$url = substr ( $url, 0, strlen ( $url ) - 1 );
163
-		if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) {
164
-			$url = $this->getUrl ( $url );
161
+		if ($url!=="/" && JString::endsWith($url, "/")===true)
162
+			$url=substr($url, 0, strlen($url)-1);
163
+		if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) {
164
+			$url=$this->getUrl($url);
165 165
 		}
166 166
 		return $url;
167 167
 	}
168
-	public static function _correctParams($params, $ajaxParameters = [ ]) {
169
-		if (JString::isNull ( $params )) {
168
+	public static function _correctParams($params, $ajaxParameters=[]) {
169
+		if (JString::isNull($params)) {
170 170
 			return "";
171 171
 		}
172
-		if (\preg_match ( "@^\{.*?\}$@", $params )) {
173
-			if (! isset ( $ajaxParameters ['contentType'] ) || ! JString::contains ( $ajaxParameters ['contentType'], 'json' )) {
174
-				return '$.param(' . $params . ')';
172
+		if (\preg_match("@^\{.*?\}$@", $params)) {
173
+			if (!isset ($ajaxParameters ['contentType']) || !JString::contains($ajaxParameters ['contentType'], 'json')) {
174
+				return '$.param('.$params.')';
175 175
 			} else {
176
-				return 'JSON.stringify(' . $params . ')';
176
+				return 'JSON.stringify('.$params.')';
177 177
 			}
178 178
 		}
179 179
 		return $params;
180 180
 	}
181 181
 	public static function _implodeParams($parameters) {
182
-		$allParameters = [ ];
183
-		foreach ( $parameters as $params ) {
184
-			if (isset ( $params ))
185
-				$allParameters [] = self::_correctParams ( $params );
182
+		$allParameters=[];
183
+		foreach ($parameters as $params) {
184
+			if (isset ($params))
185
+				$allParameters []=self::_correctParams($params);
186 186
 		}
187
-		return \implode ( "+'&'+", $allParameters );
187
+		return \implode("+'&'+", $allParameters);
188 188
 	}
189
-	protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) {
190
-		if (! isset ( $ajaxLoader )) {
191
-			$ajaxLoader = $this->ajaxLoader;
189
+	protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) {
190
+		if (!isset ($ajaxLoader)) {
191
+			$ajaxLoader=$this->ajaxLoader;
192 192
 		}
193
-		$loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>';
194
-		$retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n";
193
+		$loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>';
194
+		$retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n";
195 195
 	}
196
-	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) {
197
-		if (! isset ( $ajaxLoader )) {
198
-			$ajaxLoader = $this->ajaxLoader;
196
+	protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) {
197
+		if (!isset ($ajaxLoader)) {
198
+			$ajaxLoader=$this->ajaxLoader;
199 199
 		}
200
-		$loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>';
201
-		$retour .= "{$responseElement}.empty();\n";
202
-		$retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
200
+		$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
201
+		$retour.="{$responseElement}.empty();\n";
202
+		$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
203 203
 	}
204 204
 	protected function setAjaxDataCall($params) {
205
-		$result = null;
206
-		if (! \is_callable ( $params )) {
207
-			$result = function ($responseElement, $jqueryDone = "html") use ($params) {
208
-				return AjaxTransition::{$params} ( $responseElement, $jqueryDone );
205
+		$result=null;
206
+		if (!\is_callable($params)) {
207
+			$result=function($responseElement, $jqueryDone="html") use ($params) {
208
+				return AjaxTransition::{$params} ($responseElement, $jqueryDone);
209 209
 			};
210 210
 		}
211 211
 		return $result;
212 212
 	}
213 213
 	protected function setDefaultParameters(&$parameters, $default) {
214
-		foreach ( $default as $k => $v ) {
215
-			if (! isset ( $parameters [$k] ))
216
-				$parameters [$k] = $v;
214
+		foreach ($default as $k => $v) {
215
+			if (!isset ($parameters [$k]))
216
+				$parameters [$k]=$v;
217 217
 		}
218 218
 	}
219 219
 	public function setAjaxLoader($loader) {
220
-		$this->ajaxLoader = $loader;
220
+		$this->ajaxLoader=$loader;
221 221
 	}
222 222
 
223 223
 	/**
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 	 * @param string $responseElement
229 229
 	 *        	selector of the HTML element displaying the answer
230 230
 	 */
231
-	private function _get($url, $responseElement = "", $parameters = [ ]) {
232
-		return $this->_ajax ( "get", $url, $responseElement, $parameters );
231
+	private function _get($url, $responseElement="", $parameters=[]) {
232
+		return $this->_ajax("get", $url, $responseElement, $parameters);
233 233
 	}
234 234
 
235 235
 	/**
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 	 * @param array $parameters
243 243
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
244 244
 	 */
245
-	public function get($url, $responseElement = "", $parameters = [ ]) {
246
-		$parameters ["immediatly"] = true;
247
-		return $this->_get ( $url, $responseElement, $parameters );
245
+	public function get($url, $responseElement="", $parameters=[]) {
246
+		$parameters ["immediatly"]=true;
247
+		return $this->_get($url, $responseElement, $parameters);
248 248
 	}
249 249
 
250 250
 	/**
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 	 * @param array $parameters
260 260
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
261 261
 	 */
262
-	public function ajax($method, $url, $responseElement = "", $parameters = [ ]) {
263
-		$parameters ["immediatly"] = true;
264
-		return $this->_ajax ( $method, $url, $responseElement, $parameters );
262
+	public function ajax($method, $url, $responseElement="", $parameters=[]) {
263
+		$parameters ["immediatly"]=true;
264
+		return $this->_ajax($method, $url, $responseElement, $parameters);
265 265
 	}
266 266
 
267 267
 	/**
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 *        	$immediatly
283 283
 	 * @return string
284 284
 	 */
285
-	public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [ ], $immediatly = true) {
286
-		return $this->interval ( $this->ajaxDeferred ( $method, $url, $responseElement, $parameters ), $interval, $globalName, $immediatly );
285
+	public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) {
286
+		return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly);
287 287
 	}
288 288
 
289 289
 	/**
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 	 * @param array $parameters
299 299
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
300 300
 	 */
301
-	public function ajaxDeferred($method, $url, $responseElement = "", $parameters = [ ]) {
302
-		$parameters ["immediatly"] = false;
303
-		return $this->_ajax ( $method, $url, $responseElement, $parameters );
301
+	public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) {
302
+		$parameters ["immediatly"]=false;
303
+		return $this->_ajax($method, $url, $responseElement, $parameters);
304 304
 	}
305 305
 
306 306
 	/**
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 	 * @param array $parameters
314 314
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
315 315
 	 */
316
-	private function _json($url, $method = "get", $parameters = [ ]) {
317
-		$parameters = \array_merge ( $parameters, [ 
316
+	private function _json($url, $method="get", $parameters=[]) {
317
+		$parameters=\array_merge($parameters, [ 
318 318
 				"hasLoader" => false
319
-		] );
320
-		$jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : "";
321
-		$context = isset ( $parameters ['context'] ) ? $parameters ['context'] : "document";
322
-		$retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n";
323
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
324
-		$parameters ["jsCallback"] = $retour;
325
-		return $this->_ajax ( $method, $url, null, $parameters );
319
+		]);
320
+		$jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : "";
321
+		$context=isset ($parameters ['context']) ? $parameters ['context'] : "document";
322
+		$retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n";
323
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
324
+		$parameters ["jsCallback"]=$retour;
325
+		return $this->_ajax($method, $url, null, $parameters);
326 326
 	}
327 327
 
328 328
 	/**
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 	 * @param array $parameters
336 336
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
337 337
 	 */
338
-	public function json($url, $method = "get", $parameters = [ ]) {
339
-		return $this->_json ( $url, $method, $parameters );
338
+	public function json($url, $method="get", $parameters=[]) {
339
+		return $this->_json($url, $method, $parameters);
340 340
 	}
341 341
 
342 342
 	/**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
 	 * @param array $parameters
352 352
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false)
353 353
 	 */
354
-	public function jsonOn($event, $element, $url, $method = "get", $parameters = array ()) {
355
-		$this->setDefaultParameters ( $parameters, [ 
354
+	public function jsonOn($event, $element, $url, $method="get", $parameters=array()) {
355
+		$this->setDefaultParameters($parameters, [ 
356 356
 				"preventDefault" => true,
357 357
 				"stopPropagation" => true,
358 358
 				"immediatly" => true
359
-		] );
360
-		return $this->_add_event ( $element, $this->jsonDeferred ( $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
359
+		]);
360
+		return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
361 361
 	}
362 362
 
363 363
 	/**
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 * @param array $parameters
371 371
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null)
372 372
 	 */
373
-	public function jsonDeferred($url, $method = "get", $parameters = [ ]) {
374
-		$parameters ["immediatly"] = false;
375
-		return $this->_json ( $url, $method, $parameters );
373
+	public function jsonDeferred($url, $method="get", $parameters=[]) {
374
+		$parameters ["immediatly"]=false;
375
+		return $this->_json($url, $method, $parameters);
376 376
 	}
377 377
 
378 378
 	/**
@@ -386,30 +386,30 @@  discard block
 block discarded – undo
386 386
 	 * @param array $parameters
387 387
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
388 388
 	 */
389
-	private function _jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) {
390
-		$parameters = \array_merge ( $parameters, [ 
389
+	private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
390
+		$parameters=\array_merge($parameters, [ 
391 391
 				"hasLoader" => false
392
-		] );
393
-		$rowClass = isset ( $parameters ['rowClass'] ) ? $parameters ['rowClass'] : "_json";
394
-		$jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : "";
395
-		$context = isset ( $parameters ['context'] ) ? $parameters ['context'] : null;
396
-		if ($context === null) {
397
-			$parent = "$('" . $maskSelector . "').parent()";
398
-			$newElm = "$('#'+newId)";
392
+		]);
393
+		$rowClass=isset ($parameters ['rowClass']) ? $parameters ['rowClass'] : "_json";
394
+		$jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : "";
395
+		$context=isset ($parameters ['context']) ? $parameters ['context'] : null;
396
+		if ($context===null) {
397
+			$parent="$('".$maskSelector."').parent()";
398
+			$newElm="$('#'+newId)";
399 399
 		} else {
400
-			$parent = $context;
401
-			$newElm = $context . ".find('#'+newId)";
400
+			$parent=$context;
401
+			$newElm=$context.".find('#'+newId)";
402 402
 		}
403
-		$appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n";
404
-		$retour = $parent . ".find('.{$rowClass}').remove();";
405
-		$retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n" . "\tvar created=false;var maskElm=$('" . $maskSelector . "').first();maskElm.hide();" . "\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;" . "\tvar newElm=" . $newElm . ";\n" . "\tif(!newElm.length){\n" . "\t\tnewElm=maskElm.clone();
403
+		$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
404
+		$retour=$parent.".find('.{$rowClass}').remove();";
405
+		$retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();
406 406
 		newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n";
407
-		$retour .= $appendTo;
408
-		$retour .= "\t}\n" . "\tfor(var key in value){\n" . "\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n" . "\t\t\tif(html.indexOf('__'+key+'__')>-1){\n" . "\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n" . "\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n" . "\t\t\t}\n" . "\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n" . "\t\t\tvar selElm=$(sel,newElm);\n" . "\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n" . "\t\t}\n" . "}\n" . "\t$(newElm).show(true);" . "\n" . "\t$(newElm).removeClass('hide');" . "});\n";
409
-		$retour .= "\t$(document).trigger('jsonReady',[data]);\n";
410
-		$retour .= "\t" . $jsCallback;
411
-		$parameters ["jsCallback"] = $retour;
412
-		return $this->_ajax ( $method, $url, null, $parameters );
407
+		$retour.=$appendTo;
408
+		$retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n";
409
+		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
410
+		$retour.="\t".$jsCallback;
411
+		$parameters ["jsCallback"]=$retour;
412
+		return $this->_ajax($method, $url, null, $parameters);
413 413
 	}
414 414
 
415 415
 	/**
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
 	 * @param array $parameters
424 424
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null)
425 425
 	 */
426
-	public function jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) {
427
-		return $this->_jsonArray ( $maskSelector, $url, $method, $parameters );
426
+	public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
427
+		return $this->_jsonArray($maskSelector, $url, $method, $parameters);
428 428
 	}
429 429
 
430 430
 	/**
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
 	 * @param array $parameters
439 439
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null)
440 440
 	 */
441
-	public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters = [ ]) {
442
-		$parameters ["immediatly"] = false;
443
-		return $this->jsonArray ( $maskSelector, $url, $method, $parameters );
441
+	public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters=[]) {
442
+		$parameters ["immediatly"]=false;
443
+		return $this->jsonArray($maskSelector, $url, $method, $parameters);
444 444
 	}
445 445
 
446 446
 	/**
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 	 * @param array $parameters
456 456
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false)
457 457
 	 */
458
-	public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array ()) {
459
-		$this->setDefaultParameters ( $parameters, [ 
458
+	public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) {
459
+		$this->setDefaultParameters($parameters, [ 
460 460
 				"preventDefault" => true,
461 461
 				"stopPropagation" => true,
462 462
 				"immediatly" => true
463
-		] );
464
-		return $this->_add_event ( $element, $this->jsonArrayDeferred ( $maskSelector, $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
463
+		]);
464
+		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
465 465
 	}
466 466
 
467 467
 	/**
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
 	 * @param array $parameters
476 476
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
477 477
 	 */
478
-	public function getDeferred($url, $responseElement = "", $parameters = [ ]) {
479
-		$parameters ["immediatly"] = false;
480
-		return $this->_get ( $url, $responseElement, $parameters );
478
+	public function getDeferred($url, $responseElement="", $parameters=[]) {
479
+		$parameters ["immediatly"]=false;
480
+		return $this->_get($url, $responseElement, $parameters);
481 481
 	}
482 482
 
483 483
 	/**
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
 	 * @param array $parameters
496 496
 	 *        	default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
497 497
 	 */
498
-	public function getOn($event, $element, $url, $responseElement = "", $parameters = array ()) {
499
-		$this->setDefaultParameters ( $parameters, [ 
498
+	public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
499
+		$this->setDefaultParameters($parameters, [ 
500 500
 				"preventDefault" => true,
501 501
 				"stopPropagation" => true,
502 502
 				"immediatly" => true
503
-		] );
504
-		return $this->_add_event ( $element, $this->getDeferred ( $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
503
+		]);
504
+		return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
505 505
 	}
506 506
 
507 507
 	/**
@@ -519,15 +519,15 @@  discard block
 block discarded – undo
519 519
 	 * @param array $parameters
520 520
 	 *        	default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false)
521 521
 	 */
522
-	public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array ()) {
523
-		$this->setDefaultParameters ( $parameters, [ 
522
+	public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) {
523
+		$this->setDefaultParameters($parameters, [ 
524 524
 				"preventDefault" => true,
525 525
 				"stopPropagation" => true,
526 526
 				"immediatly" => true,
527 527
 				"method" => "get",
528 528
 				"listenerOn"=>false
529
-		] );
530
-		return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ["method"], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"],$parameters['listenerOn'] );
529
+		]);
530
+		return $this->_add_event($element, $this->ajaxDeferred($parameters ["method"], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']);
531 531
 	}
532 532
 
533 533
 	/**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 	 * @param array $parameters
544 544
 	 *        	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)
545 545
 	 */
546
-	public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array ()) {
547
-		return $this->ajaxOn ( "click", $element, $url, $responseElement, $parameters );
546
+	public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) {
547
+		return $this->ajaxOn("click", $element, $url, $responseElement, $parameters);
548 548
 	}
549 549
 
550 550
 	/**
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 	 * @param array $parameters
561 561
 	 *        	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)
562 562
 	 */
563
-	public function getOnClick($element, $url, $responseElement = "", $parameters = array ()) {
564
-		return $this->getOn ( "click", $element, $url, $responseElement, $parameters );
563
+	public function getOnClick($element, $url, $responseElement="", $parameters=array()) {
564
+		return $this->getOn("click", $element, $url, $responseElement, $parameters);
565 565
 	}
566 566
 
567 567
 	/**
@@ -575,17 +575,17 @@  discard block
 block discarded – undo
575 575
 	 *        	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)
576 576
 	 * @return $this
577 577
 	 */
578
-	public function getHref($element, $responseElement = "", $parameters = array ()) {
579
-		$parameters ["attr"] = "href";
580
-		if (JString::isNull ( $responseElement )) {
581
-			$responseElement = '%$(self).attr("data-target")%';
578
+	public function getHref($element, $responseElement="", $parameters=array()) {
579
+		$parameters ["attr"]="href";
580
+		if (JString::isNull($responseElement)) {
581
+			$responseElement='%$(self).attr("data-target")%';
582 582
 		} else {
583
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
583
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
584 584
 		}
585
-		if (! isset ( $parameters ["historize"] )) {
586
-			$parameters ["historize"] = true;
585
+		if (!isset ($parameters ["historize"])) {
586
+			$parameters ["historize"]=true;
587 587
 		}
588
-		return $this->getOnClick ( $element, "", $responseElement, $parameters );
588
+		return $this->getOnClick($element, "", $responseElement, $parameters);
589 589
 	}
590 590
 
591 591
 	/**
@@ -599,21 +599,21 @@  discard block
 block discarded – undo
599 599
 	 *        	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)
600 600
 	 * @return $this
601 601
 	 */
602
-	public function postHref($element, $responseElement = "", $parameters = array ()) {
603
-		$parameters ["attr"] = "href";
604
-		if (JString::isNull ( $responseElement )) {
605
-			$responseElement = '%$(this).attr("data-target")%';
602
+	public function postHref($element, $responseElement="", $parameters=array()) {
603
+		$parameters ["attr"]="href";
604
+		if (JString::isNull($responseElement)) {
605
+			$responseElement='%$(this).attr("data-target")%';
606 606
 		} else {
607
-			$responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%';
607
+			$responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%';
608 608
 		}
609
-		if (! isset ( $parameters ["historize"] )) {
610
-			$parameters ["historize"] = true;
609
+		if (!isset ($parameters ["historize"])) {
610
+			$parameters ["historize"]=true;
611 611
 		}
612
-		return $this->postOnClick ( $element, "", "{}", $responseElement, $parameters );
612
+		return $this->postOnClick($element, "", "{}", $responseElement, $parameters);
613 613
 	}
614
-	private function _post($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
615
-		$parameters ["params"] = $params;
616
-		return $this->_ajax ( "POST", $url, $responseElement, $parameters );
614
+	private function _post($url, $params="{}", $responseElement="", $parameters=[]) {
615
+		$parameters ["params"]=$params;
616
+		return $this->_ajax("POST", $url, $responseElement, $parameters);
617 617
 	}
618 618
 
619 619
 	/**
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 	 * @param array $parameters
629 629
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
630 630
 	 */
631
-	public function post($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
632
-		$parameters ['immediatly'] = true;
633
-		return $this->_post ( $url, $params, $responseElement, $parameters );
631
+	public function post($url, $params="{}", $responseElement="", $parameters=[]) {
632
+		$parameters ['immediatly']=true;
633
+		return $this->_post($url, $params, $responseElement, $parameters);
634 634
 	}
635 635
 
636 636
 	/**
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @param array $parameters
647 647
 	 *        	default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
648 648
 	 */
649
-	public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = [ ]) {
650
-		$parameters ["immediatly"] = false;
651
-		return $this->_post ( $url, $params, $responseElement, $parameters );
649
+	public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) {
650
+		$parameters ["immediatly"]=false;
651
+		return $this->_post($url, $params, $responseElement, $parameters);
652 652
 	}
653 653
 
654 654
 	/**
@@ -666,13 +666,13 @@  discard block
 block discarded – undo
666 666
 	 * @param array $parameters
667 667
 	 *        	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)
668 668
 	 */
669
-	public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) {
670
-		$this->setDefaultParameters ( $parameters, [ 
669
+	public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
670
+		$this->setDefaultParameters($parameters, [ 
671 671
 				"preventDefault" => true,
672 672
 				"stopPropagation" => true,
673 673
 				"immediatly" => true
674
-		] );
675
-		return $this->_add_event ( $element, $this->postDeferred ( $url, $params, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
674
+		]);
675
+		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
676 676
 	}
677 677
 
678 678
 	/**
@@ -689,65 +689,65 @@  discard block
 block discarded – undo
689 689
 	 * @param array $parameters
690 690
 	 *        	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)
691 691
 	 */
692
-	public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array ()) {
693
-		return $this->postOn ( "click", $element, $url, $params, $responseElement, $parameters );
694
-	}
695
-	private function _postForm($url, $form, $responseElement, $parameters = [ ]) {
696
-		if (isset ( $this->params ["ajax"] )) {
697
-			extract ( $this->params ["ajax"] );
698
-		}
699
-		$params = "{}";
700
-		$validation = false;
701
-		\extract ( $parameters );
702
-		$async = ($async) ? "true" : "false";
703
-		$jsCallback = isset ( $jsCallback ) ? $jsCallback : "";
704
-		$retour = $this->_getAjaxUrl ( $url, $attr );
705
-		$retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');";
706
-		if (! isset ( $contentType ) || $contentType != 'false') {
707
-			$retour .= "\nvar params=$('#" . $form . "').serialize();\n";
708
-			if (isset ( $params )) {
709
-				$retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n";
692
+	public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) {
693
+		return $this->postOn("click", $element, $url, $params, $responseElement, $parameters);
694
+	}
695
+	private function _postForm($url, $form, $responseElement, $parameters=[]) {
696
+		if (isset ($this->params ["ajax"])) {
697
+			extract($this->params ["ajax"]);
698
+		}
699
+		$params="{}";
700
+		$validation=false;
701
+		\extract($parameters);
702
+		$async=($async) ? "true" : "false";
703
+		$jsCallback=isset ($jsCallback) ? $jsCallback : "";
704
+		$retour=$this->_getAjaxUrl($url, $attr);
705
+		$retour.="\n$('#".$form."').trigger('ajaxSubmit');";
706
+		if (!isset ($contentType) || $contentType!='false') {
707
+			$retour.="\nvar params=$('#".$form."').serialize();\n";
708
+			if (isset ($params)) {
709
+				$retour.="params+='&'+".self::_correctParams($params).";\n";
710 710
 			}
711 711
 		} else {
712
-			$retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n";
713
-		}
714
-		$responseElement = $this->_getResponseElement ( $responseElement );
715
-		$retour .= "var self=this;\n";
716
-		$before = isset ( $before ) ? $before : "";
717
-		$retour .= $before;
718
-		if ($hasLoader === true) {
719
-			$this->addLoading ( $retour, $responseElement, $ajaxLoader );
720
-		} elseif ($hasLoader === 'response') {
721
-			$this->addResponseLoading ( $retour, $responseElement, $ajaxLoader );
722
-		} elseif ($hasLoader === 'internal') {
723
-			$retour .= "\n$(this).addClass('loading');";
724
-		}
725
-		$ajaxParameters = [ 
712
+			$retour.="\nvar params=new FormData($('#".$form."')[0]);\n";
713
+		}
714
+		$responseElement=$this->_getResponseElement($responseElement);
715
+		$retour.="var self=this;\n";
716
+		$before=isset ($before) ? $before : "";
717
+		$retour.=$before;
718
+		if ($hasLoader===true) {
719
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
720
+		} elseif ($hasLoader==='response') {
721
+			$this->addResponseLoading($retour, $responseElement, $ajaxLoader);
722
+		} elseif ($hasLoader==='internal') {
723
+			$retour.="\n$(this).addClass('loading');";
724
+		}
725
+		$ajaxParameters=[ 
726 726
 				"url" => "url",
727 727
 				"method" => "'POST'",
728 728
 				"data" => "params",
729 729
 				"async" => $async
730 730
 		];
731
-		if (isset ( $headers )) {
732
-			$ajaxParameters ["headers"] = $headers;
731
+		if (isset ($headers)) {
732
+			$ajaxParameters ["headers"]=$headers;
733 733
 		}
734
-		if (isset ( $partial )) {
735
-			$ajaxParameters ["xhr"] = "xhrProvider";
736
-			$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
734
+		if (isset ($partial)) {
735
+			$ajaxParameters ["xhr"]="xhrProvider";
736
+			$retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };";
737 737
 		}
738
-		$this->createAjaxParameters ( $ajaxParameters, $parameters );
739
-		$retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n";
740
-		$retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n";
738
+		$this->createAjaxParameters($ajaxParameters, $parameters);
739
+		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n";
740
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n";
741 741
 
742 742
 		if ($validation) {
743
-			$retour = "$('#" . $form . "').validate({submitHandler: function(form) {
744
-			" . $retour . "
743
+			$retour="$('#".$form."').validate({submitHandler: function(form) {
744
+			" . $retour."
745 745
 			}});\n";
746
-			$retour .= "$('#" . $form . "').submit();\n";
746
+			$retour.="$('#".$form."').submit();\n";
747 747
 		}
748
-		$retour = $this->_addJsCondition ( $jsCondition, $retour );
748
+		$retour=$this->_addJsCondition($jsCondition, $retour);
749 749
 		if ($immediatly)
750
-			$this->jquery_code_for_compile [] = $retour;
750
+			$this->jquery_code_for_compile []=$retour;
751 751
 		return $retour;
752 752
 	}
753 753
 
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
 	 * @param array $parameters
764 764
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
765 765
 	 */
766
-	public function postForm($url, $form, $responseElement, $parameters = [ ]) {
767
-		$parameters ["immediatly"] = true;
768
-		return $this->_postForm ( $url, $form, $responseElement, $parameters );
766
+	public function postForm($url, $form, $responseElement, $parameters=[]) {
767
+		$parameters ["immediatly"]=true;
768
+		return $this->_postForm($url, $form, $responseElement, $parameters);
769 769
 	}
770 770
 
771 771
 	/**
@@ -781,9 +781,9 @@  discard block
 block discarded – undo
781 781
 	 * @param array $parameters
782 782
 	 *        	default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null)
783 783
 	 */
784
-	public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) {
785
-		$parameters ["immediatly"] = false;
786
-		return $this->_postForm ( $url, $form, $responseElement, $parameters );
784
+	public function postFormDeferred($url, $form, $responseElement, $parameters=[]) {
785
+		$parameters ["immediatly"]=false;
786
+		return $this->_postForm($url, $form, $responseElement, $parameters);
787 787
 	}
788 788
 
789 789
 	/**
@@ -799,13 +799,13 @@  discard block
 block discarded – undo
799 799
 	 * @param array $parameters
800 800
 	 *        	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)
801 801
 	 */
802
-	public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) {
803
-		$this->setDefaultParameters ( $parameters, [ 
802
+	public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
803
+		$this->setDefaultParameters($parameters, [ 
804 804
 				"preventDefault" => true,
805 805
 				"stopPropagation" => true,
806 806
 				"immediatly" => true
807
-		] );
808
-		return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] );
807
+		]);
808
+		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]);
809 809
 	}
810 810
 
811 811
 	/**
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 	 * @param array $parameters
821 821
 	 *        	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)
822 822
 	 */
823
-	public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) {
824
-		return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters );
823
+	public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) {
824
+		return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters);
825 825
 	}
826 826
 }
Please login to merge, or discard this patch.