Completed
Push — master ( 2b1feb...63bca8 )
by Jean-Christophe
03:46
created

JsUtilsActionsTrait::toggle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace Ajax\common\traits;
4
5
use Ajax\service\Javascript;
6
7
/**
8
 * @author jc
9
 * @property Ajax\JsUtils $js
10
 */
11
trait JsUtilsActionsTrait {
12
13
14
	/**
15
	 * Ensures the speed parameter is valid for jQuery
16
	 * @param string|int $speed
17
	 * @return string
18
	 */
19
	private function _validate_speed($speed) {
20
		if (in_array($speed, array (
21
				'slow','normal','fast'
22
		))) {
23
			$speed='"'.$speed.'"';
24
		} elseif (preg_match("/[^0-9]/", $speed)) {
25
			$speed='';
26
		}
27
28
		return $speed;
29
	}
30
31
	/**
32
	 * Execute a generic jQuery call with a value.
33
	 * @param string $jQueryCall
34
	 * @param string $element
35
	 * @param string $param
36
	 * @param boolean $immediatly delayed if false
37
	 */
38 View Code Duplication
	public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
		$element=Javascript::prep_element($element);
40
		if (isset($param)) {
41
			$param=Javascript::prep_value($param);
42
			$str="$({$element}).{$jQueryCall}({$param});";
43
		} else
44
			$str="$({$element}).{$jQueryCall}();";
45
		if ($immediatly)
46
			$this->jquery_code_for_compile[]=$str;
0 ignored issues
show
Bug introduced by
The property jquery_code_for_compile does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
47
		return $str;
48
	}
49
50
	/**
51
	 * Execute a generic jQuery call with 2 elements.
52
	 * @param string $jQueryCall
53
	 * @param string $to
54
	 * @param string $element
55
	 * @param boolean $immediatly delayed if false
56
	 * @return string
57
	 */
58
	public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) {
59
		$to=Javascript::prep_element($to);
60
		$element=Javascript::prep_element($element);
61
		$str="$({$to}).{$jQueryCall}({$element});";
62
		if ($immediatly)
63
			$this->jquery_code_for_compile[]=$str;
64
		return $str;
65
	}
66
	/**
67
	 * add class to element
68
	 *
69
	 * @param string $element
70
	 * @param string $class to add
71
	 * @param boolean $immediatly defers the execution if set to false
72
	 * @return string
73
	 */
74
	public function addClass($element='this', $class='', $immediatly=false) {
75
		return $this->_genericCallValue('addClass',$element, $class, $immediatly);
76
	}
77
78
	/**
79
	 * Insert content, specified by the parameter, after each element in the set of matched elements
80
	 * @param string $to
81
	 * @param string $element
82
	 * @param boolean $immediatly defers the execution if set to false
83
	 * @return string
84
	 */
85
	public function after($to, $element, $immediatly=false){
86
		return $this->_genericCallElement('after',$to, $element, $immediatly);
87
	}
88
89
	/**
90
	 * Insert content, specified by the parameter, before each element in the set of matched elements
91
	 * @param string $to
92
	 * @param string $element
93
	 * @param boolean $immediatly defers the execution if set to false
94
	 * @return string
95
	 */
96
	public function before($to, $element, $immediatly=false){
97
		return $this->_genericCallElement('before',$to, $element, $immediatly);
98
	}
99
100
	/**
101
	 * Get or set the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.
102
	 * @param string $element
103
	 * @param string $attributeName
104
	 * @param string $value
105
	 * @param boolean $immediatly delayed if false
106
	 */
107 View Code Duplication
	public function attr($element='this', $attributeName, $value="", $immediatly=false) {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
		$element=Javascript::prep_element($element);
109
		if (isset($value)) {
110
			$value=Javascript::prep_value($value);
111
			$str="$({$element}).attr(\"$attributeName\",{$value});";
112
		} else
113
			$str="$({$element}).attr(\"$attributeName\");";
114
		if ($immediatly)
115
			$this->jquery_code_for_compile[]=$str;
116
		return $str;
117
	}
