@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @property array $jquery_code_for_compile |
11 | 11 | */ |
12 | 12 | trait JsUtilsEventsTrait { |
13 | - protected $jquery_events = array ( |
|
13 | + protected $jquery_events=array( |
|
14 | 14 | "bind", |
15 | 15 | "blur", |
16 | 16 | "change", |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | "undelegate", |
51 | 51 | "unload" |
52 | 52 | ); |
53 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
53 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Outputs a javascript library blur event |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * code to execute |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function blur($element = 'this', $js = '') { |
|
65 | - return $this->_add_event ( $element, $js, 'blur' ); |
|
64 | + public function blur($element='this', $js='') { |
|
65 | + return $this->_add_event($element, $js, 'blur'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param boolean $stopPropagation |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function change($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
80 | - return $this->_add_event ( $element, $js, 'change', $preventDefault, $stopPropagation ); |
|
79 | + public function change($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
80 | + return $this->_add_event($element, $js, 'change', $preventDefault, $stopPropagation); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | * @param boolean $stopPropagation |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public function click($element = 'this', $js = '', $ret_false = TRUE, $preventDefault = false, $stopPropagation = false) { |
|
97 | - if (! is_array ( $js )) { |
|
98 | - $js = array ( |
|
96 | + public function click($element='this', $js='', $ret_false=TRUE, $preventDefault=false, $stopPropagation=false) { |
|
97 | + if (!is_array($js)) { |
|
98 | + $js=array( |
|
99 | 99 | $js |
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($ret_false) { |
104 | - $js [] = "return false;"; |
|
104 | + $js []="return false;"; |
|
105 | 105 | } |
106 | 106 | |
107 | - return $this->_add_event ( $element, $js, 'click', $preventDefault, $stopPropagation ); |
|
107 | + return $this->_add_event($element, $js, 'click', $preventDefault, $stopPropagation); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * code to execute |
117 | 117 | * @return string |
118 | 118 | */ |
119 | - public function contextmenu($element = 'this', $js = '') { |
|
120 | - return $this->_add_event ( $element, $js, 'contextmenu' ); |
|
119 | + public function contextmenu($element='this', $js='') { |
|
120 | + return $this->_add_event($element, $js, 'contextmenu'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * code to execute |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public function dblclick($element = 'this', $js = '') { |
|
133 | - return $this->_add_event ( $element, $js, 'dblclick' ); |
|
132 | + public function dblclick($element='this', $js='') { |
|
133 | + return $this->_add_event($element, $js, 'dblclick'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * code to execute |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function error($element = 'this', $js = '') { |
|
146 | - return $this->_add_event ( $element, $js, 'error' ); |
|
145 | + public function error($element='this', $js='') { |
|
146 | + return $this->_add_event($element, $js, 'error'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * code to execute |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function focus($element = 'this', $js = '') { |
|
159 | - return $this->_add_event ( $element, $js, 'focus' ); |
|
158 | + public function focus($element='this', $js='') { |
|
159 | + return $this->_add_event($element, $js, 'focus'); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * code for mouse out |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function hover($element = 'this', $over = '', $out = '') { |
|
173 | - $event = "\n\t$(" . Javascript::prep_element ( $element ) . ").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
|
174 | - $this->jquery_code_for_compile [] = $event; |
|
172 | + public function hover($element='this', $over='', $out='') { |
|
173 | + $event="\n\t$(".Javascript::prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
|
174 | + $this->jquery_code_for_compile []=$event; |
|
175 | 175 | return $event; |
176 | 176 | } |
177 | 177 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * code to execute |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - public function keydown($element = 'this', $js = '') { |
|
188 | - return $this->_add_event ( $element, $js, 'keydown' ); |
|
187 | + public function keydown($element='this', $js='') { |
|
188 | + return $this->_add_event($element, $js, 'keydown'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * code to execute |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - public function keypress($element = 'this', $js = '') { |
|
201 | - return $this->_add_event ( $element, $js, 'keypress' ); |
|
200 | + public function keypress($element='this', $js='') { |
|
201 | + return $this->_add_event($element, $js, 'keypress'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * code to execute |
211 | 211 | * @return string |
212 | 212 | */ |
213 | - public function keyup($element = 'this', $js = '') { |
|
214 | - return $this->_add_event ( $element, $js, 'keyup' ); |
|
213 | + public function keyup($element='this', $js='') { |
|
214 | + return $this->_add_event($element, $js, 'keyup'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * code to execute |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - public function load($element = 'this', $js = '') { |
|
227 | - return $this->_add_event ( $element, $js, 'load' ); |
|
226 | + public function load($element='this', $js='') { |
|
227 | + return $this->_add_event($element, $js, 'load'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * code to execute |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - public function mousedown($element = 'this', $js = '') { |
|
240 | - return $this->_add_event ( $element, $js, 'mousedown' ); |
|
239 | + public function mousedown($element='this', $js='') { |
|
240 | + return $this->_add_event($element, $js, 'mousedown'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * code to execute |
250 | 250 | * @return string |
251 | 251 | */ |
252 | - public function mouseout($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
253 | - return $this->_add_event ( $element, $js, 'mouseout', $preventDefault, $stopPropagation ); |
|
252 | + public function mouseout($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
253 | + return $this->_add_event($element, $js, 'mouseout', $preventDefault, $stopPropagation); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * code to execute |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function mouseleave($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
266 | - return $this->_add_event ( $element, $js, 'mouseleave', $preventDefault, $stopPropagation ); |
|
265 | + public function mouseleave($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
266 | + return $this->_add_event($element, $js, 'mouseleave', $preventDefault, $stopPropagation); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * code to execute |
276 | 276 | * @return string |
277 | 277 | */ |
278 | - public function mouseenter($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
279 | - return $this->_add_event ( $element, $js, 'mouseenter', $preventDefault, $stopPropagation ); |
|
278 | + public function mouseenter($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
279 | + return $this->_add_event($element, $js, 'mouseenter', $preventDefault, $stopPropagation); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -288,8 +288,8 @@ discard block |
||
288 | 288 | * code to execute |
289 | 289 | * @return string |
290 | 290 | */ |
291 | - public function mouseover($element = 'this', $js = '') { |
|
292 | - return $this->_add_event ( $element, $js, 'mouseover' ); |
|
291 | + public function mouseover($element='this', $js='') { |
|
292 | + return $this->_add_event($element, $js, 'mouseover'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * code to execute |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function mouseup($element = 'this', $js = '') { |
|
305 | - return $this->_add_event ( $element, $js, 'mouseup' ); |
|
304 | + public function mouseup($element='this', $js='') { |
|
305 | + return $this->_add_event($element, $js, 'mouseup'); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * code to execute |
315 | 315 | * @return string |
316 | 316 | */ |
317 | - public function unload($element = 'this', $js = '') { |
|
318 | - return $this->_add_event ( $element, $js, 'unload' ); |
|
317 | + public function unload($element='this', $js='') { |
|
318 | + return $this->_add_event($element, $js, 'unload'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // -------------------------------------------------------------------- |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * code to execute |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public function resize($element = 'this', $js = '') { |
|
332 | - return $this->_add_event ( $element, $js, 'resize' ); |
|
331 | + public function resize($element='this', $js='') { |
|
332 | + return $this->_add_event($element, $js, 'resize'); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // -------------------------------------------------------------------- |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * code to execute |
343 | 343 | * @return string |
344 | 344 | */ |
345 | - public function scroll($element = 'this', $js = '') { |
|
346 | - return $this->_add_event ( $element, $js, 'scroll' ); |
|
345 | + public function scroll($element='this', $js='') { |
|
346 | + return $this->_add_event($element, $js, 'scroll'); |
|
347 | 347 | } |
348 | 348 | } |
@@ -14,210 +14,210 @@ discard block |
||
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); |
|
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); |
|
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
351 | 351 | * @param array $parameters |
352 | 352 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null) |
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) |
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 |
||
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 |
||
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) |
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,14 +519,14 @@ discard block |
||
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) |
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 | - ] ); |
|
529 | - return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ["method"], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
528 | + ]); |
|
529 | + return $this->_add_event($element, $this->ajaxDeferred($parameters ["method"], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -542,8 +542,8 @@ discard block |
||
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) |
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 |
||
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) |
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 |
||
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 |
||
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 |
||
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 |
||
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,13 +665,13 @@ discard block |
||
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) |
667 | 667 | */ |
668 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
669 | - $this->setDefaultParameters ( $parameters, [ |
|
668 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
669 | + $this->setDefaultParameters($parameters, [ |
|
670 | 670 | "preventDefault" => true, |
671 | 671 | "stopPropagation" => true, |
672 | 672 | "immediatly" => true |
673 | - ] ); |
|
674 | - return $this->_add_event ( $element, $this->postDeferred ( $url, $params, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
673 | + ]); |
|
674 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | /** |
@@ -688,65 +688,65 @@ discard block |
||
688 | 688 | * @param array $parameters |
689 | 689 | * 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) |
690 | 690 | */ |
691 | - public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
692 | - return $this->postOn ( "click", $element, $url, $params, $responseElement, $parameters ); |
|
693 | - } |
|
694 | - private function _postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
695 | - if (isset ( $this->params ["ajax"] )) { |
|
696 | - extract ( $this->params ["ajax"] ); |
|
697 | - } |
|
698 | - $params = "{}"; |
|
699 | - $validation = false; |
|
700 | - \extract ( $parameters ); |
|
701 | - $async = ($async) ? "true" : "false"; |
|
702 | - $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
703 | - $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
704 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
705 | - if (! isset ( $contentType ) || $contentType != 'false') { |
|
706 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
707 | - if (isset ( $params )) { |
|
708 | - $retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n"; |
|
691 | + public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
692 | + return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
|
693 | + } |
|
694 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
695 | + if (isset ($this->params ["ajax"])) { |
|
696 | + extract($this->params ["ajax"]); |
|
697 | + } |
|
698 | + $params="{}"; |
|
699 | + $validation=false; |
|
700 | + \extract($parameters); |
|
701 | + $async=($async) ? "true" : "false"; |
|
702 | + $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
703 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
704 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
705 | + if (!isset ($contentType) || $contentType!='false') { |
|
706 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
707 | + if (isset ($params)) { |
|
708 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
709 | 709 | } |
710 | 710 | } else { |
711 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
712 | - } |
|
713 | - $responseElement = $this->_getResponseElement ( $responseElement ); |
|
714 | - $retour .= "var self=this;\n"; |
|
715 | - $before = isset ( $before ) ? $before : ""; |
|
716 | - $retour .= $before; |
|
717 | - if ($hasLoader === true) { |
|
718 | - $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
719 | - } elseif ($hasLoader === 'response') { |
|
720 | - $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
721 | - } elseif ($hasLoader === 'internal') { |
|
722 | - $retour .= "\n$(this).addClass('loading');"; |
|
723 | - } |
|
724 | - $ajaxParameters = [ |
|
711 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
712 | + } |
|
713 | + $responseElement=$this->_getResponseElement($responseElement); |
|
714 | + $retour.="var self=this;\n"; |
|
715 | + $before=isset ($before) ? $before : ""; |
|
716 | + $retour.=$before; |
|
717 | + if ($hasLoader===true) { |
|
718 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
719 | + } elseif ($hasLoader==='response') { |
|
720 | + $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
721 | + } elseif ($hasLoader==='internal') { |
|
722 | + $retour.="\n$(this).addClass('loading');"; |
|
723 | + } |
|
724 | + $ajaxParameters=[ |
|
725 | 725 | "url" => "url", |
726 | 726 | "method" => "'POST'", |
727 | 727 | "data" => "params", |
728 | 728 | "async" => $async |
729 | 729 | ]; |
730 | - if (isset ( $headers )) { |
|
731 | - $ajaxParameters ["headers"] = $headers; |
|
730 | + if (isset ($headers)) { |
|
731 | + $ajaxParameters ["headers"]=$headers; |
|
732 | 732 | } |
733 | - if (isset ( $partial )) { |
|
734 | - $ajaxParameters ["xhr"] = "xhrProvider"; |
|
735 | - $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 | + if (isset ($partial)) { |
|
734 | + $ajaxParameters ["xhr"]="xhrProvider"; |
|
735 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
736 | 736 | } |
737 | - $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
738 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n"; |
|
739 | - $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n"; |
|
737 | + $this->createAjaxParameters($ajaxParameters, $parameters); |
|
738 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
739 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
740 | 740 | |
741 | 741 | if ($validation) { |
742 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
743 | - " . $retour . " |
|
742 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
743 | + " . $retour." |
|
744 | 744 | }});\n"; |
745 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
745 | + $retour.="$('#".$form."').submit();\n"; |
|
746 | 746 | } |
747 | - $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
747 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
748 | 748 | if ($immediatly) |
749 | - $this->jquery_code_for_compile [] = $retour; |
|
749 | + $this->jquery_code_for_compile []=$retour; |
|
750 | 750 | return $retour; |
751 | 751 | } |
752 | 752 | |
@@ -762,9 +762,9 @@ discard block |
||
762 | 762 | * @param array $parameters |
763 | 763 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
764 | 764 | */ |
765 | - public function postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
766 | - $parameters ["immediatly"] = true; |
|
767 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
765 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
766 | + $parameters ["immediatly"]=true; |
|
767 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -780,9 +780,9 @@ discard block |
||
780 | 780 | * @param array $parameters |
781 | 781 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
782 | 782 | */ |
783 | - public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) { |
|
784 | - $parameters ["immediatly"] = false; |
|
785 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
783 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
784 | + $parameters ["immediatly"]=false; |
|
785 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -798,13 +798,13 @@ discard block |
||
798 | 798 | * @param array $parameters |
799 | 799 | * 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) |
800 | 800 | */ |
801 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
802 | - $this->setDefaultParameters ( $parameters, [ |
|
801 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
802 | + $this->setDefaultParameters($parameters, [ |
|
803 | 803 | "preventDefault" => true, |
804 | 804 | "stopPropagation" => true, |
805 | 805 | "immediatly" => true |
806 | - ] ); |
|
807 | - return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
806 | + ]); |
|
807 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @param array $parameters |
820 | 820 | * 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) |
821 | 821 | */ |
822 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
823 | - return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters ); |
|
822 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
823 | + return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
|
824 | 824 | } |
825 | 825 | } |
@@ -60,8 +60,9 @@ discard block |
||
60 | 60 | $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n"; |
61 | 61 | |
62 | 62 | $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
63 | - if ($immediatly) |
|
64 | - $this->jquery_code_for_compile [] = $retour; |
|
63 | + if ($immediatly) { |
|
64 | + $this->jquery_code_for_compile [] = $retour; |
|
65 | + } |
|
65 | 66 | return $retour; |
66 | 67 | } |
67 | 68 | protected function createAjaxParameters(&$original, $parameters) { |
@@ -112,8 +113,9 @@ discard block |
||
112 | 113 | $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
113 | 114 | } elseif (\substr ( $attr, 0, 3 ) === "js:") { |
114 | 115 | $retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n"; |
115 | - } elseif ($attr !== null && $attr !== "") |
|
116 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
116 | + } elseif ($attr !== null && $attr !== "") { |
|
117 | + $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
118 | + } |
|
117 | 119 | } |
118 | 120 | return $retour; |
119 | 121 | } |
@@ -134,10 +136,11 @@ discard block |
||
134 | 136 | } elseif (isset ( $this->ajaxTransition )) { |
135 | 137 | $call = $this->ajaxTransition; |
136 | 138 | } |
137 | - if (\is_callable ( $call )) |
|
138 | - $retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n"; |
|
139 | - else |
|
140 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
139 | + if (\is_callable ( $call )) { |
|
140 | + $retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n"; |
|
141 | + } else { |
|
142 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
143 | + } |
|
141 | 144 | } |
142 | 145 | if (isset ( $history )) { |
143 | 146 | if ($this->params ["autoActiveLinks"]) { |
@@ -158,8 +161,9 @@ discard block |
||
158 | 161 | return $responseElement; |
159 | 162 | } |
160 | 163 | protected function _correctAjaxUrl($url) { |
161 | - if ($url !== "/" && JString::endsWith ( $url, "/" ) === true) |
|
162 | - $url = substr ( $url, 0, strlen ( $url ) - 1 ); |
|
164 | + if ($url !== "/" && JString::endsWith ( $url, "/" ) === true) { |
|
165 | + $url = substr ( $url, 0, strlen ( $url ) - 1 ); |
|
166 | + } |
|
163 | 167 | if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) { |
164 | 168 | $url = $this->getUrl ( $url ); |
165 | 169 | } |
@@ -181,8 +185,9 @@ discard block |
||
181 | 185 | public static function _implodeParams($parameters) { |
182 | 186 | $allParameters = [ ]; |
183 | 187 | foreach ( $parameters as $params ) { |
184 | - if (isset ( $params )) |
|
185 | - $allParameters [] = self::_correctParams ( $params ); |
|
188 | + if (isset ( $params )) { |
|
189 | + $allParameters [] = self::_correctParams ( $params ); |
|
190 | + } |
|
186 | 191 | } |
187 | 192 | return \implode ( "+'&'+", $allParameters ); |
188 | 193 | } |
@@ -212,8 +217,9 @@ discard block |
||
212 | 217 | } |
213 | 218 | protected function setDefaultParameters(&$parameters, $default) { |
214 | 219 | foreach ( $default as $k => $v ) { |
215 | - if (! isset ( $parameters [$k] )) |
|
216 | - $parameters [$k] = $v; |
|
220 | + if (! isset ( $parameters [$k] )) { |
|
221 | + $parameters [$k] = $v; |
|
222 | + } |
|
217 | 223 | } |
218 | 224 | } |
219 | 225 | public function setAjaxLoader($loader) { |
@@ -745,8 +751,9 @@ discard block |
||
745 | 751 | $retour .= "$('#" . $form . "').submit();\n"; |
746 | 752 | } |
747 | 753 | $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
748 | - if ($immediatly) |
|
749 | - $this->jquery_code_for_compile [] = $retour; |
|
754 | + if ($immediatly) { |
|
755 | + $this->jquery_code_for_compile [] = $retour; |
|
756 | + } |
|
750 | 757 | return $retour; |
751 | 758 | } |
752 | 759 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @property array $jquery_code_for_compile_at_last |
12 | 12 | */ |
13 | 13 | trait JsUtilsActionsTrait { |
14 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
14 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * show or hide with effect |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * defers the execution if set to false |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
31 | - $element = Javascript::prep_element ( $element ); |
|
32 | - $speed = $this->_validate_speed ( $speed ); |
|
33 | - if ($callback != '') { |
|
34 | - $callback = ", function(){\n{$callback}\n}"; |
|
30 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
31 | + $element=Javascript::prep_element($element); |
|
32 | + $speed=$this->_validate_speed($speed); |
|
33 | + if ($callback!='') { |
|
34 | + $callback=", function(){\n{$callback}\n}"; |
|
35 | 35 | } |
36 | - $str = "$({$element}).{$action}({$speed}{$callback});"; |
|
36 | + $str="$({$element}).{$action}({$speed}{$callback});"; |
|
37 | 37 | if ($immediatly) |
38 | - $this->jquery_code_for_compile [] = $str; |
|
38 | + $this->jquery_code_for_compile []=$str; |
|
39 | 39 | return $str; |
40 | 40 | } |
41 | 41 | |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @return string |
47 | 47 | */ |
48 | 48 | private function _validate_speed($speed) { |
49 | - if (in_array ( $speed, array ( |
|
49 | + if (in_array($speed, array( |
|
50 | 50 | 'slow', |
51 | 51 | 'normal', |
52 | 52 | 'fast' |
53 | - ) )) { |
|
54 | - $speed = '"' . $speed . '"'; |
|
55 | - } elseif (preg_match ( "/[^0-9]/", $speed )) { |
|
56 | - $speed = ''; |
|
53 | + ))) { |
|
54 | + $speed='"'.$speed.'"'; |
|
55 | + } elseif (preg_match("/[^0-9]/", $speed)) { |
|
56 | + $speed=''; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | return $speed; |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | * @param boolean $immediatly |
69 | 69 | * delayed if false |
70 | 70 | */ |
71 | - public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) { |
|
72 | - $element = Javascript::prep_element ( $element ); |
|
73 | - if (isset ( $param )) { |
|
74 | - $param = Javascript::prep_value ( $param ); |
|
75 | - $str = "$({$element}).{$jQueryCall}({$param});"; |
|
71 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
72 | + $element=Javascript::prep_element($element); |
|
73 | + if (isset ($param)) { |
|
74 | + $param=Javascript::prep_value($param); |
|
75 | + $str="$({$element}).{$jQueryCall}({$param});"; |
|
76 | 76 | } else |
77 | - $str = "$({$element}).{$jQueryCall}();"; |
|
77 | + $str="$({$element}).{$jQueryCall}();"; |
|
78 | 78 | if ($immediatly) |
79 | - $this->jquery_code_for_compile [] = $str; |
|
79 | + $this->jquery_code_for_compile []=$str; |
|
80 | 80 | return $str; |
81 | 81 | } |
82 | 82 | |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * delayed if false |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) { |
|
94 | - $to = Javascript::prep_element ( $to ); |
|
95 | - $element = Javascript::prep_element ( $element ); |
|
96 | - $str = "$({$to}).{$jQueryCall}({$element});"; |
|
93 | + public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) { |
|
94 | + $to=Javascript::prep_element($to); |
|
95 | + $element=Javascript::prep_element($element); |
|
96 | + $str="$({$to}).{$jQueryCall}({$element});"; |
|
97 | 97 | if ($immediatly) |
98 | - $this->jquery_code_for_compile [] = $str; |
|
98 | + $this->jquery_code_for_compile []=$str; |
|
99 | 99 | return $str; |
100 | 100 | } |
101 | 101 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * defers the execution if set to false |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function addClass($element = 'this', $class = '', $immediatly = false) { |
|
113 | - return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly ); |
|
112 | + public function addClass($element='this', $class='', $immediatly=false) { |
|
113 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * defers the execution if set to false |
123 | 123 | * @return string |
124 | 124 | */ |
125 | - public function after($to, $element, $immediatly = false) { |
|
126 | - return $this->_genericCallElement ( 'after', $to, $element, $immediatly ); |
|
125 | + public function after($to, $element, $immediatly=false) { |
|
126 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * defers the execution if set to false |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function before($to, $element, $immediatly = false) { |
|
139 | - return $this->_genericCallElement ( 'before', $to, $element, $immediatly ); |
|
138 | + public function before($to, $element, $immediatly=false) { |
|
139 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | * @param boolean $immediatly |
149 | 149 | * delayed if false |
150 | 150 | */ |
151 | - public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) { |
|
152 | - $element = Javascript::prep_element ( $element ); |
|
153 | - if (isset ( $value )) { |
|
154 | - $value = Javascript::prep_value ( $value ); |
|
155 | - $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
|
151 | + public function attr($element='this', $attributeName='id', $value="", $immediatly=false) { |
|
152 | + $element=Javascript::prep_element($element); |
|
153 | + if (isset ($value)) { |
|
154 | + $value=Javascript::prep_value($value); |
|
155 | + $str="$({$element}).attr(\"$attributeName\",{$value});"; |
|
156 | 156 | } else |
157 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
157 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
158 | 158 | if ($immediatly) |
159 | - $this->jquery_code_for_compile [] = $str; |
|
159 | + $this->jquery_code_for_compile []=$str; |
|
160 | 160 | return $str; |
161 | 161 | } |
162 | 162 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param boolean $immediatly |
169 | 169 | * defers the execution if set to false |
170 | 170 | */ |
171 | - public function val($element = 'this', $value = '', $immediatly = false) { |
|
172 | - return $this->_genericCallValue ( 'val', $element, $value, $immediatly ); |
|
171 | + public function val($element='this', $value='', $immediatly=false) { |
|
172 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | * @param boolean $immediatly |
181 | 181 | * defers the execution if set to false |
182 | 182 | */ |
183 | - public function html($element = 'this', $value = '', $immediatly = false) { |
|
184 | - return $this->_genericCallValue ( 'html', $element, $value, $immediatly ); |
|
183 | + public function html($element='this', $value='', $immediatly=false) { |
|
184 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -197,30 +197,30 @@ discard block |
||
197 | 197 | * defers the execution if set to false |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) { |
|
201 | - $element = Javascript::prep_element ( $element ); |
|
202 | - $speed = $this->_validate_speed ( $speed ); |
|
200 | + public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
|
201 | + $element=Javascript::prep_element($element); |
|
202 | + $speed=$this->_validate_speed($speed); |
|
203 | 203 | |
204 | - $animations = "\t\t\t"; |
|
205 | - if (\is_array ( $params )) { |
|
206 | - foreach ( $params as $param => $value ) { |
|
207 | - $animations .= $param . ': \'' . $value . '\', '; |
|
204 | + $animations="\t\t\t"; |
|
205 | + if (\is_array($params)) { |
|
206 | + foreach ($params as $param => $value) { |
|
207 | + $animations.=$param.': \''.$value.'\', '; |
|
208 | 208 | } |
209 | 209 | } |
210 | - $animations = substr ( $animations, 0, - 2 ); // remove the last ", " |
|
210 | + $animations=substr($animations, 0, - 2); // remove the last ", " |
|
211 | 211 | |
212 | - if ($speed != '') { |
|
213 | - $speed = ', ' . $speed; |
|
212 | + if ($speed!='') { |
|
213 | + $speed=', '.$speed; |
|
214 | 214 | } |
215 | 215 | |
216 | - if ($extra != '') { |
|
217 | - $extra = ', ' . $extra; |
|
216 | + if ($extra!='') { |
|
217 | + $extra=', '.$extra; |
|
218 | 218 | } |
219 | 219 | |
220 | - $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
|
220 | + $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
|
221 | 221 | |
222 | 222 | if ($immediatly) |
223 | - $this->jquery_code_for_compile [] = $str; |
|
223 | + $this->jquery_code_for_compile []=$str; |
|
224 | 224 | return $str; |
225 | 225 | } |
226 | 226 | |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * defers the execution if set to false |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - public function append($to, $element, $immediatly = false) { |
|
237 | - return $this->_genericCallElement ( 'append', $to, $element, $immediatly ); |
|
236 | + public function append($to, $element, $immediatly=false) { |
|
237 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | * defers the execution if set to false |
247 | 247 | * @return string |
248 | 248 | */ |
249 | - public function prepend($to, $element, $immediatly = false) { |
|
250 | - return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly ); |
|
249 | + public function prepend($to, $element, $immediatly=false) { |
|
250 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * defers the execution if set to false |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
267 | - return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly ); |
|
266 | + public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
267 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * defers the execution if set to false |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
284 | - return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly ); |
|
283 | + public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
284 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -297,8 +297,8 @@ discard block |
||
297 | 297 | * defers the execution if set to false |
298 | 298 | * @return string |
299 | 299 | */ |
300 | - public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
301 | - return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly ); |
|
300 | + public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
301 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * defers the execution if set to false |
313 | 313 | * @return string |
314 | 314 | */ |
315 | - public function removeClass($element = 'this', $class = '', $immediatly = false) { |
|
316 | - return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly ); |
|
315 | + public function removeClass($element='this', $class='', $immediatly=false) { |
|
316 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * defers the execution if set to false |
330 | 330 | * @return string |
331 | 331 | */ |
332 | - public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
333 | - return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly ); |
|
332 | + public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
333 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | * defers the execution if set to false |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
350 | - return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly ); |
|
349 | + public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
350 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * defers the execution if set to false |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
367 | - return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly ); |
|
366 | + public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
367 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * defers the execution if set to false |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
384 | - return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly ); |
|
383 | + public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
384 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * defers the execution if set to false |
395 | 395 | * @return string |
396 | 396 | */ |
397 | - public function toggleClass($element = 'this', $class = '', $immediatly = false) { |
|
398 | - return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly ); |
|
397 | + public function toggleClass($element='this', $class='', $immediatly=false) { |
|
398 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * @param boolean $immediatly |
407 | 407 | * defers the execution if set to false |
408 | 408 | */ |
409 | - public function trigger($element = 'this', $event = 'click', $immediatly = false) { |
|
410 | - $element = Javascript::prep_element ( $element ); |
|
411 | - $str = "$({$element}).trigger(\"$event\");"; |
|
409 | + public function trigger($element='this', $event='click', $immediatly=false) { |
|
410 | + $element=Javascript::prep_element($element); |
|
411 | + $str="$({$element}).trigger(\"$event\");"; |
|
412 | 412 | |
413 | 413 | if ($immediatly) |
414 | - $this->jquery_code_for_compile [] = $str; |
|
414 | + $this->jquery_code_for_compile []=$str; |
|
415 | 415 | return $str; |
416 | 416 | } |
417 | 417 | |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * defers the execution if set to false |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
432 | - return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly ); |
|
431 | + public function show($element='this', $speed='', $callback='', $immediatly=false) { |
|
432 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -439,18 +439,18 @@ discard block |
||
439 | 439 | * @param array $options |
440 | 440 | * @return string |
441 | 441 | */ |
442 | - public function sortable($element, $options = array ()) { |
|
443 | - if (count ( $options ) > 0) { |
|
444 | - $sort_options = array (); |
|
445 | - foreach ( $options as $k => $v ) { |
|
446 | - $sort_options [] = "\n\t\t" . $k . ': ' . $v . ""; |
|
442 | + public function sortable($element, $options=array()) { |
|
443 | + if (count($options)>0) { |
|
444 | + $sort_options=array(); |
|
445 | + foreach ($options as $k => $v) { |
|
446 | + $sort_options []="\n\t\t".$k.': '.$v.""; |
|
447 | 447 | } |
448 | - $sort_options = implode ( ",", $sort_options ); |
|
448 | + $sort_options=implode(",", $sort_options); |
|
449 | 449 | } else { |
450 | - $sort_options = ''; |
|
450 | + $sort_options=''; |
|
451 | 451 | } |
452 | 452 | |
453 | - return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});"; |
|
453 | + return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});"; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | * plugin location |
463 | 463 | * @return string |
464 | 464 | */ |
465 | - public function tablesorter($table = '', $options = '') { |
|
466 | - $this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n"; |
|
465 | + public function tablesorter($table='', $options='') { |
|
466 | + $this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n"; |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -475,14 +475,14 @@ discard block |
||
475 | 475 | * @param boolean $immediatly |
476 | 476 | * defers the execution if set to false |
477 | 477 | */ |
478 | - public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) { |
|
479 | - $str = "if(" . $condition . "){" . $jsCodeIfTrue . "}"; |
|
480 | - if (isset ( $jsCodeIfFalse )) { |
|
481 | - $str .= "else{" . $jsCodeIfFalse . "}"; |
|
478 | + public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
|
479 | + $str="if(".$condition."){".$jsCodeIfTrue."}"; |
|
480 | + if (isset ($jsCodeIfFalse)) { |
|
481 | + $str.="else{".$jsCodeIfFalse."}"; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | if ($immediatly) |
485 | - $this->jquery_code_for_compile [] = $str; |
|
485 | + $this->jquery_code_for_compile []=$str; |
|
486 | 486 | return $str; |
487 | 487 | } |
488 | 488 | |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | * @param boolean $immediatly |
498 | 498 | * @return string |
499 | 499 | */ |
500 | - private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
|
501 | - $param = Javascript::prep_value ( $param ); |
|
502 | - $callback = ""; |
|
503 | - if ($jsCallback != "") |
|
504 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
505 | - $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
|
500 | + private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
|
501 | + $param=Javascript::prep_value($param); |
|
502 | + $callback=""; |
|
503 | + if ($jsCallback!="") |
|
504 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
505 | + $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
|
506 | 506 | if ($immediatly) |
507 | - $this->jquery_code_for_compile [] = $script; |
|
507 | + $this->jquery_code_for_compile []=$script; |
|
508 | 508 | return $script; |
509 | 509 | } |
510 | 510 | |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | * javascript code to execute after the jquery call |
522 | 522 | * @return mixed |
523 | 523 | */ |
524 | - public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
525 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true ); |
|
524 | + public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
|
525 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * javascript code to execute after the jquery call |
539 | 539 | * @return mixed |
540 | 540 | */ |
541 | - public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
542 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false ); |
|
541 | + public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
|
542 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | * @param boolean $immediatly |
557 | 557 | * @return string |
558 | 558 | */ |
559 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) { |
|
560 | - return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
559 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
560 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -571,13 +571,13 @@ discard block |
||
571 | 571 | * @param array $parameters |
572 | 572 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
573 | 573 | */ |
574 | - public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) { |
|
575 | - $jsCallback = ""; |
|
576 | - $stopPropagation = false; |
|
577 | - $preventDefault = false; |
|
578 | - $immediatly = true; |
|
579 | - extract ( $parameters ); |
|
580 | - return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly ); |
|
574 | + public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
575 | + $jsCallback=""; |
|
576 | + $stopPropagation=false; |
|
577 | + $preventDefault=false; |
|
578 | + $immediatly=true; |
|
579 | + extract($parameters); |
|
580 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | * delayed if false |
590 | 590 | * @return String |
591 | 591 | */ |
592 | - public function exec($js, $immediatly = false) { |
|
593 | - $script = $js . "\n"; |
|
592 | + public function exec($js, $immediatly=false) { |
|
593 | + $script=$js."\n"; |
|
594 | 594 | if ($immediatly) |
595 | - $this->jquery_code_for_compile [] = $script; |
|
595 | + $this->jquery_code_for_compile []=$script; |
|
596 | 596 | return $script; |
597 | 597 | } |
598 | 598 | |
@@ -606,8 +606,8 @@ discard block |
||
606 | 606 | * @return String |
607 | 607 | */ |
608 | 608 | public function execAtLast($js) { |
609 | - $script = $js . "\n"; |
|
610 | - $this->jquery_code_for_compile_at_last [] = $script; |
|
609 | + $script=$js."\n"; |
|
610 | + $this->jquery_code_for_compile_at_last []=$script; |
|
611 | 611 | return $script; |
612 | 612 | } |
613 | 613 | |
@@ -622,18 +622,18 @@ discard block |
||
622 | 622 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
623 | 623 | * @return String |
624 | 624 | */ |
625 | - public function execOn($event, $element, $js, $parameters = array ()) { |
|
626 | - $stopPropagation = false; |
|
627 | - $preventDefault = false; |
|
628 | - $immediatly = true; |
|
629 | - extract ( $parameters ); |
|
630 | - $script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
625 | + public function execOn($event, $element, $js, $parameters=array()) { |
|
626 | + $stopPropagation=false; |
|
627 | + $preventDefault=false; |
|
628 | + $immediatly=true; |
|
629 | + extract($parameters); |
|
630 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
631 | 631 | return $script; |
632 | 632 | } |
633 | - public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) { |
|
634 | - $retour = "var data={$json};" . "\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);" . "\n\tvar pk=data['pk'];var object=data['object'];" . "\n\tfor(var field in object){" . "\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){" . "\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){" . "\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }" . "\n\t});" . "\n}};\n"; |
|
635 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
636 | - return $this->exec ( $retour, $immediatly ); |
|
633 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
634 | + $retour="var data={$json};"."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);"."\n\tvar pk=data['pk'];var object=data['object'];"."\n\tfor(var field in object){"."\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){"."\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){"."\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }"."\n\t});"."\n}};\n"; |
|
635 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
636 | + return $this->exec($retour, $immediatly); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -644,13 +644,13 @@ discard block |
||
644 | 644 | * @param array $parameters |
645 | 645 | * default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
646 | 646 | */ |
647 | - public function setDraggable($element, $parameters = [ ]) { |
|
648 | - $attr = "id"; |
|
649 | - $preventDefault = false; |
|
650 | - $stopPropagation = false; |
|
651 | - $immediatly = true; |
|
652 | - extract ( $parameters ); |
|
653 | - $script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly ); |
|
647 | + public function setDraggable($element, $parameters=[]) { |
|
648 | + $attr="id"; |
|
649 | + $preventDefault=false; |
|
650 | + $stopPropagation=false; |
|
651 | + $immediatly=true; |
|
652 | + extract($parameters); |
|
653 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly); |
|
654 | 654 | return $script; |
655 | 655 | } |
656 | 656 | |
@@ -664,13 +664,13 @@ discard block |
||
664 | 664 | * @param string $jsCallback |
665 | 665 | * the js script to call when element is dropped |
666 | 666 | */ |
667 | - public function asDropZone($element, $jsCallback = "", $parameters = [ ]) { |
|
668 | - $stopPropagation = false; |
|
669 | - $immediatly = true; |
|
670 | - $jqueryDone = "append"; |
|
671 | - $script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly ); |
|
672 | - extract ( $parameters ); |
|
673 | - $script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly ); |
|
667 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
668 | + $stopPropagation=false; |
|
669 | + $immediatly=true; |
|
670 | + $jqueryDone="append"; |
|
671 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
672 | + extract($parameters); |
|
673 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
674 | 674 | return $script; |
675 | 675 | } |
676 | 676 | |
@@ -687,16 +687,16 @@ discard block |
||
687 | 687 | * delayed if false |
688 | 688 | * @return string |
689 | 689 | */ |
690 | - public function interval($jsCode, $time, $globalName = null, $immediatly = true) { |
|
691 | - if (! Javascript::isFunction ( $jsCode )) { |
|
692 | - $jsCode = "function(){\n" . $jsCode . "\n}"; |
|
690 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
691 | + if (!Javascript::isFunction($jsCode)) { |
|
692 | + $jsCode="function(){\n".$jsCode."\n}"; |
|
693 | 693 | } |
694 | - if (isset ( $globalName )) { |
|
695 | - $script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
694 | + if (isset ($globalName)) { |
|
695 | + $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
696 | 696 | } else { |
697 | - $script = "setInterval({$jsCode},{$time});"; |
|
697 | + $script="setInterval({$jsCode},{$time});"; |
|
698 | 698 | } |
699 | - return $this->exec ( $script, $immediatly ); |
|
699 | + return $this->exec($script, $immediatly); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | * delayed if false |
709 | 709 | * @return string |
710 | 710 | */ |
711 | - public function clearInterval($globalName, $immediatly = true) { |
|
712 | - return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly ); |
|
711 | + public function clearInterval($globalName, $immediatly=true) { |
|
712 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | /** |
@@ -730,20 +730,20 @@ discard block |
||
730 | 730 | * delayed if false |
731 | 731 | * @return string |
732 | 732 | */ |
733 | - public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) { |
|
734 | - $stop = ""; |
|
733 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
734 | + $stop=""; |
|
735 | 735 | if ($countDown) { |
736 | - $stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
736 | + $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
737 | 737 | } else { |
738 | - if ($limit != 0) { |
|
739 | - $stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
738 | + if ($limit!=0) { |
|
739 | + $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
740 | 740 | } |
741 | 741 | } |
742 | - $global = ""; |
|
743 | - if (isset ( $globalName )) { |
|
744 | - $global = "\nwindow.{$globalName}=interval;"; |
|
742 | + $global=""; |
|
743 | + if (isset ($globalName)) { |
|
744 | + $global="\nwindow.{$globalName}=interval;"; |
|
745 | 745 | } |
746 | - $timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
746 | + $timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
747 | 747 | var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};}; |
748 | 748 | var shHide=function(v,k,kBefore){if(v==0 && display.find(k).closest('.timer').is(':visible') && (!kBefore || !display.find(kBefore).closest('.timer').is(':visible'))){display.find(k).closest('.timer').hide();}else{sh(display.find(k),v);}}; |
749 | 749 | var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';}; |
@@ -759,12 +759,12 @@ discard block |
||
759 | 759 | minutes = d0(parseInt((timer%3600) / 60, 10)); |
760 | 760 | seconds = d0(parseInt(timer%60, 10)); |
761 | 761 | mainSh(days,hours,minutes,seconds); |
762 | - " . $stop . " |
|
762 | + " . $stop." |
|
763 | 763 | }, 1000); |
764 | - " . $global . " |
|
764 | + " . $global." |
|
765 | 765 | }"; |
766 | - $element = '$("' . $counterSelector . '")'; |
|
767 | - return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly ); |
|
766 | + $element='$("'.$counterSelector.'")'; |
|
767 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -786,8 +786,8 @@ discard block |
||
786 | 786 | * count down if true or elapse if false |
787 | 787 | * @return string |
788 | 788 | */ |
789 | - public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) { |
|
790 | - return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) ); |
|
789 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
790 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | /** |
@@ -801,8 +801,8 @@ discard block |
||
801 | 801 | * the active href (if null, window.location.href is used) |
802 | 802 | * @return string |
803 | 803 | */ |
804 | - public function activateLink($target, $property = 'href', $href = null) { |
|
805 | - return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) ); |
|
804 | + public function activateLink($target, $property='href', $href=null) { |
|
805 | + return $this->execAtLast($this->_activateLink($target, $property, $href)); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | /** |
@@ -816,14 +816,14 @@ discard block |
||
816 | 816 | * the active href (if null, window.location.href is used) |
817 | 817 | * @return string |
818 | 818 | */ |
819 | - public function _activateLink($target, $property = 'href', $href = null) { |
|
820 | - $js = '$("' . $target . ' [' . $property . ']").removeClass("active");'; |
|
821 | - if (isset ( $href )) { |
|
822 | - $js .= 'var href="' . $href . '";'; |
|
819 | + public function _activateLink($target, $property='href', $href=null) { |
|
820 | + $js='$("'.$target.' ['.$property.']").removeClass("active");'; |
|
821 | + if (isset ($href)) { |
|
822 | + $js.='var href="'.$href.'";'; |
|
823 | 823 | } else { |
824 | - $js .= 'var href=window.location.href;'; |
|
824 | + $js.='var href=window.location.href;'; |
|
825 | 825 | } |
826 | - $js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});'; |
|
826 | + $js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});'; |
|
827 | 827 | return $js; |
828 | 828 | } |
829 | 829 | } |
@@ -34,8 +34,9 @@ discard block |
||
34 | 34 | $callback = ", function(){\n{$callback}\n}"; |
35 | 35 | } |
36 | 36 | $str = "$({$element}).{$action}({$speed}{$callback});"; |
37 | - if ($immediatly) |
|
38 | - $this->jquery_code_for_compile [] = $str; |
|
37 | + if ($immediatly) { |
|
38 | + $this->jquery_code_for_compile [] = $str; |
|
39 | + } |
|
39 | 40 | return $str; |
40 | 41 | } |
41 | 42 | |
@@ -73,10 +74,12 @@ discard block |
||
73 | 74 | if (isset ( $param )) { |
74 | 75 | $param = Javascript::prep_value ( $param ); |
75 | 76 | $str = "$({$element}).{$jQueryCall}({$param});"; |
76 | - } else |
|
77 | - $str = "$({$element}).{$jQueryCall}();"; |
|
78 | - if ($immediatly) |
|
79 | - $this->jquery_code_for_compile [] = $str; |
|
77 | + } else { |
|
78 | + $str = "$({$element}).{$jQueryCall}();"; |
|
79 | + } |
|
80 | + if ($immediatly) { |
|
81 | + $this->jquery_code_for_compile [] = $str; |
|
82 | + } |
|
80 | 83 | return $str; |
81 | 84 | } |
82 | 85 | |
@@ -94,8 +97,9 @@ discard block |
||
94 | 97 | $to = Javascript::prep_element ( $to ); |
95 | 98 | $element = Javascript::prep_element ( $element ); |
96 | 99 | $str = "$({$to}).{$jQueryCall}({$element});"; |
97 | - if ($immediatly) |
|
98 | - $this->jquery_code_for_compile [] = $str; |
|
100 | + if ($immediatly) { |
|
101 | + $this->jquery_code_for_compile [] = $str; |
|
102 | + } |
|
99 | 103 | return $str; |
100 | 104 | } |
101 | 105 | |
@@ -153,10 +157,12 @@ discard block |
||
153 | 157 | if (isset ( $value )) { |
154 | 158 | $value = Javascript::prep_value ( $value ); |
155 | 159 | $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
156 | - } else |
|
157 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
158 | - if ($immediatly) |
|
159 | - $this->jquery_code_for_compile [] = $str; |
|
160 | + } else { |
|
161 | + $str = "$({$element}).attr(\"$attributeName\");"; |
|
162 | + } |
|
163 | + if ($immediatly) { |
|
164 | + $this->jquery_code_for_compile [] = $str; |
|
165 | + } |
|
160 | 166 | return $str; |
161 | 167 | } |
162 | 168 | |
@@ -219,8 +225,9 @@ discard block |
||
219 | 225 | |
220 | 226 | $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
221 | 227 | |
222 | - if ($immediatly) |
|
223 | - $this->jquery_code_for_compile [] = $str; |
|
228 | + if ($immediatly) { |
|
229 | + $this->jquery_code_for_compile [] = $str; |
|
230 | + } |
|
224 | 231 | return $str; |
225 | 232 | } |
226 | 233 | |
@@ -410,8 +417,9 @@ discard block |
||
410 | 417 | $element = Javascript::prep_element ( $element ); |
411 | 418 | $str = "$({$element}).trigger(\"$event\");"; |
412 | 419 | |
413 | - if ($immediatly) |
|
414 | - $this->jquery_code_for_compile [] = $str; |
|
420 | + if ($immediatly) { |
|
421 | + $this->jquery_code_for_compile [] = $str; |
|
422 | + } |
|
415 | 423 | return $str; |
416 | 424 | } |
417 | 425 | |
@@ -481,8 +489,9 @@ discard block |
||
481 | 489 | $str .= "else{" . $jsCodeIfFalse . "}"; |
482 | 490 | } |
483 | 491 | |
484 | - if ($immediatly) |
|
485 | - $this->jquery_code_for_compile [] = $str; |
|
492 | + if ($immediatly) { |
|
493 | + $this->jquery_code_for_compile [] = $str; |
|
494 | + } |
|
486 | 495 | return $str; |
487 | 496 | } |
488 | 497 | |
@@ -500,11 +509,13 @@ discard block |
||
500 | 509 | private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
501 | 510 | $param = Javascript::prep_value ( $param ); |
502 | 511 | $callback = ""; |
503 | - if ($jsCallback != "") |
|
504 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
512 | + if ($jsCallback != "") { |
|
513 | + $callback = ", function(event){\n{$jsCallback}\n}"; |
|
514 | + } |
|
505 | 515 | $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
506 | - if ($immediatly) |
|
507 | - $this->jquery_code_for_compile [] = $script; |
|
516 | + if ($immediatly) { |
|
517 | + $this->jquery_code_for_compile [] = $script; |
|
518 | + } |
|
508 | 519 | return $script; |
509 | 520 | } |
510 | 521 | |
@@ -591,8 +602,9 @@ discard block |
||
591 | 602 | */ |
592 | 603 | public function exec($js, $immediatly = false) { |
593 | 604 | $script = $js . "\n"; |
594 | - if ($immediatly) |
|
595 | - $this->jquery_code_for_compile [] = $script; |
|
605 | + if ($immediatly) { |
|
606 | + $this->jquery_code_for_compile [] = $script; |
|
607 | + } |
|
596 | 608 | return $script; |
597 | 609 | } |
598 | 610 |