1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
---|
2 | |
---|
3 | /** |
---|
4 | * CodeIgniter |
---|
5 | * |
---|
6 | * An open source application development framework for PHP 4.3.2 or newer |
---|
7 | * |
---|
8 | * @package CodeIgniter |
---|
9 | * @author ExpressionEngine Dev Team |
---|
10 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
---|
11 | * @license http://www.codeigniter.com/user_guide/license.html |
---|
12 | * @link http://www.codeigniter.com |
---|
13 | * @since Version 1.0 |
---|
14 | * @filesource |
---|
15 | */ |
---|
16 | |
---|
17 | /** |
---|
18 | * Jquery Class |
---|
19 | * |
---|
20 | * @package CodeIgniter |
---|
21 | * @subpackage Libraries |
---|
22 | * @author ExpressionEngine Dev Team |
---|
23 | * @category Loader |
---|
24 | * @link http://www.codeigniter.com/user_guide/libraries/javascript.html |
---|
25 | */ |
---|
26 | |
---|
27 | class CI_Jquery extends CI_Javascript { |
---|
28 | |
---|
29 | var $_javascript_folder = 'js'; |
---|
30 | var $jquery_code_for_load = array(); |
---|
31 | var $jquery_code_for_compile = array(); |
---|
32 | var $jquery_corner_active = FALSE; |
---|
33 | var $jquery_table_sorter_active = FALSE; |
---|
34 | var $jquery_table_sorter_pager_active = FALSE; |
---|
35 | var $jquery_ajax_img = ''; |
---|
36 | |
---|
37 | public function __construct($params) |
---|
38 | { |
---|
39 | $this->CI =& get_instance(); |
---|
40 | extract($params); |
---|
41 | |
---|
42 | if ($autoload === TRUE) |
---|
43 | { |
---|
44 | $this->script(); |
---|
45 | } |
---|
46 | |
---|
47 | log_message('debug', "Jquery Class Initialized"); |
---|
48 | } |
---|
49 | |
---|
50 | // -------------------------------------------------------------------- |
---|
51 | // Event Code |
---|
52 | // -------------------------------------------------------------------- |
---|
53 | |
---|
54 | /** |
---|
55 | * Blur |
---|
56 | * |
---|
57 | * Outputs a jQuery blur event |
---|
58 | * |
---|
59 | * @access private |
---|
60 | * @param string The element to attach the event to |
---|
61 | * @param string The code to execute |
---|
62 | * @return string |
---|
63 | */ |
---|
64 | function _blur($element = 'this', $js = '') |
---|
65 | { |
---|
66 | return $this->_add_event($element, $js, 'blur'); |
---|
67 | } |
---|
68 | |
---|
69 | // -------------------------------------------------------------------- |
---|
70 | |
---|
71 | /** |
---|
72 | * Change |
---|
73 | * |
---|
74 | * Outputs a jQuery change event |
---|
75 | * |
---|
76 | * @access private |
---|
77 | * @param string The element to attach the event to |
---|
78 | * @param string The code to execute |
---|
79 | * @return string |
---|
80 | */ |
---|
81 | function _change($element = 'this', $js = '') |
---|
82 | { |
---|
83 | return $this->_add_event($element, $js, 'change'); |
---|
84 | } |
---|
85 | |
---|
86 | // -------------------------------------------------------------------- |
---|
87 | |
---|
88 | /** |
---|
89 | * Click |
---|
90 | * |
---|
91 | * Outputs a jQuery click event |
---|
92 | * |
---|
93 | * @access private |
---|
94 | * @param string The element to attach the event to |
---|
95 | * @param string The code to execute |
---|
96 | * @param boolean whether or not to return false |
---|
97 | * @return string |
---|
98 | */ |
---|
99 | function _click($element = 'this', $js = '', $ret_false = TRUE) |
---|
100 | { |
---|
101 | if ( ! is_array($js)) |
---|
102 | { |
---|
103 | $js = array($js); |
---|
104 | } |
---|
105 | |
---|
106 | if ($ret_false) |
---|
107 | { |
---|
108 | $js[] = "return false;"; |
---|
109 | } |
---|
110 | |
---|
111 | return $this->_add_event($element, $js, 'click'); |
---|
112 | } |
---|
113 | |
---|
114 | // -------------------------------------------------------------------- |
---|
115 | |
---|
116 | /** |
---|
117 | * Double Click |
---|
118 | * |
---|
119 | * Outputs a jQuery dblclick event |
---|
120 | * |
---|
121 | * @access private |
---|
122 | * @param string The element to attach the event to |
---|
123 | * @param string The code to execute |
---|
124 | * @return string |
---|
125 | */ |
---|
126 | function _dblclick($element = 'this', $js = '') |
---|
127 | { |
---|
128 | return $this->_add_event($element, $js, 'dblclick'); |
---|
129 | } |
---|
130 | |
---|
131 | // -------------------------------------------------------------------- |
---|
132 | |
---|
133 | /** |
---|
134 | * Error |
---|
135 | * |
---|
136 | * Outputs a jQuery error event |
---|
137 | * |
---|
138 | * @access private |
---|
139 | * @param string The element to attach the event to |
---|
140 | * @param string The code to execute |
---|
141 | * @return string |
---|
142 | */ |
---|
143 | function _error($element = 'this', $js = '') |
---|
144 | { |
---|
145 | return $this->_add_event($element, $js, 'error'); |
---|
146 | } |
---|
147 | |
---|
148 | // -------------------------------------------------------------------- |
---|
149 | |
---|
150 | /** |
---|
151 | * Focus |
---|
152 | * |
---|
153 | * Outputs a jQuery focus event |
---|
154 | * |
---|
155 | * @access private |
---|
156 | * @param string The element to attach the event to |
---|
157 | * @param string The code to execute |
---|
158 | * @return string |
---|
159 | */ |
---|
160 | function _focus($element = 'this', $js = '') |
---|
161 | { |
---|
162 | return $this->_add_event($element, $js, 'focus'); |
---|
163 | } |
---|
164 | |
---|
165 | // -------------------------------------------------------------------- |
---|
166 | |
---|
167 | /** |
---|
168 | * Hover |
---|
169 | * |
---|
170 | * Outputs a jQuery hover event |
---|
171 | * |
---|
172 | * @access private |
---|
173 | * @param string - element |
---|
174 | * @param string - Javascript code for mouse over |
---|
175 | * @param string - Javascript code for mouse out |
---|
176 | * @return string |
---|
177 | */ |
---|
178 | function _hover($element = 'this', $over, $out) |
---|
179 | { |
---|
180 | $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"; |
---|
181 | |
---|
182 | $this->jquery_code_for_compile[] = $event; |
---|
183 | |
---|
184 | return $event; |
---|
185 | } |
---|
186 | |
---|
187 | // -------------------------------------------------------------------- |
---|
188 | |
---|
189 | /** |
---|
190 | * Keydown |
---|
191 | * |
---|
192 | * Outputs a jQuery keydown event |
---|
193 | * |
---|
194 | * @access private |
---|
195 | * @param string The element to attach the event to |
---|
196 | * @param string The code to execute |
---|
197 | * @return string |
---|
198 | */ |
---|
199 | function _keydown($element = 'this', $js = '') |
---|
200 | { |
---|
201 | return $this->_add_event($element, $js, 'keydown'); |
---|
202 | } |
---|
203 | |
---|
204 | // -------------------------------------------------------------------- |
---|
205 | |
---|
206 | /** |
---|
207 | * Keyup |
---|
208 | * |
---|
209 | * Outputs a jQuery keydown event |
---|
210 | * |
---|
211 | * @access private |
---|
212 | * @param string The element to attach the event to |
---|
213 | * @param string The code to execute |
---|
214 | * @return string |
---|
215 | */ |
---|
216 | function _keyup($element = 'this', $js = '') |
---|
217 | { |
---|
218 | return $this->_add_event($element, $js, 'keyup'); |
---|
219 | } |
---|
220 | |
---|
221 | // -------------------------------------------------------------------- |
---|
222 | |
---|
223 | /** |
---|
224 | * Load |
---|
225 | * |
---|
226 | * Outputs a jQuery load event |
---|
227 | * |
---|
228 | * @access private |
---|
229 | * @param string The element to attach the event to |
---|
230 | * @param string The code to execute |
---|
231 | * @return string |
---|
232 | */ |
---|
233 | function _load($element = 'this', $js = '') |
---|
234 | { |
---|
235 | return $this->_add_event($element, $js, 'load'); |
---|
236 | } |
---|
237 | |
---|
238 | // -------------------------------------------------------------------- |
---|
239 | |
---|
240 | /** |
---|
241 | * Mousedown |
---|
242 | * |
---|
243 | * Outputs a jQuery mousedown event |
---|
244 | * |
---|
245 | * @access private |
---|
246 | * @param string The element to attach the event to |
---|
247 | * @param string The code to execute |
---|
248 | * @return string |
---|
249 | */ |
---|
250 | function _mousedown($element = 'this', $js = '') |
---|
251 | { |
---|
252 | return $this->_add_event($element, $js, 'mousedown'); |
---|
253 | } |
---|
254 | |
---|
255 | // -------------------------------------------------------------------- |
---|
256 | |
---|
257 | /** |
---|
258 | * Mouse Out |
---|
259 | * |
---|
260 | * Outputs a jQuery mouseout event |
---|
261 | * |
---|
262 | * @access private |
---|
263 | * @param string The element to attach the event to |
---|
264 | * @param string The code to execute |
---|
265 | * @return string |
---|
266 | */ |
---|
267 | function _mouseout($element = 'this', $js = '') |
---|
268 | { |
---|
269 | return $this->_add_event($element, $js, 'mouseout'); |
---|
270 | } |
---|
271 | |
---|
272 | // -------------------------------------------------------------------- |
---|
273 | |
---|
274 | /** |
---|
275 | * Mouse Over |
---|
276 | * |
---|
277 | * Outputs a jQuery mouseover event |
---|
278 | * |
---|
279 | * @access private |
---|
280 | * @param string The element to attach the event to |
---|
281 | * @param string The code to execute |
---|
282 | * @return string |
---|
283 | */ |
---|
284 | function _mouseover($element = 'this', $js = '') |
---|
285 | { |
---|
286 | return $this->_add_event($element, $js, 'mouseover'); |
---|
287 | } |
---|
288 | |
---|
289 | // -------------------------------------------------------------------- |
---|
290 | |
---|
291 | /** |
---|
292 | * Mouseup |
---|
293 | * |
---|
294 | * Outputs a jQuery mouseup event |
---|
295 | * |
---|
296 | * @access private |
---|
297 | * @param string The element to attach the event to |
---|
298 | * @param string The code to execute |
---|
299 | * @return string |
---|
300 | */ |
---|
301 | function _mouseup($element = 'this', $js = '') |
---|
302 | { |
---|
303 | return $this->_add_event($element, $js, 'mouseup'); |
---|
304 | } |
---|
305 | |
---|
306 | // -------------------------------------------------------------------- |
---|
307 | |
---|
308 | /** |
---|
309 | * Output |
---|
310 | * |
---|
311 | * Outputs script directly |
---|
312 | * |
---|
313 | * @access private |
---|
314 | * @param string The element to attach the event to |
---|
315 | * @param string The code to execute |
---|
316 | * @return string |
---|
317 | */ |
---|
318 | function _output($array_js = '') |
---|
319 | { |
---|
320 | if ( ! is_array($array_js)) |
---|
321 | { |
---|
322 | $array_js = array($array_js); |
---|
323 | } |
---|
324 | |
---|
325 | foreach ($array_js as $js) |
---|
326 | { |
---|
327 | $this->jquery_code_for_compile[] = "\t$js\n"; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | // -------------------------------------------------------------------- |
---|
332 | |
---|
333 | /** |
---|
334 | * Resize |
---|
335 | * |
---|
336 | * Outputs a jQuery resize event |
---|
337 | * |
---|
338 | * @access private |
---|
339 | * @param string The element to attach the event to |
---|
340 | * @param string The code to execute |
---|
341 | * @return string |
---|
342 | */ |
---|
343 | function _resize($element = 'this', $js = '') |
---|
344 | { |
---|
345 | return $this->_add_event($element, $js, 'resize'); |
---|
346 | } |
---|
347 | |
---|
348 | // -------------------------------------------------------------------- |
---|
349 | |
---|
350 | /** |
---|
351 | * Scroll |
---|
352 | * |
---|
353 | * Outputs a jQuery scroll event |
---|
354 | * |
---|
355 | * @access private |
---|
356 | * @param string The element to attach the event to |
---|
357 | * @param string The code to execute |
---|
358 | * @return string |
---|
359 | */ |
---|
360 | function _scroll($element = 'this', $js = '') |
---|
361 | { |
---|
362 | return $this->_add_event($element, $js, 'scroll'); |
---|
363 | } |
---|
364 | |
---|
365 | // -------------------------------------------------------------------- |
---|
366 | |
---|
367 | /** |
---|
368 | * Unload |
---|
369 | * |
---|
370 | * Outputs a jQuery unload event |
---|
371 | * |
---|
372 | * @access private |
---|
373 | * @param string The element to attach the event to |
---|
374 | * @param string The code to execute |
---|
375 | * @return string |
---|
376 | */ |
---|
377 | function _unload($element = 'this', $js = '') |
---|
378 | { |
---|
379 | return $this->_add_event($element, $js, 'unload'); |
---|
380 | } |
---|
381 | |
---|
382 | // -------------------------------------------------------------------- |
---|
383 | // Effects |
---|
384 | // -------------------------------------------------------------------- |
---|
385 | |
---|
386 | /** |
---|
387 | * Add Class |
---|
388 | * |
---|
389 | * Outputs a jQuery addClass event |
---|
390 | * |
---|
391 | * @access private |
---|
392 | * @param string - element |
---|
393 | * @return string |
---|
394 | */ |
---|
395 | function _addClass($element = 'this', $class='') |
---|
396 | { |
---|
397 | $element = $this->_prep_element($element); |
---|
398 | $str = "$({$element}).addClass(\"$class\");"; |
---|
399 | return $str; |
---|
400 | } |
---|
401 | |
---|
402 | // -------------------------------------------------------------------- |
---|
403 | |
---|
404 | /** |
---|
405 | * Animate |
---|
406 | * |
---|
407 | * Outputs a jQuery animate event |
---|
408 | * |
---|
409 | * @access private |
---|
410 | * @param string - element |
---|
411 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
412 | * @param string - Javascript callback function |
---|
413 | * @return string |
---|
414 | */ |
---|
415 | function _animate($element = 'this', $params = array(), $speed = '', $extra = '') |
---|
416 | { |
---|
417 | $element = $this->_prep_element($element); |
---|
418 | $speed = $this->_validate_speed($speed); |
---|
419 | |
---|
420 | $animations = "\t\t\t"; |
---|
421 | |
---|
422 | foreach ($params as $param=>$value) |
---|
423 | { |
---|
424 | $animations .= $param.': \''.$value.'\', '; |
---|
425 | } |
---|
426 | |
---|
427 | $animations = substr($animations, 0, -2); // remove the last ", " |
---|
428 | |
---|
429 | if ($speed != '') |
---|
430 | { |
---|
431 | $speed = ', '.$speed; |
---|
432 | } |
---|
433 | |
---|
434 | if ($extra != '') |
---|
435 | { |
---|
436 | $extra = ', '.$extra; |
---|
437 | } |
---|
438 | |
---|
439 | $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
---|
440 | |
---|
441 | return $str; |
---|
442 | } |
---|
443 | |
---|
444 | // -------------------------------------------------------------------- |
---|
445 | |
---|
446 | /** |
---|
447 | * Fade In |
---|
448 | * |
---|
449 | * Outputs a jQuery hide event |
---|
450 | * |
---|
451 | * @access private |
---|
452 | * @param string - element |
---|
453 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
454 | * @param string - Javascript callback function |
---|
455 | * @return string |
---|
456 | */ |
---|
457 | function _fadeIn($element = 'this', $speed = '', $callback = '') |
---|
458 | { |
---|
459 | $element = $this->_prep_element($element); |
---|
460 | $speed = $this->_validate_speed($speed); |
---|
461 | |
---|
462 | if ($callback != '') |
---|
463 | { |
---|
464 | $callback = ", function(){\n{$callback}\n}"; |
---|
465 | } |
---|
466 | |
---|
467 | $str = "$({$element}).fadeIn({$speed}{$callback});"; |
---|
468 | |
---|
469 | return $str; |
---|
470 | } |
---|
471 | |
---|
472 | // -------------------------------------------------------------------- |
---|
473 | |
---|
474 | /** |
---|
475 | * Fade Out |
---|
476 | * |
---|
477 | * Outputs a jQuery hide event |
---|
478 | * |
---|
479 | * @access private |
---|
480 | * @param string - element |
---|
481 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
482 | * @param string - Javascript callback function |
---|
483 | * @return string |
---|
484 | */ |
---|
485 | function _fadeOut($element = 'this', $speed = '', $callback = '') |
---|
486 | { |
---|
487 | $element = $this->_prep_element($element); |
---|
488 | $speed = $this->_validate_speed($speed); |
---|
489 | |
---|
490 | if ($callback != '') |
---|
491 | { |
---|
492 | $callback = ", function(){\n{$callback}\n}"; |
---|
493 | } |
---|
494 | |
---|
495 | $str = "$({$element}).fadeOut({$speed}{$callback});"; |
---|
496 | |
---|
497 | return $str; |
---|
498 | } |
---|
499 | |
---|
500 | // -------------------------------------------------------------------- |
---|
501 | |
---|
502 | /** |
---|
503 | * Hide |
---|
504 | * |
---|
505 | * Outputs a jQuery hide action |
---|
506 | * |
---|
507 | * @access private |
---|
508 | * @param string - element |
---|
509 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
510 | * @param string - Javascript callback function |
---|
511 | * @return string |
---|
512 | */ |
---|
513 | function _hide($element = 'this', $speed = '', $callback = '') |
---|
514 | { |
---|
515 | $element = $this->_prep_element($element); |
---|
516 | $speed = $this->_validate_speed($speed); |
---|
517 | |
---|
518 | if ($callback != '') |
---|
519 | { |
---|
520 | $callback = ", function(){\n{$callback}\n}"; |
---|
521 | } |
---|
522 | |
---|
523 | $str = "$({$element}).hide({$speed}{$callback});"; |
---|
524 | |
---|
525 | return $str; |
---|
526 | } |
---|
527 | |
---|
528 | // -------------------------------------------------------------------- |
---|
529 | |
---|
530 | /** |
---|
531 | * Remove Class |
---|
532 | * |
---|
533 | * Outputs a jQuery remove class event |
---|
534 | * |
---|
535 | * @access private |
---|
536 | * @param string - element |
---|
537 | * @return string |
---|
538 | */ |
---|
539 | function _removeClass($element = 'this', $class='') |
---|
540 | { |
---|
541 | $element = $this->_prep_element($element); |
---|
542 | $str = "$({$element}).removeClass(\"$class\");"; |
---|
543 | return $str; |
---|
544 | } |
---|
545 | |
---|
546 | // -------------------------------------------------------------------- |
---|
547 | |
---|
548 | /** |
---|
549 | * Slide Up |
---|
550 | * |
---|
551 | * Outputs a jQuery slideUp event |
---|
552 | * |
---|
553 | * @access private |
---|
554 | * @param string - element |
---|
555 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
556 | * @param string - Javascript callback function |
---|
557 | * @return string |
---|
558 | */ |
---|
559 | function _slideUp($element = 'this', $speed = '', $callback = '') |
---|
560 | { |
---|
561 | $element = $this->_prep_element($element); |
---|
562 | $speed = $this->_validate_speed($speed); |
---|
563 | |
---|
564 | if ($callback != '') |
---|
565 | { |
---|
566 | $callback = ", function(){\n{$callback}\n}"; |
---|
567 | } |
---|
568 | |
---|
569 | $str = "$({$element}).slideUp({$speed}{$callback});"; |
---|
570 | |
---|
571 | return $str; |
---|
572 | } |
---|
573 | |
---|
574 | // -------------------------------------------------------------------- |
---|
575 | |
---|
576 | /** |
---|
577 | * Slide Down |
---|
578 | * |
---|
579 | * Outputs a jQuery slideDown event |
---|
580 | * |
---|
581 | * @access private |
---|
582 | * @param string - element |
---|
583 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
584 | * @param string - Javascript callback function |
---|
585 | * @return string |
---|
586 | */ |
---|
587 | function _slideDown($element = 'this', $speed = '', $callback = '') |
---|
588 | { |
---|
589 | $element = $this->_prep_element($element); |
---|
590 | $speed = $this->_validate_speed($speed); |
---|
591 | |
---|
592 | if ($callback != '') |
---|
593 | { |
---|
594 | $callback = ", function(){\n{$callback}\n}"; |
---|
595 | } |
---|
596 | |
---|
597 | $str = "$({$element}).slideDown({$speed}{$callback});"; |
---|
598 | |
---|
599 | return $str; |
---|
600 | } |
---|
601 | |
---|
602 | // -------------------------------------------------------------------- |
---|
603 | |
---|
604 | /** |
---|
605 | * Slide Toggle |
---|
606 | * |
---|
607 | * Outputs a jQuery slideToggle event |
---|
608 | * |
---|
609 | * @access public |
---|
610 | * @param string - element |
---|
611 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
612 | * @param string - Javascript callback function |
---|
613 | * @return string |
---|
614 | */ |
---|
615 | function _slideToggle($element = 'this', $speed = '', $callback = '') |
---|
616 | { |
---|
617 | $element = $this->_prep_element($element); |
---|
618 | $speed = $this->_validate_speed($speed); |
---|
619 | |
---|
620 | if ($callback != '') |
---|
621 | { |
---|
622 | $callback = ", function(){\n{$callback}\n}"; |
---|
623 | } |
---|
624 | |
---|
625 | $str = "$({$element}).slideToggle({$speed}{$callback});"; |
---|
626 | |
---|
627 | return $str; |
---|
628 | } |
---|
629 | |
---|
630 | // -------------------------------------------------------------------- |
---|
631 | |
---|
632 | /** |
---|
633 | * Toggle |
---|
634 | * |
---|
635 | * Outputs a jQuery toggle event |
---|
636 | * |
---|
637 | * @access private |
---|
638 | * @param string - element |
---|
639 | * @return string |
---|
640 | */ |
---|
641 | function _toggle($element = 'this') |
---|
642 | { |
---|
643 | $element = $this->_prep_element($element); |
---|
644 | $str = "$({$element}).toggle();"; |
---|
645 | return $str; |
---|
646 | } |
---|
647 | |
---|
648 | // -------------------------------------------------------------------- |
---|
649 | |
---|
650 | /** |
---|
651 | * Toggle Class |
---|
652 | * |
---|
653 | * Outputs a jQuery toggle class event |
---|
654 | * |
---|
655 | * @access private |
---|
656 | * @param string - element |
---|
657 | * @return string |
---|
658 | */ |
---|
659 | function _toggleClass($element = 'this', $class='') |
---|
660 | { |
---|
661 | $element = $this->_prep_element($element); |
---|
662 | $str = "$({$element}).toggleClass(\"$class\");"; |
---|
663 | return $str; |
---|
664 | } |
---|
665 | |
---|
666 | // -------------------------------------------------------------------- |
---|
667 | |
---|
668 | /** |
---|
669 | * Show |
---|
670 | * |
---|
671 | * Outputs a jQuery show event |
---|
672 | * |
---|
673 | * @access private |
---|
674 | * @param string - element |
---|
675 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
---|
676 | * @param string - Javascript callback function |
---|
677 | * @return string |
---|
678 | */ |
---|
679 | function _show($element = 'this', $speed = '', $callback = '') |
---|
680 | { |
---|
681 | $element = $this->_prep_element($element); |
---|
682 | $speed = $this->_validate_speed($speed); |
---|
683 | |
---|
684 | if ($callback != '') |
---|
685 | { |
---|
686 | $callback = ", function(){\n{$callback}\n}"; |
---|
687 | } |
---|
688 | |
---|
689 | $str = "$({$element}).show({$speed}{$callback});"; |
---|
690 | |
---|
691 | return $str; |
---|
692 | } |
---|
693 | |
---|
694 | // -------------------------------------------------------------------- |
---|
695 | |
---|
696 | /** |
---|
697 | * Updater |
---|
698 | * |
---|
699 | * An Ajax call that populates the designated DOM node with |
---|
700 | * returned content |
---|
701 | * |
---|
702 | * @access private |
---|
703 | * @param string The element to attach the event to |
---|
704 | * @param string the controller to run the call against |
---|
705 | * @param string optional parameters |
---|
706 | * @return string |
---|
707 | */ |
---|
708 | |
---|
709 | function _updater($container = 'this', $controller, $options = '') |
---|
710 | { |
---|
711 | $container = $this->_prep_element($container); |
---|
712 | |
---|
713 | $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); |
---|
714 | |
---|
715 | // ajaxStart and ajaxStop are better choices here... but this is a stop gap |
---|
716 | if ($this->CI->config->item('javascript_ajax_img') == '') |
---|
717 | { |
---|
718 | $loading_notifier = "Loading..."; |
---|
719 | } |
---|
720 | else |
---|
721 | { |
---|
722 | $loading_notifier = '<img src=\'' . $this->CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />'; |
---|
723 | } |
---|
724 | |
---|
725 | $updater = "$($container).empty();\n"; // anything that was in... get it out |
---|
726 | $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image |
---|
727 | |
---|
728 | $request_options = ''; |
---|
729 | if ($options != '') |
---|
730 | { |
---|
731 | $request_options .= ", {"; |
---|
732 | $request_options .= (is_array($options)) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'"; |
---|
733 | $request_options .= "}"; |
---|
734 | } |
---|
735 | |
---|
736 | $updater .= "\t\t$($container).load('$controller'$request_options);"; |
---|
737 | return $updater; |
---|
738 | } |
---|
739 | |
---|
740 | |
---|
741 | // -------------------------------------------------------------------- |
---|
742 | // Pre-written handy stuff |
---|
743 | // -------------------------------------------------------------------- |
---|
744 | |
---|
745 | /** |
---|
746 | * Zebra tables |
---|
747 | * |
---|
748 | * @access private |
---|
749 | * @param string table name |
---|
750 | * @param string plugin location |
---|
751 | * @return string |
---|
752 | */ |
---|
753 | function _zebraTables($class = '', $odd = 'odd', $hover = '') |
---|
754 | { |
---|
755 | $class = ($class != '') ? '.'.$class : ''; |
---|
756 | |
---|
757 | $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; |
---|
758 | |
---|
759 | $this->jquery_code_for_compile[] = $zebra; |
---|
760 | |
---|
761 | if ($hover != '') |
---|
762 | { |
---|
763 | $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); |
---|
764 | } |
---|
765 | |
---|
766 | return $zebra; |
---|
767 | } |
---|
768 | |
---|
769 | |
---|
770 | |
---|
771 | // -------------------------------------------------------------------- |
---|
772 | // Plugins |
---|
773 | // -------------------------------------------------------------------- |
---|
774 | |
---|
775 | /** |
---|
776 | * Corner Plugin |
---|
777 | * |
---|
778 | * http://www.malsup.com/jquery/corner/ |
---|
779 | * |
---|
780 | * @access public |
---|
781 | * @param string target |
---|
782 | * @return string |
---|
783 | */ |
---|
784 | function corner($element = '', $corner_style = '') |
---|
785 | { |
---|
786 | // may want to make this configurable down the road |
---|
787 | $corner_location = '/plugins/jquery.corner.js'; |
---|
788 | |
---|
789 | if ($corner_style != '') |
---|
790 | { |
---|
791 | $corner_style = '"'.$corner_style.'"'; |
---|
792 | } |
---|
793 | |
---|
794 | return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; |
---|
795 | } |
---|
796 | |
---|
797 | // -------------------------------------------------------------------- |
---|
798 | |
---|
799 | /** |
---|
800 | * modal window |
---|
801 | * |
---|
802 | * Load a thickbox modal window |
---|
803 | * |
---|
804 | * @access public |
---|
805 | * @return void |
---|
806 | */ |
---|
807 | function modal($src, $relative = FALSE) |
---|
808 | { |
---|
809 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
---|
810 | } |
---|
811 | |
---|
812 | // -------------------------------------------------------------------- |
---|
813 | |
---|
814 | /** |
---|
815 | * Effect |
---|
816 | * |
---|
817 | * Load an Effect library |
---|
818 | * |
---|
819 | * @access public |
---|
820 | * @return void |
---|
821 | */ |
---|
822 | function effect($src, $relative = FALSE) |
---|
823 | { |
---|
824 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
---|
825 | } |
---|
826 | |
---|
827 | // -------------------------------------------------------------------- |
---|
828 | |
---|
829 | /** |
---|
830 | * Plugin |
---|
831 | * |
---|
832 | * Load a plugin library |
---|
833 | * |
---|
834 | * @access public |
---|
835 | * @return void |
---|
836 | */ |
---|
837 | function plugin($src, $relative = FALSE) |
---|
838 | { |
---|
839 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
---|
840 | } |
---|
841 | |
---|
842 | // -------------------------------------------------------------------- |
---|
843 | |
---|
844 | /** |
---|
845 | * UI |
---|
846 | * |
---|
847 | * Load a user interface library |
---|
848 | * |
---|
849 | * @access public |
---|
850 | * @return void |
---|
851 | */ |
---|
852 | function ui($src, $relative = FALSE) |
---|
853 | { |
---|
854 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
---|
855 | } |
---|
856 | // -------------------------------------------------------------------- |
---|
857 | |
---|
858 | /** |
---|
859 | * Sortable |
---|
860 | * |
---|
861 | * Creates a jQuery sortable |
---|
862 | * |
---|
863 | * @access public |
---|
864 | * @return void |
---|
865 | */ |
---|
866 | function sortable($element, $options = array()) |
---|
867 | { |
---|
868 | |
---|
869 | if (count($options) > 0) |
---|
870 | { |
---|
871 | $sort_options = array(); |
---|
872 | foreach ($options as $k=>$v) |
---|
873 | { |
---|
874 | $sort_options[] = "\n\t\t".$k.': '.$v.""; |
---|
875 | } |
---|
876 | $sort_options = implode(",", $sort_options); |
---|
877 | } |
---|
878 | else |
---|
879 | { |
---|
880 | $sort_options = ''; |
---|
881 | } |
---|
882 | |
---|
883 | return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});"; |
---|
884 | } |
---|
885 | |
---|
886 | // -------------------------------------------------------------------- |
---|
887 | |
---|
888 | /** |
---|
889 | * Table Sorter Plugin |
---|
890 | * |
---|
891 | * @access public |
---|
892 | * @param string table name |
---|
893 | * @param string plugin location |
---|
894 | * @return string |
---|
895 | */ |
---|
896 | function tablesorter($table = '', $options = '') |
---|
897 | { |
---|
898 | $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; |
---|
899 | } |
---|
900 | |
---|
901 | // -------------------------------------------------------------------- |
---|
902 | // Class functions |
---|
903 | // -------------------------------------------------------------------- |
---|
904 | |
---|
905 | /** |
---|
906 | * Add Event |
---|
907 | * |
---|
908 | * Constructs the syntax for an event, and adds to into the array for compilation |
---|
909 | * |
---|
910 | * @access private |
---|
911 | * @param string The element to attach the event to |
---|
912 | * @param string The code to execute |
---|
913 | * @param string The event to pass |
---|
914 | * @return string |
---|
915 | */ |
---|
916 | function _add_event($element, $js, $event) |
---|
917 | { |
---|
918 | if (is_array($js)) |
---|
919 | { |
---|
920 | $js = implode("\n\t\t", $js); |
---|
921 | |
---|
922 | } |
---|
923 | |
---|
924 | $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n"; |
---|
925 | $this->jquery_code_for_compile[] = $event; |
---|
926 | return $event; |
---|
927 | } |
---|
928 | |
---|
929 | // -------------------------------------------------------------------- |
---|
930 | |
---|
931 | /** |
---|
932 | * Compile |
---|
933 | * |
---|
934 | * As events are specified, they are stored in an array |
---|
935 | * This funciton compiles them all for output on a page |
---|
936 | * |
---|
937 | * @access private |
---|
938 | * @return string |
---|
939 | */ |
---|
940 | function _compile($view_var = 'script_foot', $script_tags = TRUE) |
---|
941 | { |
---|
942 | // External references |
---|
943 | $external_scripts = implode('', $this->jquery_code_for_load); |
---|
944 | $this->CI->load->vars(array('library_src' => $external_scripts)); |
---|
945 | |
---|
946 | if (count($this->jquery_code_for_compile) == 0 ) |
---|
947 | { |
---|
948 | // no inline references, let's just return |
---|
949 | return; |
---|
950 | } |
---|
951 | |
---|
952 | // Inline references |
---|
953 | $script = '$(document).ready(function() {' . "\n"; |
---|
954 | $script .= implode('', $this->jquery_code_for_compile); |
---|
955 | $script .= '});'; |
---|
956 | |
---|
957 | $output = ($script_tags === FALSE) ? $script : $this->inline($script); |
---|
958 | |
---|
959 | $this->CI->load->vars(array($view_var => $output)); |
---|
960 | |
---|
961 | } |
---|
962 | |
---|
963 | // -------------------------------------------------------------------- |
---|
964 | |
---|
965 | /** |
---|
966 | * Clear Compile |
---|
967 | * |
---|
968 | * Clears the array of script events collected for output |
---|
969 | * |
---|
970 | * @access public |
---|
971 | * @return void |
---|
972 | */ |
---|
973 | function _clear_compile() |
---|
974 | { |
---|
975 | $this->jquery_code_for_compile = array(); |
---|
976 | } |
---|
977 | |
---|
978 | // -------------------------------------------------------------------- |
---|
979 | |
---|
980 | /** |
---|
981 | * Document Ready |
---|
982 | * |
---|
983 | * A wrapper for writing document.ready() |
---|
984 | * |
---|
985 | * @access private |
---|
986 | * @return string |
---|
987 | */ |
---|
988 | function _document_ready($js) |
---|
989 | { |
---|
990 | if ( ! is_array($js)) |
---|
991 | { |
---|
992 | $js = array ($js); |
---|
993 | |
---|
994 | } |
---|
995 | |
---|
996 | foreach ($js as $script) |
---|
997 | { |
---|
998 | $this->jquery_code_for_compile[] = $script; |
---|
999 | } |
---|
1000 | } |
---|
1001 | |
---|
1002 | // -------------------------------------------------------------------- |
---|
1003 | |
---|
1004 | /** |
---|
1005 | * Script Tag |
---|
1006 | * |
---|
1007 | * Outputs the script tag that loads the jquery.js file into an HTML document |
---|
1008 | * |
---|
1009 | * @access public |
---|
1010 | * @param string |
---|
1011 | * @return string |
---|
1012 | */ |
---|
1013 | function script($library_src = '', $relative = FALSE) |
---|
1014 | { |
---|
1015 | $library_src = $this->external($library_src, $relative); |
---|
1016 | $this->jquery_code_for_load[] = $library_src; |
---|
1017 | return $library_src; |
---|
1018 | } |
---|
1019 | |
---|
1020 | // -------------------------------------------------------------------- |
---|
1021 | |
---|
1022 | /** |
---|
1023 | * Prep Element |
---|
1024 | * |
---|
1025 | * Puts HTML element in quotes for use in jQuery code |
---|
1026 | * unless the supplied element is the Javascript 'this' |
---|
1027 | * object, in which case no quotes are added |
---|
1028 | * |
---|
1029 | * @access public |
---|
1030 | * @param string |
---|
1031 | * @return string |
---|
1032 | */ |
---|
1033 | function _prep_element($element) |
---|
1034 | { |
---|
1035 | if ($element != 'this') |
---|
1036 | { |
---|
1037 | $element = '"'.$element.'"'; |
---|
1038 | } |
---|
1039 | |
---|
1040 | return $element; |
---|
1041 | } |
---|
1042 | |
---|
1043 | // -------------------------------------------------------------------- |
---|
1044 | |
---|
1045 | /** |
---|
1046 | * Validate Speed |
---|
1047 | * |
---|
1048 | * Ensures the speed parameter is valid for jQuery |
---|
1049 | * |
---|
1050 | * @access private |
---|
1051 | * @param string |
---|
1052 | * @return string |
---|
1053 | */ |
---|
1054 | function _validate_speed($speed) |
---|
1055 | { |
---|
1056 | if (in_array($speed, array('slow', 'normal', 'fast'))) |
---|
1057 | { |
---|
1058 | $speed = '"'.$speed.'"'; |
---|
1059 | } |
---|
1060 | elseif (preg_match("/[^0-9]/", $speed)) |
---|
1061 | { |
---|
1062 | $speed = ''; |
---|
1063 | } |
---|
1064 | |
---|
1065 | return $speed; |
---|
1066 | } |
---|
1067 | |
---|
1068 | } |
---|
1069 | |
---|
1070 | /* End of file Jquery.php */ |
---|
1071 | /* Location: ./system/libraries/Jquery.php */ |
---|