118
119
	/**
120
	 * Get or set the value of the first element in the set of matched elements or set one or more attributes for every matched element.
121
	 * @param string $element
122
	 * @param string $value
123
	 * @param boolean $immediatly defers the execution if set to false
124
	 */
125
	public function val($element='this',$value='',$immediatly=false){
126
		return $this->_genericCallValue('val',$element,$value,$immediatly);
127
	}
128
129
	/**
130
	 * Get or set the html of an attribute for the first element in the set of matched elements.
131
	 * @param string $element
132
	 * @param string $value
133
	 * @param boolean $immediatly defers the execution if set to false
134
	 */
135
	public function html($element='this', $value='', $immediatly=false) {
136
		return $this->_genericCallValue('html',$element, $value, $immediatly);
137
	}
138
139
	/**
140
	 * Outputs a javascript library animate event
141
	 *
142
	 * @param string $element element
143
	 * @param array $params
144
	 * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds
145
	 * @param string $extra
146
	 * @param boolean $immediatly defers the execution if set to false
147
	 * @return string
148
	 */
149
	public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) {
150
		$element=Javascript::prep_element($element);
151
		$speed=$this->_validate_speed($speed);
152
153
		$animations="\t\t\t";
154
		if (\is_array($params)) {
155
			foreach ( $params as $param => $value ) {
156
				$animations.=$param.': \''.$value.'\', ';
157
			}
158
		}
159
		$animations=substr($animations, 0, -2); // remove the last ", "
160
161
		if ($speed!='') {
162
			$speed=', '.$speed;
163
		}
164
165
		if ($extra!='') {
166
			$extra=', '.$extra;
167
		}
168
169
		$str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
170
171
		if ($immediatly)
172
			$this->jquery_code_for_compile[]=$str;
173
		return $str;
174
	}
175
176
	/**
177
	 * Insert content, specified by the parameter $element, to the end of each element in the set of matched elements $to.
178
	 * @param string $to
179
	 * @param string $element
180
	 * @param boolean $immediatly defers the execution if set to false
181
	 * @return string
182
	 */
183
	public function append($to, $element, $immediatly=false) {
184
		return $this->_genericCallElement('append',$to, $element, $immediatly);
185
	}
186
187
	/**
188
	 * Insert content, specified by the parameter $element, to the beginning of each element in the set of matched elements $to.
189
	 * @param string $to
190
	 * @param string $element
191
	 * @param boolean $immediatly defers the execution if set to false
192
	 * @return string
193
	 */
194
	public function prepend($to, $element, $immediatly=false) {
195
		return $this->_genericCallElement('prepend',$to, $element, $immediatly);
196
	}
197
198
	/**
199
	 * Execute a javascript library hide action
200
	 *
201
	 * @param string - element
202
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
203
	 * @param string - Javascript callback function
204
	 * @param boolean $immediatly defers the execution if set to false
205
	 * @return string
206
	 */
207 View Code Duplication
	public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
220
	}
221
222
	/**
223
	 * Execute a javascript library hide action
224
	 *
225
	 * @param string - element
226
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
227
	 * @param string - Javascript callback function
228
	 * @param boolean $immediatly defers the execution if set to false
229
	 * @return string
230
	 */
231 View Code Duplication
	public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
244
	}
245
246
	/**
247
	 * Execute a javascript library slideUp action
248
	 *
249
	 * @param string - element
250
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
251
	 * @param string - Javascript callback function
252
	 * @param boolean $immediatly defers the execution if set to false
253
	 * @return string
254
	 */
255 View Code Duplication
	public function slideUp($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
268
	}
269
270
	/**
271
	 * Execute a javascript library removeClass action
272
	 *
273
	 * @param string - element
274
	 * @param string - Class to add
275
	 * @param boolean $immediatly defers the execution if set to false
276
	 * @return string
277
	 */
278
	public function removeClass($element='this', $class='', $immediatly=false) {
279
		return $this->_genericCall('removeClass',$element, $class, $immediatly);
0 ignored issues
show
Bug introduced by
The method _genericCall() does not exist on Ajax\common\traits\JsUtilsActionsTrait. Did you maybe mean _genericCallValue()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
280
	}
