blob: ab78e8b2e184cdadee82839dc14ea1917578889f [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Jones811f4752010-03-02 18:13:59 -06002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Jonesf4a4bd82011-10-20 12:18:42 -05006 *
7 * NOTICE OF LICENSE
Andrey Andreevad47f942011-12-25 19:13:48 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevad47f942011-12-25 19:13:48 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
Derek Jones811f4752010-03-02 18:13:59 -060018 *
19 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
Derek Jones811f4752010-03-02 18:13:59 -060024 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Jones811f4752010-03-02 18:13:59 -060028
29/**
30 * Jquery Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
Derek Jones811f4752010-03-02 18:13:59 -060034 * @category Loader
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
36 * @link http://codeigniter.com/user_guide/libraries/javascript.html
Derek Jones811f4752010-03-02 18:13:59 -060037 */
Greg Akeraacfe482010-03-03 12:26:31 -060038class CI_Jquery extends CI_Javascript {
Derek Jones811f4752010-03-02 18:13:59 -060039
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020040 /**
41 * JavaScript directory location
42 *
43 * @var string
44 */
Andrey Andreevad47f942011-12-25 19:13:48 +020045 protected $_javascript_folder = 'js';
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020046
47 /**
48 * JQuery code for load
49 *
50 * @var array
51 */
Andrey Andreevad47f942011-12-25 19:13:48 +020052 public $jquery_code_for_load = array();
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020053
54 /**
55 * JQuery code for compile
56 *
57 * @var array
58 */
Andrey Andreevad47f942011-12-25 19:13:48 +020059 public $jquery_code_for_compile = array();
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020060
61 /**
62 * JQuery corner active flag
63 *
64 * @var bool
65 */
Andrey Andreevad47f942011-12-25 19:13:48 +020066 public $jquery_corner_active = FALSE;
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020067
68 /**
69 * JQuery table sorter active flag
70 *
71 * @var bool
72 */
Andrey Andreevad47f942011-12-25 19:13:48 +020073 public $jquery_table_sorter_active = FALSE;
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020074
75 /**
76 * JQuery table sorder pager active
77 *
78 * @var bool
79 */
Andrey Andreevad47f942011-12-25 19:13:48 +020080 public $jquery_table_sorter_pager_active = FALSE;
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020081
82 /**
83 * JQuery AJAX image
84 *
85 * @var string
86 */
Andrey Andreevad47f942011-12-25 19:13:48 +020087 public $jquery_ajax_img = '';
Derek Jones811f4752010-03-02 18:13:59 -060088
Andrey Andreev0fa95bd2012-11-01 23:33:14 +020089 // --------------------------------------------------------------------
90
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030091 /**
92 * Constructor
93 *
94 * @param array $params
95 * @return void
96 */
Greg Akera9263282010-11-10 15:26:43 -060097 public function __construct($params)
Derek Jones811f4752010-03-02 18:13:59 -060098 {
Andrey Andreevad47f942011-12-25 19:13:48 +020099 $this->CI =& get_instance();
Derek Jones811f4752010-03-02 18:13:59 -0600100 extract($params);
101
102 if ($autoload === TRUE)
103 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200104 $this->script();
Derek Jones811f4752010-03-02 18:13:59 -0600105 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200106
Andrey Andreev56454792012-05-17 14:32:19 +0300107 log_message('debug', 'Jquery Class Initialized');
Derek Jones811f4752010-03-02 18:13:59 -0600108 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200109
110 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600111 // Event Code
Andrey Andreevad47f942011-12-25 19:13:48 +0200112 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600113
114 /**
115 * Blur
116 *
117 * Outputs a jQuery blur event
118 *
Derek Jones811f4752010-03-02 18:13:59 -0600119 * @param string The element to attach the event to
120 * @param string The code to execute
121 * @return string
122 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200123 protected function _blur($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600124 {
125 return $this->_add_event($element, $js, 'blur');
126 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200127
Derek Jones811f4752010-03-02 18:13:59 -0600128 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200129
Derek Jones811f4752010-03-02 18:13:59 -0600130 /**
131 * Change
132 *
133 * Outputs a jQuery change event
134 *
Derek Jones811f4752010-03-02 18:13:59 -0600135 * @param string The element to attach the event to
136 * @param string The code to execute
137 * @return string
138 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200139 protected function _change($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600140 {
141 return $this->_add_event($element, $js, 'change');
142 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200143
Derek Jones811f4752010-03-02 18:13:59 -0600144 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200145
Derek Jones811f4752010-03-02 18:13:59 -0600146 /**
147 * Click
148 *
149 * Outputs a jQuery click event
150 *
Derek Jones811f4752010-03-02 18:13:59 -0600151 * @param string The element to attach the event to
152 * @param string The code to execute
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300153 * @param bool whether or not to return false
Derek Jones811f4752010-03-02 18:13:59 -0600154 * @return string
155 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200156 protected function _click($element = 'this', $js = '', $ret_false = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600157 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300158 is_array($js) OR $js = array($js);
Derek Jones811f4752010-03-02 18:13:59 -0600159
160 if ($ret_false)
161 {
Andrey Andreev56454792012-05-17 14:32:19 +0300162 $js[] = 'return false;';
Derek Jones811f4752010-03-02 18:13:59 -0600163 }
164
165 return $this->_add_event($element, $js, 'click');
166 }
167
168 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200169
Derek Jones811f4752010-03-02 18:13:59 -0600170 /**
171 * Double Click
172 *
173 * Outputs a jQuery dblclick event
174 *
Derek Jones811f4752010-03-02 18:13:59 -0600175 * @param string The element to attach the event to
176 * @param string The code to execute
177 * @return string
178 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200179 protected function _dblclick($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600180 {
181 return $this->_add_event($element, $js, 'dblclick');
182 }
183
184 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200185
Derek Jones811f4752010-03-02 18:13:59 -0600186 /**
187 * Error
188 *
189 * Outputs a jQuery error event
190 *
Derek Jones811f4752010-03-02 18:13:59 -0600191 * @param string The element to attach the event to
192 * @param string The code to execute
193 * @return string
194 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200195 protected function _error($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600196 {
197 return $this->_add_event($element, $js, 'error');
198 }
199
200 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200201
Derek Jones811f4752010-03-02 18:13:59 -0600202 /**
203 * Focus
204 *
205 * Outputs a jQuery focus event
206 *
Derek Jones811f4752010-03-02 18:13:59 -0600207 * @param string The element to attach the event to
208 * @param string The code to execute
209 * @return string
210 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200211 protected function _focus($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600212 {
213 return $this->_add_event($element, $js, 'focus');
214 }
215
216 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200217
Derek Jones811f4752010-03-02 18:13:59 -0600218 /**
219 * Hover
220 *
221 * Outputs a jQuery hover event
222 *
Derek Jones811f4752010-03-02 18:13:59 -0600223 * @param string - element
224 * @param string - Javascript code for mouse over
225 * @param string - Javascript code for mouse out
Barry Mienydd671972010-10-04 16:33:58 +0200226 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600227 */
Rasmus Lerdorf0a6a88a2013-05-18 10:26:21 -0400228 protected function _hover($element = 'this', $over = '', $out = '')
Derek Jones811f4752010-03-02 18:13:59 -0600229 {
Andrey Andreev56454792012-05-17 14:32:19 +0300230 $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";
Derek Jones811f4752010-03-02 18:13:59 -0600231
232 $this->jquery_code_for_compile[] = $event;
233
234 return $event;
235 }
236
237 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200238
Derek Jones811f4752010-03-02 18:13:59 -0600239 /**
240 * Keydown
241 *
242 * Outputs a jQuery keydown event
243 *
Derek Jones811f4752010-03-02 18:13:59 -0600244 * @param string The element to attach the event to
245 * @param string The code to execute
246 * @return string
247 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200248 protected function _keydown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600249 {
250 return $this->_add_event($element, $js, 'keydown');
251 }
252
253 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200254
Derek Jones811f4752010-03-02 18:13:59 -0600255 /**
256 * Keyup
257 *
258 * Outputs a jQuery keydown event
259 *
Derek Jones811f4752010-03-02 18:13:59 -0600260 * @param string The element to attach the event to
261 * @param string The code to execute
262 * @return string
263 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200264 protected function _keyup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600265 {
266 return $this->_add_event($element, $js, 'keyup');
Andrey Andreevad47f942011-12-25 19:13:48 +0200267 }
Derek Jones811f4752010-03-02 18:13:59 -0600268
269 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200270
Derek Jones811f4752010-03-02 18:13:59 -0600271 /**
272 * Load
273 *
274 * Outputs a jQuery load event
275 *
Derek Jones811f4752010-03-02 18:13:59 -0600276 * @param string The element to attach the event to
277 * @param string The code to execute
278 * @return string
279 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200280 protected function _load($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600281 {
282 return $this->_add_event($element, $js, 'load');
Andrey Andreevad47f942011-12-25 19:13:48 +0200283 }
284
Derek Jones811f4752010-03-02 18:13:59 -0600285 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200286
Derek Jones811f4752010-03-02 18:13:59 -0600287 /**
288 * Mousedown
289 *
290 * Outputs a jQuery mousedown event
291 *
Derek Jones811f4752010-03-02 18:13:59 -0600292 * @param string The element to attach the event to
293 * @param string The code to execute
294 * @return string
295 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200296 protected function _mousedown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600297 {
298 return $this->_add_event($element, $js, 'mousedown');
299 }
300
301 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200302
Derek Jones811f4752010-03-02 18:13:59 -0600303 /**
304 * Mouse Out
305 *
306 * Outputs a jQuery mouseout event
307 *
Derek Jones811f4752010-03-02 18:13:59 -0600308 * @param string The element to attach the event to
309 * @param string The code to execute
310 * @return string
311 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200312 protected function _mouseout($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600313 {
314 return $this->_add_event($element, $js, 'mouseout');
315 }
316
317 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200318
Derek Jones811f4752010-03-02 18:13:59 -0600319 /**
320 * Mouse Over
321 *
322 * Outputs a jQuery mouseover event
323 *
Derek Jones811f4752010-03-02 18:13:59 -0600324 * @param string The element to attach the event to
325 * @param string The code to execute
326 * @return string
327 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200328 protected function _mouseover($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600329 {
330 return $this->_add_event($element, $js, 'mouseover');
331 }
332
333 // --------------------------------------------------------------------
334
335 /**
336 * Mouseup
337 *
338 * Outputs a jQuery mouseup event
339 *
Derek Jones811f4752010-03-02 18:13:59 -0600340 * @param string The element to attach the event to
341 * @param string The code to execute
342 * @return string
343 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200344 protected function _mouseup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600345 {
346 return $this->_add_event($element, $js, 'mouseup');
347 }
348
349 // --------------------------------------------------------------------
350
351 /**
352 * Output
353 *
354 * Outputs script directly
355 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300356 * @param array $array_js = array()
357 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600358 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300359 protected function _output($array_js = array())
Derek Jones811f4752010-03-02 18:13:59 -0600360 {
361 if ( ! is_array($array_js))
362 {
363 $array_js = array($array_js);
364 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200365
Derek Jones811f4752010-03-02 18:13:59 -0600366 foreach ($array_js as $js)
367 {
Andrey Andreev56454792012-05-17 14:32:19 +0300368 $this->jquery_code_for_compile[] = "\t".$js."\n";
Derek Jones811f4752010-03-02 18:13:59 -0600369 }
370 }
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Resize
376 *
377 * Outputs a jQuery resize event
378 *
Derek Jones811f4752010-03-02 18:13:59 -0600379 * @param string The element to attach the event to
380 * @param string The code to execute
381 * @return string
382 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200383 protected function _resize($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600384 {
385 return $this->_add_event($element, $js, 'resize');
386 }
387
388 // --------------------------------------------------------------------
389
390 /**
391 * Scroll
392 *
393 * Outputs a jQuery scroll event
394 *
Derek Jones811f4752010-03-02 18:13:59 -0600395 * @param string The element to attach the event to
396 * @param string The code to execute
397 * @return string
398 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200399 protected function _scroll($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600400 {
401 return $this->_add_event($element, $js, 'scroll');
402 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200403
Derek Jones811f4752010-03-02 18:13:59 -0600404 // --------------------------------------------------------------------
405
406 /**
407 * Unload
408 *
409 * Outputs a jQuery unload event
410 *
Derek Jones811f4752010-03-02 18:13:59 -0600411 * @param string The element to attach the event to
412 * @param string The code to execute
413 * @return string
414 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200415 protected function _unload($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600416 {
417 return $this->_add_event($element, $js, 'unload');
418 }
419
Andrey Andreevad47f942011-12-25 19:13:48 +0200420 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600421 // Effects
Andrey Andreevad47f942011-12-25 19:13:48 +0200422 // --------------------------------------------------------------------
423
Derek Jones811f4752010-03-02 18:13:59 -0600424 /**
425 * Add Class
426 *
427 * Outputs a jQuery addClass event
428 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200429 * @param string $element
430 * @param string $class
Barry Mienydd671972010-10-04 16:33:58 +0200431 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600432 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300433 protected function _addClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600434 {
435 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300436 return '$('.$element.').addClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600437 }
438
439 // --------------------------------------------------------------------
440
441 /**
442 * Animate
443 *
444 * Outputs a jQuery animate event
445 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200446 * @param string $element
447 * @param array $params
448 * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds
449 * @param string $extra
Barry Mienydd671972010-10-04 16:33:58 +0200450 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600451 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200452 protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
Derek Jones811f4752010-03-02 18:13:59 -0600453 {
454 $element = $this->_prep_element($element);
455 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200456
Derek Jones811f4752010-03-02 18:13:59 -0600457 $animations = "\t\t\t";
Andrey Andreevad47f942011-12-25 19:13:48 +0200458
Andrey Andreev56454792012-05-17 14:32:19 +0300459 foreach ($params as $param => $value)
Derek Jones811f4752010-03-02 18:13:59 -0600460 {
Andrey Andreev56454792012-05-17 14:32:19 +0300461 $animations .= $param.": '".$value."', ";
Derek Jones811f4752010-03-02 18:13:59 -0600462 }
463
464 $animations = substr($animations, 0, -2); // remove the last ", "
465
Alex Bilbied261b1e2012-06-02 11:12:16 +0100466 if ($speed !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600467 {
468 $speed = ', '.$speed;
469 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200470
Alex Bilbied261b1e2012-06-02 11:12:16 +0100471 if ($extra !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600472 {
473 $extra = ', '.$extra;
474 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200475
Andrey Andreev56454792012-05-17 14:32:19 +0300476 return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');';
Derek Jones811f4752010-03-02 18:13:59 -0600477 }
478
479 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200480
Derek Jones811f4752010-03-02 18:13:59 -0600481 /**
482 * Fade In
483 *
484 * Outputs a jQuery hide event
485 *
Derek Jones811f4752010-03-02 18:13:59 -0600486 * @param string - element
487 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
488 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200489 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600490 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200491 protected function _fadeIn($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600492 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200493 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600494 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200495
Alex Bilbied261b1e2012-06-02 11:12:16 +0100496 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600497 {
498 $callback = ", function(){\n{$callback}\n}";
499 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200500
501 return "$({$element}).fadeIn({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600502 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200503
Derek Jones811f4752010-03-02 18:13:59 -0600504 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200505
Derek Jones811f4752010-03-02 18:13:59 -0600506 /**
507 * Fade Out
508 *
509 * Outputs a jQuery hide event
510 *
Derek Jones811f4752010-03-02 18:13:59 -0600511 * @param string - element
512 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
513 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200514 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600515 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200516 protected function _fadeOut($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600517 {
518 $element = $this->_prep_element($element);
519 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200520
Alex Bilbied261b1e2012-06-02 11:12:16 +0100521 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600522 {
523 $callback = ", function(){\n{$callback}\n}";
524 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200525
Andrey Andreev56454792012-05-17 14:32:19 +0300526 return '$('.$element.').fadeOut('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600527 }
528
529 // --------------------------------------------------------------------
530
531 /**
532 * Hide
533 *
534 * Outputs a jQuery hide action
535 *
Derek Jones811f4752010-03-02 18:13:59 -0600536 * @param string - element
537 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
538 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200539 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600540 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200541 protected function _hide($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600542 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200543 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600544 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200545
Alex Bilbied261b1e2012-06-02 11:12:16 +0100546 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600547 {
548 $callback = ", function(){\n{$callback}\n}";
549 }
Derek Jones811f4752010-03-02 18:13:59 -0600550
Andrey Andreevad47f942011-12-25 19:13:48 +0200551 return "$({$element}).hide({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600552 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200553
Derek Jones811f4752010-03-02 18:13:59 -0600554 // --------------------------------------------------------------------
555
556 /**
557 * Remove Class
558 *
559 * Outputs a jQuery remove class event
560 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200561 * @param string $element
562 * @param string $class
Barry Mienydd671972010-10-04 16:33:58 +0200563 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600564 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300565 protected function _removeClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600566 {
567 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300568 return '$('.$element.').removeClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600569 }
570
571 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200572
Derek Jones811f4752010-03-02 18:13:59 -0600573 /**
574 * Slide Up
575 *
576 * Outputs a jQuery slideUp event
577 *
Derek Jones811f4752010-03-02 18:13:59 -0600578 * @param string - element
579 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
580 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200581 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600582 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200583 protected function _slideUp($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600584 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200585 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600586 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200587
Alex Bilbied261b1e2012-06-02 11:12:16 +0100588 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600589 {
590 $callback = ", function(){\n{$callback}\n}";
591 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200592
Andrey Andreev56454792012-05-17 14:32:19 +0300593 return '$('.$element.').slideUp('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600594 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200595
Derek Jones811f4752010-03-02 18:13:59 -0600596 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200597
Derek Jones811f4752010-03-02 18:13:59 -0600598 /**
599 * Slide Down
600 *
601 * Outputs a jQuery slideDown event
602 *
Derek Jones811f4752010-03-02 18:13:59 -0600603 * @param string - element
604 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
605 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200606 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600607 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200608 protected function _slideDown($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600609 {
610 $element = $this->_prep_element($element);
611 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200612
Alex Bilbied261b1e2012-06-02 11:12:16 +0100613 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600614 {
615 $callback = ", function(){\n{$callback}\n}";
616 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200617
Andrey Andreev56454792012-05-17 14:32:19 +0300618 return '$('.$element.').slideDown('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600619 }
620
621 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200622
Derek Jones811f4752010-03-02 18:13:59 -0600623 /**
624 * Slide Toggle
625 *
626 * Outputs a jQuery slideToggle event
627 *
Derek Jones811f4752010-03-02 18:13:59 -0600628 * @param string - element
629 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
630 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200631 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600632 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200633 protected function _slideToggle($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600634 {
635 $element = $this->_prep_element($element);
636 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200637
Alex Bilbied261b1e2012-06-02 11:12:16 +0100638 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600639 {
640 $callback = ", function(){\n{$callback}\n}";
641 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200642
Andrey Andreev56454792012-05-17 14:32:19 +0300643 return '$('.$element.').slideToggle('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600644 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200645
Derek Jones811f4752010-03-02 18:13:59 -0600646 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200647
Derek Jones811f4752010-03-02 18:13:59 -0600648 /**
649 * Toggle
650 *
651 * Outputs a jQuery toggle event
652 *
Derek Jones811f4752010-03-02 18:13:59 -0600653 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200654 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600655 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200656 protected function _toggle($element = 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600657 {
658 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300659 return '$('.$element.').toggle();';
Derek Jones811f4752010-03-02 18:13:59 -0600660 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200661
Derek Jones811f4752010-03-02 18:13:59 -0600662 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200663
Derek Jones811f4752010-03-02 18:13:59 -0600664 /**
665 * Toggle Class
666 *
667 * Outputs a jQuery toggle class event
668 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200669 * @param string $element
670 * @param string $class
Barry Mienydd671972010-10-04 16:33:58 +0200671 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600672 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300673 protected function _toggleClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600674 {
675 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300676 return '$('.$element.').toggleClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600677 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200678
Derek Jones811f4752010-03-02 18:13:59 -0600679 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200680
Derek Jones811f4752010-03-02 18:13:59 -0600681 /**
682 * Show
683 *
684 * Outputs a jQuery show event
685 *
Derek Jones811f4752010-03-02 18:13:59 -0600686 * @param string - element
687 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
688 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200689 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600690 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200691 protected function _show($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600692 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200693 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600694 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200695
Alex Bilbied261b1e2012-06-02 11:12:16 +0100696 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600697 {
698 $callback = ", function(){\n{$callback}\n}";
699 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200700
Andrey Andreev56454792012-05-17 14:32:19 +0300701 return '$('.$element.').show('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600702 }
703
704 // --------------------------------------------------------------------
705
706 /**
707 * Updater
708 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200709 * An Ajax call that populates the designated DOM node with
Derek Jones811f4752010-03-02 18:13:59 -0600710 * returned content
711 *
Derek Jones811f4752010-03-02 18:13:59 -0600712 * @param string The element to attach the event to
713 * @param string the controller to run the call against
714 * @param string optional parameters
715 * @return string
716 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200717
Rasmus Lerdorf0a6a88a2013-05-18 10:26:21 -0400718 protected function _updater($container = 'this', $controller = '', $options = '')
Andrey Andreevad47f942011-12-25 19:13:48 +0200719 {
Derek Jones811f4752010-03-02 18:13:59 -0600720 $container = $this->_prep_element($container);
Derek Jones811f4752010-03-02 18:13:59 -0600721 $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
Andrey Andreevad47f942011-12-25 19:13:48 +0200722
Derek Jones811f4752010-03-02 18:13:59 -0600723 // ajaxStart and ajaxStop are better choices here... but this is a stop gap
Alex Bilbied261b1e2012-06-02 11:12:16 +0100724 if ($this->CI->config->item('javascript_ajax_img') === '')
Derek Jones811f4752010-03-02 18:13:59 -0600725 {
Andrey Andreev56454792012-05-17 14:32:19 +0300726 $loading_notifier = 'Loading...';
Derek Jones811f4752010-03-02 18:13:59 -0600727 }
728 else
729 {
Andrey Andreev56454792012-05-17 14:32:19 +0300730 $loading_notifier = '<img src="'.$this->CI->config->slash_item('base_url').$this->CI->config->item('javascript_ajax_img').'" alt="Loading" />';
Derek Jones811f4752010-03-02 18:13:59 -0600731 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200732
Andrey Andreev56454792012-05-17 14:32:19 +0300733 $updater = '$('.$container.").empty();\n" // anything that was in... get it out
734 ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
Derek Jones811f4752010-03-02 18:13:59 -0600735
736 $request_options = '';
Alex Bilbied261b1e2012-06-02 11:12:16 +0100737 if ($options !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600738 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200739 $request_options .= ', {'
Andrey Andreev56454792012-05-17 14:32:19 +0300740 .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
741 .'}';
Derek Jones811f4752010-03-02 18:13:59 -0600742 }
743
Andrey Andreevad47f942011-12-25 19:13:48 +0200744 return $updater."\t\t$($container).load('$controller'$request_options);";
Derek Jones811f4752010-03-02 18:13:59 -0600745 }
746
Derek Jones811f4752010-03-02 18:13:59 -0600747 // --------------------------------------------------------------------
748 // Pre-written handy stuff
749 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200750
Derek Jones811f4752010-03-02 18:13:59 -0600751 /**
752 * Zebra tables
753 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200754 * @param string $class
755 * @param string $odd
756 * @param string $hover
Derek Jones811f4752010-03-02 18:13:59 -0600757 * @return string
758 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200759 protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
Derek Jones811f4752010-03-02 18:13:59 -0600760 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100761 $class = ($class !== '') ? '.'.$class : '';
vkeranovbfbe8b22012-10-27 18:25:08 +0300762 $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
Derek Jones811f4752010-03-02 18:13:59 -0600763
764 $this->jquery_code_for_compile[] = $zebra;
765
Alex Bilbied261b1e2012-06-02 11:12:16 +0100766 if ($hover !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600767 {
768 $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
769 }
770
771 return $zebra;
772 }
773
Derek Jones811f4752010-03-02 18:13:59 -0600774 // --------------------------------------------------------------------
775 // Plugins
776 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200777
Derek Jones811f4752010-03-02 18:13:59 -0600778 /**
779 * Corner Plugin
780 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200781 * @link http://www.malsup.com/jquery/corner/
782 * @param string $element
783 * @param string $corner_style
Derek Jones811f4752010-03-02 18:13:59 -0600784 * @return string
785 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200786 public function corner($element = '', $corner_style = '')
Derek Jones811f4752010-03-02 18:13:59 -0600787 {
788 // may want to make this configurable down the road
789 $corner_location = '/plugins/jquery.corner.js';
790
Alex Bilbied261b1e2012-06-02 11:12:16 +0100791 if ($corner_style !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600792 {
793 $corner_style = '"'.$corner_style.'"';
794 }
795
Andrey Andreev56454792012-05-17 14:32:19 +0300796 return '$('.$this->_prep_element($element).').corner('.$corner_style.');';
Derek Jones811f4752010-03-02 18:13:59 -0600797 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200798
Derek Jones811f4752010-03-02 18:13:59 -0600799 // --------------------------------------------------------------------
800
801 /**
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300802 * Modal window
Derek Jones811f4752010-03-02 18:13:59 -0600803 *
804 * Load a thickbox modal window
805 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300806 * @param string $src
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200807 * @param bool $relative
Derek Jones811f4752010-03-02 18:13:59 -0600808 * @return void
809 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200810 public function modal($src, $relative = FALSE)
811 {
Derek Jones811f4752010-03-02 18:13:59 -0600812 $this->jquery_code_for_load[] = $this->external($src, $relative);
813 }
814
815 // --------------------------------------------------------------------
816
817 /**
818 * Effect
819 *
820 * Load an Effect library
821 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300822 * @param string $src
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200823 * @param bool $relative
Derek Jones811f4752010-03-02 18:13:59 -0600824 * @return void
825 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200826 public function effect($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600827 {
828 $this->jquery_code_for_load[] = $this->external($src, $relative);
829 }
830
831 // --------------------------------------------------------------------
832
833 /**
834 * Plugin
835 *
836 * Load a plugin library
837 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300838 * @param string $src
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200839 * @param bool $relative
Derek Jones811f4752010-03-02 18:13:59 -0600840 * @return void
841 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200842 public function plugin($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600843 {
844 $this->jquery_code_for_load[] = $this->external($src, $relative);
845 }
846
847 // --------------------------------------------------------------------
848
849 /**
850 * UI
851 *
852 * Load a user interface library
853 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300854 * @param string $src
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200855 * @param bool $relative
Derek Jones811f4752010-03-02 18:13:59 -0600856 * @return void
857 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200858 public function ui($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600859 {
860 $this->jquery_code_for_load[] = $this->external($src, $relative);
861 }
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300862
Derek Jones811f4752010-03-02 18:13:59 -0600863 // --------------------------------------------------------------------
864
865 /**
866 * Sortable
867 *
868 * Creates a jQuery sortable
869 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300870 * @param string $element
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200871 * @param array $options
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300872 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600873 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200874 public function sortable($element, $options = array())
Derek Jones811f4752010-03-02 18:13:59 -0600875 {
Derek Jones811f4752010-03-02 18:13:59 -0600876 if (count($options) > 0)
877 {
878 $sort_options = array();
879 foreach ($options as $k=>$v)
880 {
Andrey Andreev56454792012-05-17 14:32:19 +0300881 $sort_options[] = "\n\t\t".$k.': '.$v;
Derek Jones811f4752010-03-02 18:13:59 -0600882 }
Andrey Andreev56454792012-05-17 14:32:19 +0300883 $sort_options = implode(',', $sort_options);
Derek Jones811f4752010-03-02 18:13:59 -0600884 }
885 else
886 {
887 $sort_options = '';
888 }
889
Andrey Andreev56454792012-05-17 14:32:19 +0300890 return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});";
Derek Jones811f4752010-03-02 18:13:59 -0600891 }
892
893 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200894
Derek Jones811f4752010-03-02 18:13:59 -0600895 /**
896 * Table Sorter Plugin
897 *
Derek Jones811f4752010-03-02 18:13:59 -0600898 * @param string table name
899 * @param string plugin location
900 * @return string
901 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200902 public function tablesorter($table = '', $options = '')
Derek Jones811f4752010-03-02 18:13:59 -0600903 {
Andrey Andreev56454792012-05-17 14:32:19 +0300904 $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n";
Derek Jones811f4752010-03-02 18:13:59 -0600905 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200906
Derek Jones811f4752010-03-02 18:13:59 -0600907 // --------------------------------------------------------------------
908 // Class functions
909 // --------------------------------------------------------------------
910
911 /**
912 * Add Event
913 *
914 * Constructs the syntax for an event, and adds to into the array for compilation
915 *
Derek Jones811f4752010-03-02 18:13:59 -0600916 * @param string The element to attach the event to
917 * @param string The code to execute
918 * @param string The event to pass
919 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200920 */
921 protected function _add_event($element, $js, $event)
Derek Jones811f4752010-03-02 18:13:59 -0600922 {
923 if (is_array($js))
924 {
925 $js = implode("\n\t\t", $js);
Derek Jones811f4752010-03-02 18:13:59 -0600926 }
927
Andrey Andreev56454792012-05-17 14:32:19 +0300928 $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
Derek Jones811f4752010-03-02 18:13:59 -0600929 $this->jquery_code_for_compile[] = $event;
930 return $event;
931 }
932
933 // --------------------------------------------------------------------
934
935 /**
936 * Compile
937 *
938 * As events are specified, they are stored in an array
vlakoff3b8b8922013-07-24 22:41:00 +0200939 * This function compiles them all for output on a page
Derek Jones811f4752010-03-02 18:13:59 -0600940 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +0200941 * @param string $view_var
942 * @param bool $script_tags
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300943 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600944 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200945 protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600946 {
947 // External references
948 $external_scripts = implode('', $this->jquery_code_for_load);
949 $this->CI->load->vars(array('library_src' => $external_scripts));
950
Andrey Andreevad47f942011-12-25 19:13:48 +0200951 if (count($this->jquery_code_for_compile) === 0)
Derek Jones811f4752010-03-02 18:13:59 -0600952 {
953 // no inline references, let's just return
954 return;
955 }
956
957 // Inline references
Andrey Andreevad47f942011-12-25 19:13:48 +0200958 $script = '$(document).ready(function() {'."\n"
Andrey Andreev56454792012-05-17 14:32:19 +0300959 .implode('', $this->jquery_code_for_compile)
960 .'});';
Andrey Andreevad47f942011-12-25 19:13:48 +0200961
Derek Jones811f4752010-03-02 18:13:59 -0600962 $output = ($script_tags === FALSE) ? $script : $this->inline($script);
963
964 $this->CI->load->vars(array($view_var => $output));
Derek Jones811f4752010-03-02 18:13:59 -0600965 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200966
Derek Jones811f4752010-03-02 18:13:59 -0600967 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200968
Derek Jones811f4752010-03-02 18:13:59 -0600969 /**
970 * Clear Compile
971 *
972 * Clears the array of script events collected for output
973 *
Derek Jones811f4752010-03-02 18:13:59 -0600974 * @return void
975 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200976 protected function _clear_compile()
Derek Jones811f4752010-03-02 18:13:59 -0600977 {
978 $this->jquery_code_for_compile = array();
979 }
980
981 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200982
Derek Jones811f4752010-03-02 18:13:59 -0600983 /**
984 * Document Ready
985 *
986 * A wrapper for writing document.ready()
987 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300988 * @param array $js
989 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600990 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200991 protected function _document_ready($js)
Derek Jones811f4752010-03-02 18:13:59 -0600992 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300993 is_array($js) OR $js = array($js);
Andrey Andreevad47f942011-12-25 19:13:48 +0200994
Derek Jones811f4752010-03-02 18:13:59 -0600995 foreach ($js as $script)
996 {
997 $this->jquery_code_for_compile[] = $script;
998 }
999 }
1000
1001 // --------------------------------------------------------------------
1002
1003 /**
1004 * Script Tag
1005 *
1006 * Outputs the script tag that loads the jquery.js file into an HTML document
1007 *
Andrey Andreev0fa95bd2012-11-01 23:33:14 +02001008 * @param string $library_src
1009 * @param bool $relative
Derek Jones811f4752010-03-02 18:13:59 -06001010 * @return string
1011 */
Andrey Andreevad47f942011-12-25 19:13:48 +02001012 public function script($library_src = '', $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -06001013 {
1014 $library_src = $this->external($library_src, $relative);
1015 $this->jquery_code_for_load[] = $library_src;
1016 return $library_src;
1017 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001018
Derek Jones811f4752010-03-02 18:13:59 -06001019 // --------------------------------------------------------------------
1020
1021 /**
1022 * Prep Element
1023 *
1024 * Puts HTML element in quotes for use in jQuery code
1025 * unless the supplied element is the Javascript 'this'
1026 * object, in which case no quotes are added
1027 *
Derek Jones811f4752010-03-02 18:13:59 -06001028 * @param string
1029 * @return string
1030 */
Andrey Andreevad47f942011-12-25 19:13:48 +02001031 protected function _prep_element($element)
Derek Jones811f4752010-03-02 18:13:59 -06001032 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001033 if ($element !== 'this')
Derek Jones811f4752010-03-02 18:13:59 -06001034 {
1035 $element = '"'.$element.'"';
1036 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001037
Derek Jones811f4752010-03-02 18:13:59 -06001038 return $element;
1039 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001040
Derek Jones811f4752010-03-02 18:13:59 -06001041 // --------------------------------------------------------------------
1042
1043 /**
1044 * Validate Speed
1045 *
1046 * Ensures the speed parameter is valid for jQuery
1047 *
Derek Jones811f4752010-03-02 18:13:59 -06001048 * @param string
1049 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +02001050 */
1051 protected function _validate_speed($speed)
Derek Jones811f4752010-03-02 18:13:59 -06001052 {
1053 if (in_array($speed, array('slow', 'normal', 'fast')))
1054 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001055 return '"'.$speed.'"';
Derek Jones811f4752010-03-02 18:13:59 -06001056 }
Andrey Andreev56454792012-05-17 14:32:19 +03001057 elseif (preg_match('/[^0-9]/', $speed))
Derek Jones811f4752010-03-02 18:13:59 -06001058 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001059 return '';
Derek Jones811f4752010-03-02 18:13:59 -06001060 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001061
Derek Jones811f4752010-03-02 18:13:59 -06001062 return $speed;
1063 }
1064
1065}
1066
1067/* End of file Jquery.php */
Andrey Andreevc5a7c5f2013-07-17 20:10:09 +03001068/* Location: ./system/libraries/Jquery.php */