6
6
7
7
/**
8
8
* @author jc
9
- * @property Ajax\JsUtils $js
9
+ * @property array $jquery_code_for_compile
10
10
*/
11
11
trait JsUtilsActionsTrait {
12
12
13
-
13
+ abstract public function _add_event ($ element , $ js , $ event , $ preventDefault =false , $ stopPropagation =false ,$ immediatly =true );
14
+ /**
15
+ * show or hide with effect
16
+ *
17
+ * @param string $action
18
+ * @param string - element
19
+ * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
20
+ * @param string - Javascript callback function
21
+ * @param boolean $immediatly defers the execution if set to false
22
+ * @return string
23
+ */
24
+ protected function _showHideWithEffect ($ action ,$ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
25
+ $ element =Javascript::prep_element ($ element );
26
+ $ speed =$ this ->_validate_speed ($ speed );
27
+ if ($ callback !='' ) {
28
+ $ callback =", function(){ \n{$ callback }\n} " ;
29
+ }
30
+ $ str ="$( {$ element }). {$ action }( {$ speed }{$ callback }); " ;
31
+ if ($ immediatly )
32
+ $ this ->jquery_code_for_compile []=$ str ;
33
+ return $ str ;
34
+ }
14
35
/**
15
36
* Ensures the speed parameter is valid for jQuery
16
37
* @param string|int $speed
@@ -205,18 +226,7 @@ public function prepend($to, $element, $immediatly=false) {
205
226
* @return string
206
227
*/
207
228
public function fadeIn ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
208
- $ element =Javascript::prep_element ($ element );
209
- $ speed =$ this ->_validate_speed ($ speed );
210
-
211
- if ($ callback !='' ) {
212
- $ callback =", function(){ \n{$ callback }\n} " ;
213
- }
214
-
215
- $ str ="$( {$ element }).fadeIn( {$ speed }{$ callback }); " ;
216
-
217
- if ($ immediatly )
218
- $ this ->jquery_code_for_compile []=$ str ;
219
- return $ str ;
229
+ return $ this ->_showHideWithEffect ("fadeIn " ,$ element ,$ speed ,$ callback ,$ immediatly );
220
230
}
221
231
222
232
/**
@@ -229,18 +239,7 @@ public function fadeIn($element='this', $speed='', $callback='', $immediatly=fal
229
239
* @return string
230
240
*/
231
241
public function fadeOut ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
232
- $ element =Javascript::prep_element ($ element );
233
- $ speed =$ this ->_validate_speed ($ speed );
234
-
235
- if ($ callback !='' ) {
236
- $ callback =", function(){ \n{$ callback }\n} " ;
237
- }
238
-
239
- $ str ="$( {$ element }).fadeOut( {$ speed }{$ callback }); " ;
240
-
241
- if ($ immediatly )
242
- $ this ->jquery_code_for_compile []=$ str ;
243
- return $ str ;
242
+ return $ this ->_showHideWithEffect ("fadeOut " ,$ element ,$ speed ,$ callback ,$ immediatly );
244
243
}
245
244
246
245
/**
@@ -253,18 +252,7 @@ public function fadeOut($element='this', $speed='', $callback='', $immediatly=fa
253
252
* @return string
254
253
*/
255
254
public function slideUp ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
256
- $ element =Javascript::prep_element ($ element );
257
- $ speed =$ this ->_validate_speed ($ speed );
258
-
259
- if ($ callback !='' ) {
260
- $ callback =", function(){ \n{$ callback }\n} " ;
261
- }
262
-
263
- $ str ="$( {$ element }).slideUp( {$ speed }{$ callback }); " ;
264
-
265
- if ($ immediatly )
266
- $ this ->jquery_code_for_compile []=$ str ;
267
- return $ str ;
255
+ return $ this ->_showHideWithEffect ("slideUp " ,$ element ,$ speed ,$ callback ,$ immediatly );
268
256
}
269
257
270
258
/**
@@ -289,18 +277,7 @@ public function removeClass($element='this', $class='', $immediatly=false) {
289
277
* @return string
290
278
*/
291
279
public function slideDown ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
292
- $ element =Javascript::prep_element ($ element );
293
- $ speed =$ this ->_validate_speed ($ speed );
294
-
295
- if ($ callback !='' ) {
296
- $ callback =", function(){ \n{$ callback }\n} " ;
297
- }
298
-
299
- $ str ="$( {$ element }).slideDown( {$ speed }{$ callback }); " ;
300
-
301
- if ($ immediatly )
302
- $ this ->jquery_code_for_compile []=$ str ;
303
- return $ str ;
280
+ return $ this ->_showHideWithEffect ("slideDown " ,$ element ,$ speed ,$ callback ,$ immediatly );
304
281
}
305
282
306
283
/**
@@ -313,18 +290,7 @@ public function slideDown($element='this', $speed='', $callback='', $immediatly=
313
290
* @return string
314
291
*/
315
292
public function slideToggle ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
316
- $ element =Javascript::prep_element ($ element );
317
- $ speed =$ this ->_validate_speed ($ speed );
318
-
319
- if ($ callback !='' ) {
320
- $ callback =", function(){ \n{$ callback }\n} " ;
321
- }
322
-
323
- $ str ="$( {$ element }).slideToggle( {$ speed }{$ callback }); " ;
324
-
325
- if ($ immediatly )
326
- $ this ->jquery_code_for_compile []=$ str ;
327
- return $ str ;
293
+ return $ this ->_showHideWithEffect ("slideToggle " ,$ element ,$ speed ,$ callback ,$ immediatly );
328
294
}
329
295
330
296
/**
@@ -337,34 +303,20 @@ public function slideToggle($element='this', $speed='', $callback='', $immediatl
337
303
* @return string
338
304
*/
339
305
public function hide ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
340
- $ element =Javascript::prep_element ($ element );
341
- $ speed =$ this ->_validate_speed ($ speed );
342
-
343
- if ($ callback !='' ) {
344
- $ callback =", function(){ \n{$ callback }\n} " ;
345
- }
346
-
347
- $ str ="$( {$ element }).hide( {$ speed }{$ callback }); " ;
348
-
349
- if ($ immediatly )
350
- $ this ->jquery_code_for_compile []=$ str ;
351
- return $ str ;
306
+ return $ this ->_showHideWithEffect ("hide " ,$ element ,$ speed ,$ callback ,$ immediatly );
352
307
}
353
308
354
309
/**
355
310
* Execute a javascript library toggle action
356
311
*
357
312
* @param string - element
313
+ * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
314
+ * @param string - Javascript callback function
358
315
* @param boolean $immediatly defers the execution if set to false
359
316
* @return string
360
317
*/
361
- public function toggle ($ element ='this ' , $ immediatly =false ) {
362
- $ element =Javascript::prep_element ($ element );
363
- $ str ="$( {$ element }).toggle(); " ;
364
-
365
- if ($ immediatly )
366
- $ this ->jquery_code_for_compile []=$ str ;
367
- return $ str ;
318
+ public function toggle ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
319
+ return $ this ->_showHideWithEffect ("toggle " ,$ element ,$ speed ,$ callback ,$ immediatly );
368
320
}
369
321
370
322
/**
@@ -403,18 +355,7 @@ public function trigger($element='this', $event='click', $immediatly=false) {
403
355
* @return string
404
356
*/
405
357
public function show ($ element ='this ' , $ speed ='' , $ callback ='' , $ immediatly =false ) {
406
- $ element =Javascript::prep_element ($ element );
407
- $ speed =$ this ->_validate_speed ($ speed );
408
-
409
- if ($ callback !='' ) {
410
- $ callback =", function(){ \n{$ callback }\n} " ;
411
- }
412
-
413
- $ str ="$( {$ element }).show( {$ speed }{$ callback }); " ;
414
-
415
- if ($ immediatly )
416
- $ this ->jquery_code_for_compile []=$ str ;
417
- return $ str ;
358
+ return $ this ->_showHideWithEffect ("show " ,$ element ,$ speed ,$ callback ,$ immediatly );
418
359
}
419
360
420
361
/**
0 commit comments