281
282
	/**
283
	 * Execute a javascript library slideDown action
284
	 *
285
	 * @param string - element
286
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
287
	 * @param string - Javascript callback function
288
	 * @param boolean $immediatly defers the execution if set to false
289
	 * @return string
290
	 */
291 View Code Duplication
	public function slideDown($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
304
	}
305
306
	/**
307
	 * Execute a javascript library slideToggle action
308
	 *
309
	 * @param string - element
310
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
311
	 * @param string - Javascript callback function
312
	 * @param boolean $immediatly defers the execution if set to false
313
	 * @return string
314
	 */
315 View Code Duplication
	public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
328
	}
329
330
	/**
331
	 * Execute a javascript library hide action
332
	 *
333
	 * @param string - element
334
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
335
	 * @param string - Javascript callback function
336
	 * @param boolean $immediatly defers the execution if set to false
337
	 * @return string
338
	 */
339 View Code Duplication
	public function hide($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
352
	}
353
354
	/**
355
	 * Execute a javascript library toggle action
356
	 *
357
	 * @param string - element
358
	 * @param boolean $immediatly defers the execution if set to false
359
	 * @return string
360
	 */
361 View Code Duplication
	public function toggle($element='this', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
362
		$element=Javascript::prep_element($element);
363
		$str="$({$element}).toggle();";
364
365
		if ($immediatly)
366
			$this->jquery_code_for_compile[]=$str;
367
		return $str;
368
	}
369
370
	/**
371
	 * Execute a javascript library toggle class action
372
	 *
373
	 * @param string - element
374
	 * @param boolean $immediatly defers the execution if set to false
375
	 * @return string
376
	 */
377
	public function toggleClass($element='this', $class='', $immediatly=false) {
378
		return $this->_genericCallValue('toggleClass',$element, $class, $immediatly);
379
	}
380
381
	/**
382
	 * Execute all handlers and behaviors attached to the matched elements for the given event.
383
	 * @param string $element
384
	 * @param string $event
385
	 * @param boolean $immediatly defers the execution if set to false
386
	 */
387 View Code Duplication
	public function trigger($element='this', $event='click', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
388
		$element=Javascript::prep_element($element);
389
		$str="$({$element}).trigger(\"$event\");";
390
391
		if ($immediatly)
392
			$this->jquery_code_for_compile[]=$str;
393
		return $str;
394
	}
395
396
	/**
397
	 * Execute a javascript library show action
398
	 *
399
	 * @param string - element
400
	 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
401
	 * @param string - Javascript callback function
402
	 * @param boolean $immediatly defers the execution if set to false
403
	 * @return string
404
	 */
405 View Code Duplication
	public function show($element='this', $speed='', $callback='', $immediatly=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
418
	}
419
420
	/**
421
	 * Creates a jQuery sortable
422
	 *
423
	 * @param string $element
424
	 * @param array $options
425
	 * @return void
426
	 */
427
	public function sortable($element, $options=array()) {
428
		if (count($options)>0) {
429
			$sort_options=array ();
430
			foreach ( $options as $k => $v ) {
431
				$sort_options[]="\n\t\t".$k.': '.$v."";
432
			}
433
			$sort_options=implode(",", $sort_options);
434
		} else {
435
			$sort_options='';
436
		}
437
438
		return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});";
439
	}
440
441
	/**
442
	 * Table Sorter Plugin
443
	 *
444
	 * @param string $table table name
445
	 * @param string $options plugin location
446
	 * @return string
447
	 */
448
	public function tablesorter($table='', $options='') {
449
		$this->jquery_code_for_compile[]="\t$(".Javascript::prep_element($table).").tablesorter($options);\n";
450
	}
451
452
	/**
453
	 * Allows to attach a condition
454
	 * @param string $condition
455
	 * @param string $jsCodeIfTrue
456
	 * @param string $jsCodeIfFalse
457
	 * @param boolean $immediatly defers the execution if set to false
458
	 */
