1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\common\traits; |
4
|
|
|
|
5
|
|
|
trait JsUtilsActionsTrait { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* add class to element |
9
|
|
|
* |
10
|
|
|
* @param string $element |
11
|
|
|
* @param string $class to add |
12
|
|
|
* @param boolean $immediatly defers the execution if set to false |
13
|
|
|
* @return string |
14
|
|
|
*/ |
15
|
|
|
public function addClass($element='this', $class='', $immediatly=false) { |
16
|
|
|
return $this->js->_genericCallValue('addClass',$element, $class, $immediatly); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Insert content, specified by the parameter, after each element in the set of matched elements |
21
|
|
|
* @param string $to |
22
|
|
|
* @param string $element |
23
|
|
|
* @param boolean $immediatly defers the execution if set to false |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function after($to, $element, $immediatly=false){ |
27
|
|
|
return $this->js->_genericCallElement('after',$to, $element, $immediatly); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Insert content, specified by the parameter, before each element in the set of matched elements |
32
|
|
|
* @param string $to |
33
|
|
|
* @param string $element |
34
|
|
|
* @param boolean $immediatly defers the execution if set to false |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
public function before($to, $element, $immediatly=false){ |
38
|
|
|
return $this->js->_genericCallElement('before',$to, $element, $immediatly); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* 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. |
43
|
|
|
* @param string $element |
44
|
|
|
* @param string $attributeName |
45
|
|
|
* @param string $value |
46
|
|
|
* @param boolean $immediatly defers the execution if set to false |
47
|
|
|
*/ |
48
|
|
|
public function attr($element='this', $attributeName='value', $value='', $immediatly=false) { |
49
|
|
|
return $this->js->_attr($element, $attributeName, $value, $immediatly); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* 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. |
54
|
|
|
* @param string $element |
55
|
|
|
* @param string $value |
56
|
|
|
* @param boolean $immediatly defers the execution if set to false |
57
|
|
|
*/ |
58
|
|
|
public function val($element='this',$value='',$immediatly=false){ |
59
|
|
|
return $this->js->_genericCallValue('val',$element,$value,$immediatly); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get or set the html of an attribute for the first element in the set of matched elements. |
64
|
|
|
* @param string $element |
65
|
|
|
* @param string $value |
66
|
|
|
* @param boolean $immediatly defers the execution if set to false |
67
|
|
|
*/ |
68
|
|
|
public function html($element='this', $value='', $immediatly=false) { |
69
|
|
|
return $this->js->_genericCallValue('html',$element, $value, $immediatly); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Outputs a javascript library animate event |
74
|
|
|
* |
75
|
|
|
* @param string $element element |
76
|
|
|
* @param array $params |
77
|
|
|
* @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
78
|
|
|
* @param string $extra |
79
|
|
|
* @param boolean $immediatly defers the execution if set to false |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
83
|
|
|
return $this->js->_animate($element, $params, $speed, $extra, $immediatly); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Insert content, specified by the parameter $element, to the end of each element in the set of matched elements $to. |
88
|
|
|
* @param string $to |
89
|
|
|
* @param string $element |
90
|
|
|
* @param boolean $immediatly defers the execution if set to false |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function append($to, $element, $immediatly=false) { |
94
|
|
|
return $this->js->_genericCallElement('append',$to, $element, $immediatly); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Insert content, specified by the parameter $element, to the beginning of each element in the set of matched elements $to. |
99
|
|
|
* @param string $to |
100
|
|
|
* @param string $element |
101
|
|
|
* @param boolean $immediatly defers the execution if set to false |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function prepend($to, $element, $immediatly=false) { |
105
|
|
|
return $this->js->_genericCallElement('prepend',$to, $element, $immediatly); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Execute a javascript library hide action |
110
|
|
|
* |
111
|
|
|
* @param string - element |
112
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
113
|
|
|
* @param string - Javascript callback function |
114
|
|
|
* @param boolean $immediatly defers the execution if set to false |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
118
|
|
|
return $this->js->_fadeIn($element, $speed, $callback, $immediatly); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Execute a javascript library hide action |
123
|
|
|
* |
124
|
|
|
* @param string - element |
125
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
126
|
|
|
* @param string - Javascript callback function |
127
|
|
|
* @param boolean $immediatly defers the execution if set to false |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
131
|
|
|
return $this->js->_fadeOut($element, $speed, $callback, $immediatly); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Execute a javascript library slideUp action |
136
|
|
|
* |
137
|
|
|
* @param string - element |
138
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
139
|
|
|
* @param string - Javascript callback function |
140
|
|
|
* @param boolean $immediatly defers the execution if set to false |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
144
|
|
|
return $this->js->_slideUp($element, $speed, $callback, $immediatly); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Execute a javascript library removeClass action |
149
|
|
|
* |
150
|
|
|
* @param string - element |
151
|
|
|
* @param string - Class to add |
152
|
|
|
* @param boolean $immediatly defers the execution if set to false |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function removeClass($element='this', $class='', $immediatly=false) { |
156
|
|
|
return $this->js->_genericCall('removeClass',$element, $class, $immediatly); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Execute a javascript library slideDown action |
161
|
|
|
* |
162
|
|
|
* @param string - element |
163
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
164
|
|
|
* @param string - Javascript callback function |
165
|
|
|
* @param boolean $immediatly defers the execution if set to false |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
169
|
|
|
return $this->js->_slideDown($element, $speed, $callback, $immediatly); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Execute a javascript library slideToggle action |
174
|
|
|
* |
175
|
|
|
* @param string - element |
176
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
177
|
|
|
* @param string - Javascript callback function |
178
|
|
|
* @param boolean $immediatly defers the execution if set to false |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
182
|
|
|
return $this->js->_slideToggle($element, $speed, $callback, $immediatly); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Execute a javascript library hide action |
187
|
|
|
* |
188
|
|
|
* @param string - element |
189
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
190
|
|
|
* @param string - Javascript callback function |
191
|
|
|
* @param boolean $immediatly defers the execution if set to false |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
195
|
|
|
return $this->js->_hide($element, $speed, $callback, $immediatly); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Execute a javascript library toggle action |
200
|
|
|
* |
201
|
|
|
* @param string - element |
202
|
|
|
* @param boolean $immediatly defers the execution if set to false |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function toggle($element='this', $immediatly=false) { |
206
|
|
|
return $this->js->_toggle($element, $immediatly); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Execute a javascript library toggle class action |
211
|
|
|
* |
212
|
|
|
* @param string - element |
213
|
|
|
* @param boolean $immediatly defers the execution if set to false |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function toggleClass($element='this', $class='', $immediatly=false) { |
217
|
|
|
return $this->js->_genericCallValue('toggleClass',$element, $class, $immediatly); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Execute all handlers and behaviors attached to the matched elements for the given event. |
222
|
|
|
* @param string $element |
223
|
|
|
* @param string $event |
224
|
|
|
* @param boolean $immediatly defers the execution if set to false |
225
|
|
|
*/ |
226
|
|
|
public function trigger($element='this', $event='click', $immediatly=false) { |
227
|
|
|
return $this->js->_trigger($element, $event, $immediatly); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Execute a javascript library show action |
232
|
|
|
* |
233
|
|
|
* @param string - element |
234
|
|
|
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
235
|
|
|
* @param string - Javascript callback function |
236
|
|
|
* @param boolean $immediatly defers the execution if set to false |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
public function show($element='this', $speed='', $callback='', $immediatly=false) { |
240
|
|
|
return $this->js->_show($element, $speed, $callback, $immediatly); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Allows to attach a condition |
245
|
|
|
* @param string $condition |
246
|
|
|
* @param string $jsCodeIfTrue |
247
|
|
|
* @param string $jsCodeIfFalse |
248
|
|
|
* @param boolean $immediatly defers the execution if set to false |
249
|
|
|
*/ |
250
|
|
|
public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
251
|
|
|
return $this->js->_condition($condition, $jsCodeIfTrue, $jsCodeIfFalse, $immediatly); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Calls the JQuery callback $someThing on $element with facultative parameter $param |
256
|
|
|
* @param string $element the element |
257
|
|
|
* @param string $jqueryCall the JQuery callback |
258
|
|
|
* @param mixed $param array or string parameters |
259
|
|
|
* @param string $jsCallback javascript code to execute after the jquery call |
260
|
|
|
* @return mixed |
261
|
|
|
*/ |
262
|
|
|
public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
263
|
|
|
return $this->js->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Calls the JQuery callback $someThing on $element with facultative parameter $param |
268
|
|
|
* @param string $element the element |
269
|
|
|
* @param string $jqueryCall the JQuery callback |
270
|
|
|
* @param mixed $param array or string parameters |
271
|
|
|
* @param string $jsCallback javascript code to execute after the jquery call |
272
|
|
|
* @return mixed |
273
|
|
|
*/ |
274
|
|
|
public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
275
|
|
|
return $this->js->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Calls the JQuery callback $jqueryCall on $element with facultative parameter $param in response to an event $event |
280
|
|
|
* @param string $event |
281
|
|
|
* @param string $element |
282
|
|
|
* @param string $elementToModify |
283
|
|
|
* @param string $jqueryCall |
284
|
|
|
* @param string $param |
285
|
|
|
* @param array $parameters default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
286
|
|
|
*/ |
287
|
|
View Code Duplication |
public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
|
|
|
288
|
|
|
$jsCallback=""; |
289
|
|
|
$stopPropagation=false; |
290
|
|
|
$preventDefault=false; |
291
|
|
|
$immediatly=true; |
292
|
|
|
extract($parameters); |
293
|
|
|
return $this->js->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback,$immediatly); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Executes the code $js |
298
|
|
|
* @param string $js Code to execute |
299
|
|
|
* @param boolean $immediatly delayed if false |
300
|
|
|
* @return String |
301
|
|
|
*/ |
302
|
|
|
public function exec($js, $immediatly=false) { |
303
|
|
|
$script=$this->js->_exec($js, $immediatly); |
304
|
|
|
return $script; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Executes the javascript code $js when $event fires on $element |
309
|
|
|
* @param string $event |
310
|
|
|
* @param string $element |
311
|
|
|
* @param string $js Code to execute |
312
|
|
|
* @param array $parameters default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
313
|
|
|
* @return String |
314
|
|
|
*/ |
315
|
|
View Code Duplication |
public function execOn($event, $element, $js, $parameters=array()) { |
|
|
|
|
316
|
|
|
$stopPropagation=false; |
317
|
|
|
$preventDefault=false; |
318
|
|
|
$immediatly=true; |
319
|
|
|
extract($parameters); |
320
|
|
|
$script=$this->js->_execOn($element, $event, $js, $preventDefault, $stopPropagation,$immediatly); |
321
|
|
|
return $script; |
322
|
|
|
} |
323
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: