Passed
Push — master ( 3d3660...f6786e )
by Jean-Christophe
01:38
created

JsUtilsEventsTrait::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Ajax\common\traits;
3
4
use Ajax\service\Javascript;
5
6
/**
7
 *
8
 * @author jc
9
 * @property array $jquery_code_for_compile
10
 */
11
trait JsUtilsEventsTrait {
12
13
	protected $jquery_events = array(
14
		"bind",
15
		"blur",
16
		"change",
17
		"click",
18
		"dblclick",
19
		"delegate",
20
		"die",
21
		"error",
22
		"focus",
23
		"focusin",
24
		"focusout",
25
		"hover",
26
		"keydown",
27
		"keypress",
28
		"keyup",
29
		"live",
30
		"load",
31
		"mousedown",
32
		"mousseenter",
33
		"mouseleave",
34
		"mousemove",
35
		"mouseout",
36
		"mouseover",
37
		"mouseup",
38
		"off",
39
		"on",
40
		"one",
41
		"ready",
42
		"resize",
43
		"scroll",
44
		"select",
45
		"submit",
46
		"toggle",
47
		"trigger",
48
		"triggerHandler",
49
		"undind",
50
		"undelegate",
51
		"unload"
52
	);
53
54
	abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true);
55
56
	/**
57
	 * Outputs a javascript library blur event
58
	 *
59
	 * @param string $element
60
	 *        	element to attach the event to
61
	 * @param string $js
62
	 *        	code to execute
63
	 * @return string
64
	 */
65
	public function blur($element = 'this', $js = '') {
66
		return $this->_add_event($element, $js, 'blur');
67
	}
68
69
	/**
70
	 * Outputs a javascript library change event
71
	 *
72
	 * @param string $element
73
	 *        	element to attach the event to
74
	 * @param string $js
75
	 *        	code to execute
76
	 * @param boolean $preventDefault
77
	 * @param boolean $stopPropagation
78
	 * @return string
79
	 */
80
	public function change($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
81
		return $this->_add_event($element, $js, 'change', $preventDefault, $stopPropagation);
82
	}
83
84
	/**
85
	 * Outputs a javascript library click event
86
	 *
87
	 * @param string $element
88
	 *        	element to attach the event to
89
	 * @param string|array $js
90
	 *        	code to execute
91
	 * @param boolean $ret_false
92
	 *        	or not to return false
93
	 * @param boolean $preventDefault
94
	 * @param boolean $stopPropagation
95
	 * @return string
96
	 */
97
	public function click($element = 'this', $js = '', $ret_false = TRUE, $preventDefault = false, $stopPropagation = false) {
98
		if (! is_array($js)) {
99
			$js = array(
100
				$js
101
			);
102
		}
103
104
		if ($ret_false) {
105
			$js[] = "return false;";
106
		}
107
108
		return $this->_add_event($element, $js, 'click', $preventDefault, $stopPropagation);
109
	}
110
111
	/**
112
	 * Outputs a javascript library contextmenu event
113
	 *
114
	 * @param string $element
115
	 *        	element to attach the event to
116
	 * @param string $js
117
	 *        	code to execute
118
	 * @return string
119
	 */
120
	public function contextmenu($element = 'this', $js = '') {
121
		return $this->_add_event($element, $js, 'contextmenu');
122
	}
123
124
	/**
125
	 * Outputs a javascript library dblclick event
126
	 *
127
	 * @param string $element
128
	 *        	element to attach the event to
129
	 * @param string $js
130
	 *        	code to execute
131
	 * @return string
132
	 */
133
	public function dblclick($element = 'this', $js = '') {
134
		return $this->_add_event($element, $js, 'dblclick');
135
	}
136
137
	/**
138
	 * Outputs a javascript library error event
139
	 *
140
	 * @param string $element
141
	 *        	element to attach the event to
142
	 * @param string $js
143
	 *        	code to execute
144
	 * @return string
145
	 */
146
	public function error($element = 'this', $js = '') {
147
		return $this->_add_event($element, $js, 'error');
148
	}
149
150
	/**
151
	 * Outputs a javascript library focus event
152
	 *
153
	 * @param string $element
154
	 *        	element to attach the event to
155
	 * @param string $js
156
	 *        	code to execute
157
	 * @return string
158
	 */
159
	public function focus($element = 'this', $js = '') {
160
		return $this->_add_event($element, $js, 'focus');
161
	}
162
163
	/**
164
	 * Outputs a javascript library hover event
165
	 *
166
	 * @param string $element
167
	 * @param string $over
168
	 *        	code for mouse over
169
	 * @param string $out
170
	 *        	code for mouse out
171
	 * @return string
172
	 */
173
	public function hover($element = 'this', $over, $out) {
174
		$event = "\n\t$(" . Javascript::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";
175
		$this->jquery_code_for_compile[] = $event;
176
		return $event;
177
	}