459
	public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) {
460
		$str="if(".$condition."){".$jsCodeIfTrue."}";
461
		if (isset($jsCodeIfFalse)) {
462
			$str.="else{".$jsCodeIfFalse."}";
463
		}
464
465
		if ($immediatly)
466
			$this->jquery_code_for_compile[]=$str;
467
		return $str;
468
	}
469
470
	/**
471
	 * Call the JQuery method $jqueryCall on $element with parameters $param
472
	 * @param string $element
473
	 * @param string $jqueryCall
474
	 * @param mixed $param
475
	 * @param string $jsCallback javascript code to execute after the jquery call
476
	 * @param boolean $immediatly
477
	 * @return string
478
	 */
479
	private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) {
480
		$param=Javascript::prep_value($param);
481
		$callback="";
482
		if ($jsCallback!="")
483
			$callback=", function(event){\n{$jsCallback}\n}";
484
			$script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n";
485
			if ($immediatly)
486
				$this->jquery_code_for_compile[]=$script;
487
				return $script;
488
	}
489
490
	/**
491
	 * Calls the JQuery callback $someThing on $element with facultative parameter $param
492
	 * @param string $element the element
493
	 * @param string $jqueryCall the JQuery callback
494
	 * @param mixed $param array or string parameters
495
	 * @param string $jsCallback javascript code to execute after the jquery call
496
	 * @return mixed
497
	 */
498
	public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") {
499
		return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true);
500
	}
501
502
	/**
503
	 * Calls the JQuery callback $someThing on $element with facultative parameter $param
504
	 * @param string $element the element
505
	 * @param string $jqueryCall the JQuery callback
506
	 * @param mixed $param array or string parameters
507
	 * @param string $jsCallback javascript code to execute after the jquery call
508
	 * @return mixed
509
	 */
510
	public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") {
511
		return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false);
512
	}
513
514
	/**
515
	 *
516
	 * @param string $event
517
	 * @param string $element
518
	 * @param string $elementToModify
519
	 * @param string $jqueryCall
520
	 * @param string|array $param
521
	 * @param boolean $preventDefault
522
	 * @param boolean $stopPropagation
523
	 * @param string $jsCallback javascript code to execute after the jquery call
524
	 * @param boolean $immediatly
525
	 * @return string
526
	 */
527
	private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) {
528
		return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly);
0 ignored issues
show
Bug introduced by
It seems like _add_event() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
529
	}
530
531
	/**
532
	 * Calls the JQuery callback $jqueryCall on $element with facultative parameter $param in response to an event $event
533
	 * @param string $event
534
	 * @param string $element
535
	 * @param string $elementToModify
536
	 * @param string $jqueryCall
537
	 * @param string $param
538
	 * @param array $parameters default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true)
539
	 */
540
	public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) {
541
		$jsCallback="";
542
		$stopPropagation=false;
543
		$preventDefault=false;
544
		$immediatly=true;
545
		extract($parameters);
546
		return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback,$immediatly);
547
	}
548
549
	/**
550
	 * Executes the code $js
551
	 * @param string $js Code to execute
552
	 * @param boolean $immediatly delayed if false
553
	 * @return String
554
	 */
555
	public function exec($js, $immediatly=false) {
556
		$script=$js."\n";
557
		if ($immediatly)
558
			$this->jquery_code_for_compile[]=$script;
559
		return $script;
560
	}
561
562
	/**
563
	 * Executes the javascript code $js when $event fires on $element
564
	 * @param string $event
565
	 * @param string $element
566
	 * @param string $js Code to execute
567
	 * @param array $parameters default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true)
568
	 * @return String
569
	 */
570
	public function execOn($event, $element, $js, $parameters=array()) {
571
		$stopPropagation=false;
572
		$preventDefault=false;
573
		$immediatly=true;
574
		extract($parameters);
575
		$script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation,$immediatly);
0 ignored issues
show
Bug introduced by
It seems like _add_event() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
576
		return $script;
577
	}
578
}
579