@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | trait JsUtilsActionsTrait { |
14 | 14 | |
15 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
15 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * show or hide with effect |
@@ -28,15 +28,15 @@ discard block |
||
28 | 28 | * defers the execution if set to false |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
32 | - $element = Javascript::prep_element ( $element ); |
|
33 | - $speed = $this->_validate_speed ( $speed ); |
|
34 | - if ($callback != '') { |
|
35 | - $callback = ", function(){\n{$callback}\n}"; |
|
31 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
32 | + $element=Javascript::prep_element($element); |
|
33 | + $speed=$this->_validate_speed($speed); |
|
34 | + if ($callback!='') { |
|
35 | + $callback=", function(){\n{$callback}\n}"; |
|
36 | 36 | } |
37 | - $str = "$({$element}).{$action}({$speed}{$callback});"; |
|
37 | + $str="$({$element}).{$action}({$speed}{$callback});"; |
|
38 | 38 | if ($immediatly) |
39 | - $this->jquery_code_for_compile [] = $str; |
|
39 | + $this->jquery_code_for_compile []=$str; |
|
40 | 40 | return $str; |
41 | 41 | } |
42 | 42 | |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | * @return string |
48 | 48 | */ |
49 | 49 | private function _validate_speed($speed) { |
50 | - if (in_array ( $speed, array ( |
|
50 | + if (in_array($speed, array( |
|
51 | 51 | 'slow', |
52 | 52 | 'normal', |
53 | 53 | 'fast' |
54 | - ) )) { |
|
55 | - $speed = '"' . $speed . '"'; |
|
56 | - } elseif (preg_match ( "/[^0-9]/", $speed )) { |
|
57 | - $speed = ''; |
|
54 | + ))) { |
|
55 | + $speed='"'.$speed.'"'; |
|
56 | + } elseif (preg_match("/[^0-9]/", $speed)) { |
|
57 | + $speed=''; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return $speed; |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | * @param boolean $immediatly |
70 | 70 | * delayed if false |
71 | 71 | */ |
72 | - public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) { |
|
73 | - $element = Javascript::prep_element ( $element ); |
|
74 | - if (isset ( $param )) { |
|
75 | - $param = Javascript::prep_value ( $param ); |
|
76 | - $str = "$({$element}).{$jQueryCall}({$param});"; |
|
72 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
73 | + $element=Javascript::prep_element($element); |
|
74 | + if (isset ($param)) { |
|
75 | + $param=Javascript::prep_value($param); |
|
76 | + $str="$({$element}).{$jQueryCall}({$param});"; |
|
77 | 77 | } else |
78 | - $str = "$({$element}).{$jQueryCall}();"; |
|
78 | + $str="$({$element}).{$jQueryCall}();"; |
|
79 | 79 | if ($immediatly) |
80 | - $this->jquery_code_for_compile [] = $str; |
|
80 | + $this->jquery_code_for_compile []=$str; |
|
81 | 81 | return $str; |
82 | 82 | } |
83 | 83 | |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | * delayed if false |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) { |
|
95 | - $to = Javascript::prep_element ( $to ); |
|
96 | - $element = Javascript::prep_element ( $element ); |
|
97 | - $str = "$({$to}).{$jQueryCall}({$element});"; |
|
94 | + public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) { |
|
95 | + $to=Javascript::prep_element($to); |
|
96 | + $element=Javascript::prep_element($element); |
|
97 | + $str="$({$to}).{$jQueryCall}({$element});"; |
|
98 | 98 | if ($immediatly) |
99 | - $this->jquery_code_for_compile [] = $str; |
|
99 | + $this->jquery_code_for_compile []=$str; |
|
100 | 100 | return $str; |
101 | 101 | } |
102 | 102 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * defers the execution if set to false |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function addClass($element = 'this', $class = '', $immediatly = false) { |
|
114 | - return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly ); |
|
113 | + public function addClass($element='this', $class='', $immediatly=false) { |
|
114 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * defers the execution if set to false |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - public function after($to, $element, $immediatly = false) { |
|
127 | - return $this->_genericCallElement ( 'after', $to, $element, $immediatly ); |
|
126 | + public function after($to, $element, $immediatly=false) { |
|
127 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * defers the execution if set to false |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - public function before($to, $element, $immediatly = false) { |
|
140 | - return $this->_genericCallElement ( 'before', $to, $element, $immediatly ); |
|
139 | + public function before($to, $element, $immediatly=false) { |
|
140 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | * @param boolean $immediatly |
150 | 150 | * delayed if false |
151 | 151 | */ |
152 | - public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) { |
|
153 | - $element = Javascript::prep_element ( $element ); |
|
154 | - if (isset ( $value )) { |
|
155 | - $value = Javascript::prep_value ( $value ); |
|
156 | - $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
|
152 | + public function attr($element='this', $attributeName='id', $value="", $immediatly=false) { |
|
153 | + $element=Javascript::prep_element($element); |
|
154 | + if (isset ($value)) { |
|
155 | + $value=Javascript::prep_value($value); |
|
156 | + $str="$({$element}).attr(\"$attributeName\",{$value});"; |
|
157 | 157 | } else |
158 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
158 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
159 | 159 | if ($immediatly) |
160 | - $this->jquery_code_for_compile [] = $str; |
|
160 | + $this->jquery_code_for_compile []=$str; |
|
161 | 161 | return $str; |
162 | 162 | } |
163 | 163 | |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @param boolean $immediatly |
170 | 170 | * defers the execution if set to false |
171 | 171 | */ |
172 | - public function val($element = 'this', $value = '', $immediatly = false) { |
|
173 | - return $this->_genericCallValue ( 'val', $element, $value, $immediatly ); |
|
172 | + public function val($element='this', $value='', $immediatly=false) { |
|
173 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param boolean $immediatly |
182 | 182 | * defers the execution if set to false |
183 | 183 | */ |
184 | - public function html($element = 'this', $value = '', $immediatly = false) { |
|
185 | - return $this->_genericCallValue ( 'html', $element, $value, $immediatly ); |
|
184 | + public function html($element='this', $value='', $immediatly=false) { |
|
185 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -198,30 +198,30 @@ discard block |
||
198 | 198 | * defers the execution if set to false |
199 | 199 | * @return string |
200 | 200 | */ |
201 | - public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) { |
|
202 | - $element = Javascript::prep_element ( $element ); |
|
203 | - $speed = $this->_validate_speed ( $speed ); |
|
201 | + public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
|
202 | + $element=Javascript::prep_element($element); |
|
203 | + $speed=$this->_validate_speed($speed); |
|
204 | 204 | |
205 | - $animations = "\t\t\t"; |
|
206 | - if (\is_array ( $params )) { |
|
207 | - foreach ( $params as $param => $value ) { |
|
208 | - $animations .= $param . ': \'' . $value . '\', '; |
|
205 | + $animations="\t\t\t"; |
|
206 | + if (\is_array ($params)) { |
|
207 | + foreach ($params as $param => $value) { |
|
208 | + $animations.=$param.': \''.$value.'\', '; |
|
209 | 209 | } |
210 | 210 | } |
211 | - $animations = substr ( $animations, 0, - 2 ); // remove the last ", " |
|
211 | + $animations=substr($animations, 0, - 2); // remove the last ", " |
|
212 | 212 | |
213 | - if ($speed != '') { |
|
214 | - $speed = ', ' . $speed; |
|
213 | + if ($speed!='') { |
|
214 | + $speed=', '.$speed; |
|
215 | 215 | } |
216 | 216 | |
217 | - if ($extra != '') { |
|
218 | - $extra = ', ' . $extra; |
|
217 | + if ($extra!='') { |
|
218 | + $extra=', '.$extra; |
|
219 | 219 | } |
220 | 220 | |
221 | - $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
|
221 | + $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
|
222 | 222 | |
223 | 223 | if ($immediatly) |
224 | - $this->jquery_code_for_compile [] = $str; |
|
224 | + $this->jquery_code_for_compile []=$str; |
|
225 | 225 | return $str; |
226 | 226 | } |
227 | 227 | |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | * defers the execution if set to false |
235 | 235 | * @return string |
236 | 236 | */ |
237 | - public function append($to, $element, $immediatly = false) { |
|
238 | - return $this->_genericCallElement ( 'append', $to, $element, $immediatly ); |
|
237 | + public function append($to, $element, $immediatly=false) { |
|
238 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * defers the execution if set to false |
248 | 248 | * @return string |
249 | 249 | */ |
250 | - public function prepend($to, $element, $immediatly = false) { |
|
251 | - return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly ); |
|
250 | + public function prepend($to, $element, $immediatly=false) { |
|
251 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | * defers the execution if set to false |
265 | 265 | * @return string |
266 | 266 | */ |
267 | - public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
268 | - return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly ); |
|
267 | + public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
268 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * defers the execution if set to false |
282 | 282 | * @return string |
283 | 283 | */ |
284 | - public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
285 | - return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly ); |
|
284 | + public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
285 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | * defers the execution if set to false |
299 | 299 | * @return string |
300 | 300 | */ |
301 | - public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
302 | - return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly ); |
|
301 | + public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
302 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | * defers the execution if set to false |
314 | 314 | * @return string |
315 | 315 | */ |
316 | - public function removeClass($element = 'this', $class = '', $immediatly = false) { |
|
317 | - return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly ); |
|
316 | + public function removeClass($element='this', $class='', $immediatly=false) { |
|
317 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | * defers the execution if set to false |
331 | 331 | * @return string |
332 | 332 | */ |
333 | - public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
334 | - return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly ); |
|
333 | + public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
334 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * defers the execution if set to false |
348 | 348 | * @return string |
349 | 349 | */ |
350 | - public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
351 | - return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly ); |
|
350 | + public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
351 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | * defers the execution if set to false |
365 | 365 | * @return string |
366 | 366 | */ |
367 | - public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
368 | - return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly ); |
|
367 | + public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
368 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | * defers the execution if set to false |
382 | 382 | * @return string |
383 | 383 | */ |
384 | - public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
385 | - return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly ); |
|
384 | + public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
385 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | * defers the execution if set to false |
396 | 396 | * @return string |
397 | 397 | */ |
398 | - public function toggleClass($element = 'this', $class = '', $immediatly = false) { |
|
399 | - return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly ); |
|
398 | + public function toggleClass($element='this', $class='', $immediatly=false) { |
|
399 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | * @param boolean $immediatly |
408 | 408 | * defers the execution if set to false |
409 | 409 | */ |
410 | - public function trigger($element = 'this', $event = 'click', $immediatly = false) { |
|
411 | - $element = Javascript::prep_element ( $element ); |
|
412 | - $str = "$({$element}).trigger(\"$event\");"; |
|
410 | + public function trigger($element='this', $event='click', $immediatly=false) { |
|
411 | + $element=Javascript::prep_element($element); |
|
412 | + $str="$({$element}).trigger(\"$event\");"; |
|
413 | 413 | |
414 | 414 | if ($immediatly) |
415 | - $this->jquery_code_for_compile [] = $str; |
|
415 | + $this->jquery_code_for_compile []=$str; |
|
416 | 416 | return $str; |
417 | 417 | } |
418 | 418 | |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * defers the execution if set to false |
430 | 430 | * @return string |
431 | 431 | */ |
432 | - public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
433 | - return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly ); |
|
432 | + public function show($element='this', $speed='', $callback='', $immediatly=false) { |
|
433 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,18 +440,18 @@ discard block |
||
440 | 440 | * @param array $options |
441 | 441 | * @return string |
442 | 442 | */ |
443 | - public function sortable($element, $options = array ()) { |
|
444 | - if (count ( $options ) > 0) { |
|
445 | - $sort_options = array (); |
|
446 | - foreach ( $options as $k => $v ) { |
|
447 | - $sort_options [] = "\n\t\t" . $k . ': ' . $v . ""; |
|
443 | + public function sortable($element, $options=array()) { |
|
444 | + if (count($options)>0) { |
|
445 | + $sort_options=array(); |
|
446 | + foreach ($options as $k => $v) { |
|
447 | + $sort_options []="\n\t\t".$k.': '.$v.""; |
|
448 | 448 | } |
449 | - $sort_options = implode ( ",", $sort_options ); |
|
449 | + $sort_options=implode(",", $sort_options); |
|
450 | 450 | } else { |
451 | - $sort_options = ''; |
|
451 | + $sort_options=''; |
|
452 | 452 | } |
453 | 453 | |
454 | - return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});"; |
|
454 | + return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});"; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | * plugin location |
464 | 464 | * @return string |
465 | 465 | */ |
466 | - public function tablesorter($table = '', $options = '') { |
|
467 | - $this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n"; |
|
466 | + public function tablesorter($table='', $options='') { |
|
467 | + $this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n"; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -476,14 +476,14 @@ discard block |
||
476 | 476 | * @param boolean $immediatly |
477 | 477 | * defers the execution if set to false |
478 | 478 | */ |
479 | - public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) { |
|
480 | - $str = "if(" . $condition . "){" . $jsCodeIfTrue . "}"; |
|
481 | - if (isset ( $jsCodeIfFalse )) { |
|
482 | - $str .= "else{" . $jsCodeIfFalse . "}"; |
|
479 | + public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
|
480 | + $str="if(".$condition."){".$jsCodeIfTrue."}"; |
|
481 | + if (isset ($jsCodeIfFalse)) { |
|
482 | + $str.="else{".$jsCodeIfFalse."}"; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | if ($immediatly) |
486 | - $this->jquery_code_for_compile [] = $str; |
|
486 | + $this->jquery_code_for_compile []=$str; |
|
487 | 487 | return $str; |
488 | 488 | } |
489 | 489 | |
@@ -498,14 +498,14 @@ discard block |
||
498 | 498 | * @param boolean $immediatly |
499 | 499 | * @return string |
500 | 500 | */ |
501 | - private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
|
502 | - $param = Javascript::prep_value ( $param ); |
|
503 | - $callback = ""; |
|
504 | - if ($jsCallback != "") |
|
505 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
506 | - $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
|
501 | + private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
|
502 | + $param=Javascript::prep_value($param); |
|
503 | + $callback=""; |
|
504 | + if ($jsCallback!="") |
|
505 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
506 | + $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
|
507 | 507 | if ($immediatly) |
508 | - $this->jquery_code_for_compile [] = $script; |
|
508 | + $this->jquery_code_for_compile []=$script; |
|
509 | 509 | return $script; |
510 | 510 | } |
511 | 511 | |
@@ -522,8 +522,8 @@ discard block |
||
522 | 522 | * javascript code to execute after the jquery call |
523 | 523 | * @return mixed |
524 | 524 | */ |
525 | - public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
526 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true ); |
|
525 | + public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
|
526 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * javascript code to execute after the jquery call |
540 | 540 | * @return mixed |
541 | 541 | */ |
542 | - public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
543 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false ); |
|
542 | + public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
|
543 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -557,8 +557,8 @@ discard block |
||
557 | 557 | * @param boolean $immediatly |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) { |
|
561 | - return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
560 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
561 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /** |
@@ -572,13 +572,13 @@ discard block |
||
572 | 572 | * @param array $parameters |
573 | 573 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
574 | 574 | */ |
575 | - public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) { |
|
576 | - $jsCallback = ""; |
|
577 | - $stopPropagation = false; |
|
578 | - $preventDefault = false; |
|
579 | - $immediatly = true; |
|
580 | - extract ( $parameters ); |
|
581 | - return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly ); |
|
575 | + public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
576 | + $jsCallback=""; |
|
577 | + $stopPropagation=false; |
|
578 | + $preventDefault=false; |
|
579 | + $immediatly=true; |
|
580 | + extract($parameters); |
|
581 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | * delayed if false |
591 | 591 | * @return String |
592 | 592 | */ |
593 | - public function exec($js, $immediatly = false) { |
|
594 | - $script = $js . "\n"; |
|
593 | + public function exec($js, $immediatly=false) { |
|
594 | + $script=$js."\n"; |
|
595 | 595 | if ($immediatly) |
596 | - $this->jquery_code_for_compile [] = $script; |
|
596 | + $this->jquery_code_for_compile []=$script; |
|
597 | 597 | return $script; |
598 | 598 | } |
599 | 599 | |
@@ -607,8 +607,8 @@ discard block |
||
607 | 607 | * @return String |
608 | 608 | */ |
609 | 609 | public function execAtLast($js) { |
610 | - $script = $js . "\n"; |
|
611 | - $this->jquery_code_for_compile_at_last [] = $script; |
|
610 | + $script=$js."\n"; |
|
611 | + $this->jquery_code_for_compile_at_last []=$script; |
|
612 | 612 | return $script; |
613 | 613 | } |
614 | 614 | |
@@ -623,18 +623,18 @@ discard block |
||
623 | 623 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
624 | 624 | * @return String |
625 | 625 | */ |
626 | - public function execOn($event, $element, $js, $parameters = array ()) { |
|
627 | - $stopPropagation = false; |
|
628 | - $preventDefault = false; |
|
629 | - $immediatly = true; |
|
630 | - extract ( $parameters ); |
|
631 | - $script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
626 | + public function execOn($event, $element, $js, $parameters=array()) { |
|
627 | + $stopPropagation=false; |
|
628 | + $preventDefault=false; |
|
629 | + $immediatly=true; |
|
630 | + extract($parameters); |
|
631 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
632 | 632 | return $script; |
633 | 633 | } |
634 | - public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) { |
|
635 | - $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"; |
|
636 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
637 | - return $this->exec ( $retour, $immediatly ); |
|
634 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
635 | + $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"; |
|
636 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
637 | + return $this->exec($retour, $immediatly); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
@@ -645,13 +645,13 @@ discard block |
||
645 | 645 | * @param array $parameters |
646 | 646 | * default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
647 | 647 | */ |
648 | - public function setDraggable($element, $parameters = [ ]) { |
|
649 | - $attr = "id"; |
|
650 | - $preventDefault = false; |
|
651 | - $stopPropagation = false; |
|
652 | - $immediatly = true; |
|
653 | - extract ( $parameters ); |
|
654 | - $script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly ); |
|
648 | + public function setDraggable($element, $parameters=[]) { |
|
649 | + $attr="id"; |
|
650 | + $preventDefault=false; |
|
651 | + $stopPropagation=false; |
|
652 | + $immediatly=true; |
|
653 | + extract($parameters); |
|
654 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly); |
|
655 | 655 | return $script; |
656 | 656 | } |
657 | 657 | |
@@ -665,13 +665,13 @@ discard block |
||
665 | 665 | * @param string $jsCallback |
666 | 666 | * the js script to call when element is dropped |
667 | 667 | */ |
668 | - public function asDropZone($element, $jsCallback = "", $parameters = [ ]) { |
|
669 | - $stopPropagation = false; |
|
670 | - $immediatly = true; |
|
671 | - $jqueryDone = "append"; |
|
672 | - $script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly ); |
|
673 | - extract ( $parameters ); |
|
674 | - $script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly ); |
|
668 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
669 | + $stopPropagation=false; |
|
670 | + $immediatly=true; |
|
671 | + $jqueryDone="append"; |
|
672 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
673 | + extract($parameters); |
|
674 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
675 | 675 | return $script; |
676 | 676 | } |
677 | 677 | |
@@ -688,16 +688,16 @@ discard block |
||
688 | 688 | * delayed if false |
689 | 689 | * @return string |
690 | 690 | */ |
691 | - public function interval($jsCode, $time, $globalName = null, $immediatly = true) { |
|
692 | - if (! Javascript::isFunction ( $jsCode )) { |
|
693 | - $jsCode = "function(){\n" . $jsCode . "\n}"; |
|
691 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
692 | + if (!Javascript::isFunction($jsCode)) { |
|
693 | + $jsCode="function(){\n".$jsCode."\n}"; |
|
694 | 694 | } |
695 | - if (isset ( $globalName )) { |
|
696 | - $script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
695 | + if (isset ($globalName)) { |
|
696 | + $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
697 | 697 | } else { |
698 | - $script = "setInterval({$jsCode},{$time});"; |
|
698 | + $script="setInterval({$jsCode},{$time});"; |
|
699 | 699 | } |
700 | - return $this->exec ( $script, $immediatly ); |
|
700 | + return $this->exec($script, $immediatly); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
@@ -709,8 +709,8 @@ discard block |
||
709 | 709 | * delayed if false |
710 | 710 | * @return string |
711 | 711 | */ |
712 | - public function clearInterval($globalName, $immediatly = true) { |
|
713 | - return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly ); |
|
712 | + public function clearInterval($globalName, $immediatly=true) { |
|
713 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
@@ -731,20 +731,20 @@ discard block |
||
731 | 731 | * delayed if false |
732 | 732 | * @return string |
733 | 733 | */ |
734 | - public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) { |
|
735 | - $stop = ""; |
|
734 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
735 | + $stop=""; |
|
736 | 736 | if ($countDown) { |
737 | - $stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
737 | + $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
738 | 738 | } else { |
739 | - if ($limit != 0) { |
|
740 | - $stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
739 | + if ($limit!=0) { |
|
740 | + $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
741 | 741 | } |
742 | 742 | } |
743 | - $global = ""; |
|
744 | - if (isset ( $globalName )) { |
|
745 | - $global = "\nwindow.{$globalName}=interval;"; |
|
743 | + $global=""; |
|
744 | + if (isset ($globalName)) { |
|
745 | + $global="\nwindow.{$globalName}=interval;"; |
|
746 | 746 | } |
747 | - $timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
747 | + $timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
748 | 748 | var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};}; |
749 | 749 | 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);}}; |
750 | 750 | var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';}; |
@@ -760,12 +760,12 @@ discard block |
||
760 | 760 | minutes = d0(parseInt((timer%3600) / 60, 10)); |
761 | 761 | seconds = d0(parseInt(timer%60, 10)); |
762 | 762 | mainSh(days,hours,minutes,seconds); |
763 | - " . $stop . " |
|
763 | + " . $stop." |
|
764 | 764 | }, 1000); |
765 | - " . $global . " |
|
765 | + " . $global." |
|
766 | 766 | }"; |
767 | - $element = '$("' . $counterSelector . '")'; |
|
768 | - return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly ); |
|
767 | + $element='$("'.$counterSelector.'")'; |
|
768 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -787,8 +787,8 @@ discard block |
||
787 | 787 | * count down if true or elapse if false |
788 | 788 | * @return string |
789 | 789 | */ |
790 | - public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) { |
|
791 | - return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) ); |
|
790 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
791 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
@@ -802,8 +802,8 @@ discard block |
||
802 | 802 | * the active href (if null, window.location.href is used) |
803 | 803 | * @return string |
804 | 804 | */ |
805 | - public function activateLink($target, $property = 'href', $href = null) { |
|
806 | - return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) ); |
|
805 | + public function activateLink($target, $property='href', $href=null) { |
|
806 | + return $this->execAtLast($this->_activateLink($target, $property, $href)); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -817,14 +817,14 @@ discard block |
||
817 | 817 | * the active href (if null, window.location.href is used) |
818 | 818 | * @return string |
819 | 819 | */ |
820 | - public function _activateLink($target, $property = 'href', $href = null) { |
|
821 | - $js = '$("' . $target . ' [' . $property . ']").removeClass("active");'; |
|
822 | - if (isset ( $href )) { |
|
823 | - $js .= 'var href="' . $href . '";'; |
|
820 | + public function _activateLink($target, $property='href', $href=null) { |
|
821 | + $js='$("'.$target.' ['.$property.']").removeClass("active");'; |
|
822 | + if (isset ($href)) { |
|
823 | + $js.='var href="'.$href.'";'; |
|
824 | 824 | } else { |
825 | - $js .= 'var href=window.location.href;'; |
|
825 | + $js.='var href=window.location.href;'; |
|
826 | 826 | } |
827 | - $js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});'; |
|
827 | + $js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});'; |
|
828 | 828 | return $js; |
829 | 829 | } |
830 | 830 | } |