1 | <?php |
||
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='') { |
||
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='') { |
||
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) { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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) { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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='') { |
||
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.