178
179
	/**
180
	 * Outputs a javascript library keydown event
181
	 *
182
	 * @param string $element
183
	 *        	element to attach the event to
184
	 * @param string $js
185
	 *        	code to execute
186
	 * @return string
187
	 */
188
	public function keydown($element = 'this', $js = '') {
189
		return $this->_add_event($element, $js, 'keydown');
190
	}
191
192
	/**
193
	 * Outputs a javascript library keypress event
194
	 *
195
	 * @param string $element
196
	 *        	element to attach the event to
197
	 * @param string $js
198
	 *        	code to execute
199
	 * @return string
200
	 */
201
	public function keypress($element = 'this', $js = '') {
202
		return $this->_add_event($element, $js, 'keypress');
203
	}
204
205
	/**
206
	 * Outputs a javascript library keydown event
207
	 *
208
	 * @param string $element
209
	 *        	element to attach the event to
210
	 * @param string $js
211
	 *        	code to execute
212
	 * @return string
213
	 */
214
	public function keyup($element = 'this', $js = '') {
215
		return $this->_add_event($element, $js, 'keyup');
216
	}
217
218
	/**
219
	 * Outputs a javascript library load event
220
	 *
221
	 * @param string $element
222
	 *        	element to attach the event to
223
	 * @param string $js
224
	 *        	code to execute
225
	 * @return string
226
	 */
227
	public function load($element = 'this', $js = '') {
228
		return $this->_add_event($element, $js, 'load');
229
	}
230
231
	/**
232
	 * Outputs a javascript library mousedown event
233
	 *
234
	 * @param string $element
235
	 *        	element to attach the event to
236
	 * @param string $js
237
	 *        	code to execute
238
	 * @return string
239
	 */
240
	public function mousedown($element = 'this', $js = '') {
241
		return $this->_add_event($element, $js, 'mousedown');
242
	}
243
244
	/**
245
	 * Outputs a javascript library mouseout event
246
	 *
247
	 * @param string $element
248
	 *        	element to attach the event to
249
	 * @param string $js
250
	 *        	code to execute
251
	 * @return string
252
	 */
253
	public function mouseout($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
254
		return $this->_add_event($element, $js, 'mouseout', $preventDefault, $stopPropagation);
255
	}
256
257
	/**
258
	 * Outputs a javascript library mouseleave event
259
	 *
260
	 * @param string $element
261
	 *        	element to attach the event to
262
	 * @param string $js
263
	 *        	code to execute
264
	 * @return string
265
	 */
266
	public function mouseleave($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
267
		return $this->_add_event($element, $js, 'mouseleave', $preventDefault, $stopPropagation);
268
	}
269
270
	/**
271
	 * Outputs a javascript library mouseenter event
272
	 *
273
	 * @param string $element
274
	 *        	element to attach the event to
275
	 * @param string $js
276
	 *        	code to execute
277
	 * @return string
278
	 */
279
	public function mouseenter($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) {
280
		return $this->_add_event($element, $js, 'mouseenter', $preventDefault, $stopPropagation);
281
	}
282
283
	/**
284
	 * Outputs a javascript library mouseover event
285
	 *
286
	 * @param string $element
287
	 *        	element to attach the event to
288
	 * @param string $js
289
	 *        	code to execute
290
	 * @return string
291
	 */
292
	public function mouseover($element = 'this', $js = '') {
293
		return $this->_add_event($element, $js, 'mouseover');
294
	}
295
296
	/**
297
	 * Outputs a javascript library mouseup event
298
	 *
299
	 * @param string $element
300
	 *        	element to attach the event to
301
	 * @param string $js
302
	 *        	code to execute
303
	 * @return string
304
	 */
305
	public function mouseup($element = 'this', $js = '') {
306
		return $this->_add_event($element, $js, 'mouseup');
307
	}
308
309
	/**
310
	 * Outputs a javascript library unload event
311
	 *
312
	 * @param string $element
313
	 *        	element to attach the event to
314
	 * @param string $js
315
	 *        	code to execute
316
	 * @return string
317
	 */
318
	public function unload($element = 'this', $js = '') {
319
		return $this->_add_event($element, $js, 'unload');
320
	}
321
322
	// --------------------------------------------------------------------
323
	/**
324
	 * Outputs a javascript library resize event
325
	 *
326
	 * @param string $element
327
	 *        	element to attach the event to
328
	 * @param string $js
329
	 *        	code to execute
330
	 * @return string
331
	 */
332
	public function resize($element = 'this', $js = '') {
333
		return $this->_add_event($element, $js, 'resize');
334
	}
335
336
	// --------------------------------------------------------------------
337
	/**
338
	 * Outputs a javascript library scroll event
339
	 *
340
	 * @param string $element
341
	 *        	element to attach the event to
342
	 * @param string $js
343
	 *        	code to execute
344
	 * @return string
345
	 */
346
	public function scroll($element = 'this', $js = '') {
347
		return $this->_add_event($element, $js, 'scroll');
348
	}
349
}
350