1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\common\traits; |
4
|
|
|
|
5
|
|
|
trait JqueryEventsTrait { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Blur |
9
|
|
|
* |
10
|
|
|
* Outputs a jQuery blur event |
11
|
|
|
* |
12
|
|
|
* @param string The element to attach the event to |
13
|
|
|
* @param string The code to execute |
14
|
|
|
* @return string |
15
|
|
|
*/ |
16
|
|
|
public function _blur($element='this', $js='') { |
17
|
|
|
return $this->_add_event($element, $js, 'blur'); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// -------------------------------------------------------------------- |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Change |
24
|
|
|
* |
25
|
|
|
* Outputs a jQuery change event |
26
|
|
|
* |
27
|
|
|
* @param string The element to attach the event to |
28
|
|
|
* @param string The code to execute |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function _change($element='this', $js='') { |
32
|
|
|
return $this->_add_event($element, $js, 'change'); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// -------------------------------------------------------------------- |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Outputs a jQuery click event |
39
|
|
|
* |
40
|
|
|
* @param string $element The element to attach the event to |
41
|
|
|
* @param mixed $js The code to execute |
42
|
|
|
* @param boolean $ret_false whether or not to return false |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function _click($element='this', $js=array(), $ret_false=TRUE) { |
46
|
|
|
if (!is_array($js)) { |
47
|
|
|
$js=array ( |
48
|
|
|
$js |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($ret_false) { |
53
|
|
|
$js[]="return false;"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->_add_event($element, $js, 'click'); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Outputs a jQuery contextmenu event |
61
|
|
|
* |
62
|
|
|
* @param string The element to attach the event to |
63
|
|
|
* @param string The code to execute |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function _contextmenu($element='this', $js='') { |
67
|
|
|
return $this->_add_event($element, $js, 'contextmenu'); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// -------------------------------------------------------------------- |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Outputs a jQuery dblclick event |
74
|
|
|
* |
75
|
|
|
* @param string The element to attach the event to |
76
|
|
|
* @param string The code to execute |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function _dblclick($element='this', $js='') { |
80
|
|
|
return $this->_add_event($element, $js, 'dblclick'); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// -------------------------------------------------------------------- |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Outputs a jQuery error event |
87
|
|
|
* |
88
|
|
|
* @param string The element to attach the event to |
89
|
|
|
* @param string The code to execute |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function _error($element='this', $js='') { |
93
|
|
|
return $this->_add_event($element, $js, 'error'); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// -------------------------------------------------------------------- |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Outputs a jQuery focus event |
100
|
|
|
* |
101
|
|
|
* @param string The element to attach the event to |
102
|
|
|
* @param string The code to execute |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function _focus($element='this', $js='') { |
106
|
|
|
return $this->_add_event($element, $js, 'focus'); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// -------------------------------------------------------------------- |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Outputs a jQuery hover event |
113
|
|
|
* |
114
|
|
|
* @param string - element |
115
|
|
|
* @param string - Javascript code for mouse over |
116
|
|
|
* @param string - Javascript code for mouse out |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function _hover($element='this', $over, $out) { |
120
|
|
|
$event="\n\t$(".$this->_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"; |
|
|
|
|
121
|
|
|
|
122
|
|
|
$this->jquery_code_for_compile[]=$event; |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $event; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// -------------------------------------------------------------------- |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Outputs a jQuery keydown event |
131
|
|
|
* |
132
|
|
|
* @param string The element to attach the event to |
133
|
|
|
* @param string The code to execute |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function _keydown($element='this', $js='') { |
137
|
|
|
return $this->_add_event($element, $js, 'keydown'); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// -------------------------------------------------------------------- |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Outputs a jQuery keypress event |
144
|
|
|
* |
145
|
|
|
* @param string The element to attach the event to |
146
|
|
|
* @param string The code to execute |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function _keypress($element='this', $js='') { |
150
|
|
|
return $this->_add_event($element, $js, 'keypress'); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
// -------------------------------------------------------------------- |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Outputs a jQuery keydown event |
157
|
|
|
* |
158
|
|
|
* @param string The element to attach the event to |
159
|
|
|
* @param string The code to execute |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function _keyup($element='this', $js='') { |
163
|
|
|
return $this->_add_event($element, $js, 'keyup'); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// -------------------------------------------------------------------- |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Outputs a jQuery load event |
170
|
|
|
* |
171
|
|
|
* @param string The element to attach the event to |
172
|
|
|
* @param string The code to execute |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function _load($element='this', $js='') { |
176
|
|
|
return $this->_add_event($element, $js, 'load'); |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
// -------------------------------------------------------------------- |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Outputs a jQuery mousedown event |
183
|
|
|
* |
184
|
|
|
* @param string The element to attach the event to |
185
|
|
|
* @param string The code to execute |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function _mousedown($element='this', $js='') { |
189
|
|
|
return $this->_add_event($element, $js, 'mousedown'); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
// -------------------------------------------------------------------- |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Outputs a jQuery mouseout event |
196
|
|
|
* |
197
|
|
|
* @param string The element to attach the event to |
198
|
|
|
* @param string The code to execute |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function _mouseout($element='this', $js='') { |
202
|
|
|
return $this->_add_event($element, $js, 'mouseout'); |
|
|
|
|
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
// -------------------------------------------------------------------- |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Outputs a jQuery mouseover event |
209
|
|
|
* |
210
|
|
|
* @param string The element to attach the event to |
211
|
|
|
* @param string The code to execute |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
public function _mouseover($element='this', $js='') { |
215
|
|
|
return $this->_add_event($element, $js, 'mouseover'); |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// -------------------------------------------------------------------- |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Outputs a jQuery mouseup event |
222
|
|
|
* |
223
|
|
|
* @param string The element to attach the event to |
224
|
|
|
* @param string The code to execute |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function _mouseup($element='this', $js='') { |
228
|
|
|
return $this->_add_event($element, $js, 'mouseup'); |
|
|
|
|
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Outputs a jQuery resize event |
233
|
|
|
* |
234
|
|
|
* @param string The element to attach the event to |
235
|
|
|
* @param string The code to execute |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function _resize($element='this', $js='') { |
239
|
|
|
return $this->_add_event($element, $js, 'resize'); |
|
|
|
|
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
// -------------------------------------------------------------------- |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Outputs a jQuery scroll event |
246
|
|
|
* |
247
|
|
|
* @param string The element to attach the event to |
248
|
|
|
* @param string The code to execute |
249
|
|
|
* @return string |
250
|
|
|
*/ |
251
|
|
|
public function _scroll($element='this', $js='') { |
252
|
|
|
return $this->_add_event($element, $js, 'scroll'); |
|
|
|
|
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
// -------------------------------------------------------------------- |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Outputs a jQuery unload event |
259
|
|
|
* |
260
|
|
|
* @param string The element to attach the event to |
261
|
|
|
* @param string The code to execute |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
|
|
public function _unload($element='this', $js='') { |
265
|
|
|
return $this->_add_event($element, $js, 'unload'); |
|
|
|
|
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
} |
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
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. 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.