1 | <?php |
||
10 | trait JsUtilsEventsTrait { |
||
11 | |||
12 | |||
13 | protected $jquery_events=array ( |
||
14 | "bind","blur","change","click","dblclick","delegate","die","error","focus","focusin","focusout","hover","keydown","keypress","keyup","live","load","mousedown","mousseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","off","on","one","ready","resize","scroll","select","submit","toggle","trigger","triggerHandler","undind","undelegate","unload" |
||
15 | ); |
||
16 | |||
17 | /** |
||
18 | * Constructs the syntax for an event, and adds to into the array for compilation |
||
19 | * |
||
20 | * @param string $element The element to attach the event to |
||
21 | * @param string $js The code to execute |
||
22 | * @param string $event The event to pass |
||
23 | * @param boolean $preventDefault If set to true, the default action of the event will not be triggered. |
||
24 | * @param boolean $stopPropagation Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. |
||
25 | * @return string |
||
26 | */ |
||
27 | public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
||
45 | |||
46 | /** |
||
47 | * Outputs a javascript library blur event |
||
48 | * |
||
49 | * @param string $element element to attach the event to |
||
50 | * @param string $js code to execute |
||
51 | * @return string |
||
52 | */ |
||
53 | public function blur($element='this', $js='') { |
||
56 | |||
57 | /** |
||
58 | * Outputs a javascript library change event |
||
59 | * |
||
60 | * @param string $element element to attach the event to |
||
61 | * @param string $js code to execute |
||
62 | * @return string |
||
63 | */ |
||
64 | public function change($element='this', $js='') { |
||
67 | |||
68 | /** |
||
69 | * Outputs a javascript library click event |
||
70 | * |
||
71 | * @param string $element element to attach the event to |
||
72 | * @param string $js code to execute |
||
73 | * @param boolean $ret_false or not to return false |
||
74 | * @return string |
||
75 | */ |
||
76 | public function click($element='this', $js='', $ret_false=TRUE) { |
||
89 | |||
90 | /** |
||
91 | * Outputs a javascript library contextmenu event |
||
92 | * |
||
93 | * @param string $element element to attach the event to |
||
94 | * @param string $js code to execute |
||
95 | * @return string |
||
96 | */ |
||
97 | public function contextmenu($element='this', $js='') { |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Outputs a javascript library dblclick event |
||
104 | * |
||
105 | * @param string $element element to attach the event to |
||
106 | * @param string $js code to execute |
||
107 | * @return string |
||
108 | */ |
||
109 | public function dblclick($element='this', $js='') { |
||
112 | |||
113 | /** |
||
114 | * Outputs a javascript library error event |
||
115 | * |
||
116 | * @param string $element element to attach the event to |
||
117 | * @param string $js code to execute |
||
118 | * @return string |
||
119 | */ |
||
120 | public function error($element='this', $js='') { |
||
123 | |||
124 | /** |
||
125 | * Outputs a javascript library focus event |
||
126 | * |
||
127 | * @param string $element element to attach the event to |
||
128 | * @param string $js code to execute |
||
129 | * @return string |
||
130 | */ |
||
131 | public function focus($element='this', $js='') { |
||
134 | |||
135 | /** |
||
136 | * Outputs a javascript library hover event |
||
137 | * |
||
138 | * @param string $element |
||
139 | * @param string $over code for mouse over |
||
140 | * @param string $out code for mouse out |
||
141 | * @return string |
||
142 | */ |
||
143 | public function hover($element='this', $over, $out) { |
||
148 | |||
149 | /** |
||
150 | * Outputs a javascript library keydown event |
||
151 | * |
||
152 | * @param string $element element to attach the event to |
||
153 | * @param string $js code to execute |
||
154 | * @return string |
||
155 | */ |
||
156 | public function keydown($element='this', $js='') { |
||
159 | |||
160 | /** |
||
161 | * Outputs a javascript library keypress event |
||
162 | * |
||
163 | * @param string $element element to attach the event to |
||
164 | * @param string $js code to execute |
||
165 | * @return string |
||
166 | */ |
||
167 | public function keypress($element='this', $js='') { |
||
170 | |||
171 | /** |
||
172 | * Outputs a javascript library keydown event |
||
173 | * |
||
174 | * @param string $element element to attach the event to |
||
175 | * @param string $js code to execute |
||
176 | * @return string |
||
177 | */ |
||
178 | public function keyup($element='this', $js='') { |
||
181 | |||
182 | /** |
||
183 | * Outputs a javascript library load event |
||
184 | * |
||
185 | * @param string $element element to attach the event to |
||
186 | * @param string $js code to execute |
||
187 | * @return string |
||
188 | */ |
||
189 | public function load($element='this', $js='') { |
||
192 | |||
193 | /** |
||
194 | * Outputs a javascript library mousedown event |
||
195 | * |
||
196 | * @param string $element element to attach the event to |
||
197 | * @param string $js code to execute |
||
198 | * @return string |
||
199 | */ |
||
200 | public function mousedown($element='this', $js='') { |
||
203 | |||
204 | /** |
||
205 | * Outputs a javascript library mouseout event |
||
206 | * |
||
207 | * @param string $element element to attach the event to |
||
208 | * @param string $js code to execute |
||
209 | * @return string |
||
210 | */ |
||
211 | public function mouseout($element='this', $js='') { |
||
214 | /** |
||
215 | * Outputs a javascript library mouseover event |
||
216 | * |
||
217 | * @param string $element element to attach the event to |
||
218 | * @param string $js code to execute |
||
219 | * @return string |
||
220 | */ |
||
221 | public function mouseover($element='this', $js='') { |
||
224 | |||
225 | /** |
||
226 | * Outputs a javascript library mouseup event |
||
227 | * |
||
228 | * @param string $element element to attach the event to |
||
229 | * @param string $js code to execute |
||
230 | * @return string |
||
231 | */ |
||
232 | public function mouseup($element='this', $js='') { |
||
235 | |||
236 | |||
237 | /** |
||
238 | * Outputs a javascript library unload event |
||
239 | * |
||
240 | * @param string $element element to attach the event to |
||
241 | * @param string $js code to execute |
||
242 | * @return string |
||
243 | */ |
||
244 | public function unload($element='this', $js='') { |
||
247 | |||
248 | // -------------------------------------------------------------------- |
||
249 | /** |
||
250 | * Outputs a javascript library resize event |
||
251 | * |
||
252 | * @param string $element element to attach the event to |
||
253 | * @param string $js code to execute |
||
254 | * @return string |
||
255 | */ |
||
256 | public function resize($element='this', $js='') { |
||
259 | // -------------------------------------------------------------------- |
||
260 | /** |
||
261 | * Outputs a javascript library scroll event |
||
262 | * |
||
263 | * @param string $element element to attach the event to |
||
264 | * @param string $js code to execute |
||
265 | * @return string |
||
266 | */ |
||
267 | public function scroll($element='this', $js='') { |
||
270 | } |
||
271 |
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: