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