blob: 44c16b5789b1a0080e12cd78e0a73b69fae1b9be [file] [log] [blame]
Andrey Andreevad47f942011-12-25 19:13:48 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, 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 */
27
28/**
29 * Jquery Class
30 *
31 * @package CodeIgniter
32 * @subpackage Libraries
Derek Jones811f4752010-03-02 18:13:59 -060033 * @category Loader
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
35 * @link http://codeigniter.com/user_guide/libraries/javascript.html
Derek Jones811f4752010-03-02 18:13:59 -060036 */
Andrey Andreevad47f942011-12-25 19:13:48 +020037
Greg Akeraacfe482010-03-03 12:26:31 -060038class CI_Jquery extends CI_Javascript {
Derek Jones811f4752010-03-02 18:13:59 -060039
Andrey Andreevad47f942011-12-25 19:13:48 +020040 protected $_javascript_folder = 'js';
41 public $jquery_code_for_load = array();
42 public $jquery_code_for_compile = array();
43 public $jquery_corner_active = FALSE;
44 public $jquery_table_sorter_active = FALSE;
45 public $jquery_table_sorter_pager_active = FALSE;
46 public $jquery_ajax_img = '';
Derek Jones811f4752010-03-02 18:13:59 -060047
Greg Akera9263282010-11-10 15:26:43 -060048 public function __construct($params)
Derek Jones811f4752010-03-02 18:13:59 -060049 {
Andrey Andreevad47f942011-12-25 19:13:48 +020050 $this->CI =& get_instance();
Derek Jones811f4752010-03-02 18:13:59 -060051 extract($params);
52
53 if ($autoload === TRUE)
54 {
Andrey Andreevad47f942011-12-25 19:13:48 +020055 $this->script();
Derek Jones811f4752010-03-02 18:13:59 -060056 }
Andrey Andreevad47f942011-12-25 19:13:48 +020057
Andrey Andreev56454792012-05-17 14:32:19 +030058 log_message('debug', 'Jquery Class Initialized');
Derek Jones811f4752010-03-02 18:13:59 -060059 }
Andrey Andreevad47f942011-12-25 19:13:48 +020060
61 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060062 // Event Code
Andrey Andreevad47f942011-12-25 19:13:48 +020063 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060064
65 /**
66 * Blur
67 *
68 * Outputs a jQuery blur event
69 *
Derek Jones811f4752010-03-02 18:13:59 -060070 * @param string The element to attach the event to
71 * @param string The code to execute
72 * @return string
73 */
Andrey Andreevad47f942011-12-25 19:13:48 +020074 protected function _blur($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060075 {
76 return $this->_add_event($element, $js, 'blur');
77 }
Andrey Andreevad47f942011-12-25 19:13:48 +020078
Derek Jones811f4752010-03-02 18:13:59 -060079 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +020080
Derek Jones811f4752010-03-02 18:13:59 -060081 /**
82 * Change
83 *
84 * Outputs a jQuery change event
85 *
Derek Jones811f4752010-03-02 18:13:59 -060086 * @param string The element to attach the event to
87 * @param string The code to execute
88 * @return string
89 */
Andrey Andreevad47f942011-12-25 19:13:48 +020090 protected function _change($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060091 {
92 return $this->_add_event($element, $js, 'change');
93 }
Andrey Andreevad47f942011-12-25 19:13:48 +020094
Derek Jones811f4752010-03-02 18:13:59 -060095 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +020096
Derek Jones811f4752010-03-02 18:13:59 -060097 /**
98 * Click
99 *
100 * Outputs a jQuery click event
101 *
Derek Jones811f4752010-03-02 18:13:59 -0600102 * @param string The element to attach the event to
103 * @param string The code to execute
104 * @param boolean whether or not to return false
105 * @return string
106 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200107 protected function _click($element = 'this', $js = '', $ret_false = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600108 {
109 if ( ! is_array($js))
110 {
111 $js = array($js);
112 }
113
114 if ($ret_false)
115 {
Andrey Andreev56454792012-05-17 14:32:19 +0300116 $js[] = 'return false;';
Derek Jones811f4752010-03-02 18:13:59 -0600117 }
118
119 return $this->_add_event($element, $js, 'click');
120 }
121
122 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200123
Derek Jones811f4752010-03-02 18:13:59 -0600124 /**
125 * Double Click
126 *
127 * Outputs a jQuery dblclick event
128 *
Derek Jones811f4752010-03-02 18:13:59 -0600129 * @param string The element to attach the event to
130 * @param string The code to execute
131 * @return string
132 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200133 protected function _dblclick($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600134 {
135 return $this->_add_event($element, $js, 'dblclick');
136 }
137
138 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200139
Derek Jones811f4752010-03-02 18:13:59 -0600140 /**
141 * Error
142 *
143 * Outputs a jQuery error event
144 *
Derek Jones811f4752010-03-02 18:13:59 -0600145 * @param string The element to attach the event to
146 * @param string The code to execute
147 * @return string
148 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200149 protected function _error($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600150 {
151 return $this->_add_event($element, $js, 'error');
152 }
153
154 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200155
Derek Jones811f4752010-03-02 18:13:59 -0600156 /**
157 * Focus
158 *
159 * Outputs a jQuery focus event
160 *
Derek Jones811f4752010-03-02 18:13:59 -0600161 * @param string The element to attach the event to
162 * @param string The code to execute
163 * @return string
164 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200165 protected function _focus($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600166 {
167 return $this->_add_event($element, $js, 'focus');
168 }
169
170 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200171
Derek Jones811f4752010-03-02 18:13:59 -0600172 /**
173 * Hover
174 *
175 * Outputs a jQuery hover event
176 *
Derek Jones811f4752010-03-02 18:13:59 -0600177 * @param string - element
178 * @param string - Javascript code for mouse over
179 * @param string - Javascript code for mouse out
Barry Mienydd671972010-10-04 16:33:58 +0200180 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600181 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200182 protected function _hover($element = 'this', $over, $out)
Derek Jones811f4752010-03-02 18:13:59 -0600183 {
Andrey Andreev56454792012-05-17 14:32:19 +0300184 $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 -0600185
186 $this->jquery_code_for_compile[] = $event;
187
188 return $event;
189 }
190
191 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200192
Derek Jones811f4752010-03-02 18:13:59 -0600193 /**
194 * Keydown
195 *
196 * Outputs a jQuery keydown event
197 *
Derek Jones811f4752010-03-02 18:13:59 -0600198 * @param string The element to attach the event to
199 * @param string The code to execute
200 * @return string
201 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200202 protected function _keydown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600203 {
204 return $this->_add_event($element, $js, 'keydown');
205 }
206
207 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200208
Derek Jones811f4752010-03-02 18:13:59 -0600209 /**
210 * Keyup
211 *
212 * Outputs a jQuery keydown event
213 *
Derek Jones811f4752010-03-02 18:13:59 -0600214 * @param string The element to attach the event to
215 * @param string The code to execute
216 * @return string
217 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200218 protected function _keyup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600219 {
220 return $this->_add_event($element, $js, 'keyup');
Andrey Andreevad47f942011-12-25 19:13:48 +0200221 }
Derek Jones811f4752010-03-02 18:13:59 -0600222
223 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200224
Derek Jones811f4752010-03-02 18:13:59 -0600225 /**
226 * Load
227 *
228 * Outputs a jQuery load event
229 *
Derek Jones811f4752010-03-02 18:13:59 -0600230 * @param string The element to attach the event to
231 * @param string The code to execute
232 * @return string
233 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200234 protected function _load($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600235 {
236 return $this->_add_event($element, $js, 'load');
Andrey Andreevad47f942011-12-25 19:13:48 +0200237 }
238
Derek Jones811f4752010-03-02 18:13:59 -0600239 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200240
Derek Jones811f4752010-03-02 18:13:59 -0600241 /**
242 * Mousedown
243 *
244 * Outputs a jQuery mousedown event
245 *
Derek Jones811f4752010-03-02 18:13:59 -0600246 * @param string The element to attach the event to
247 * @param string The code to execute
248 * @return string
249 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200250 protected function _mousedown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600251 {
252 return $this->_add_event($element, $js, 'mousedown');
253 }
254
255 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200256
Derek Jones811f4752010-03-02 18:13:59 -0600257 /**
258 * Mouse Out
259 *
260 * Outputs a jQuery mouseout event
261 *
Derek Jones811f4752010-03-02 18:13:59 -0600262 * @param string The element to attach the event to
263 * @param string The code to execute
264 * @return string
265 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200266 protected function _mouseout($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600267 {
268 return $this->_add_event($element, $js, 'mouseout');
269 }
270
271 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200272
Derek Jones811f4752010-03-02 18:13:59 -0600273 /**
274 * Mouse Over
275 *
276 * Outputs a jQuery mouseover event
277 *
Derek Jones811f4752010-03-02 18:13:59 -0600278 * @param string The element to attach the event to
279 * @param string The code to execute
280 * @return string
281 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200282 protected function _mouseover($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600283 {
284 return $this->_add_event($element, $js, 'mouseover');
285 }
286
287 // --------------------------------------------------------------------
288
289 /**
290 * Mouseup
291 *
292 * Outputs a jQuery mouseup event
293 *
Derek Jones811f4752010-03-02 18:13:59 -0600294 * @param string The element to attach the event to
295 * @param string The code to execute
296 * @return string
297 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200298 protected function _mouseup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600299 {
300 return $this->_add_event($element, $js, 'mouseup');
301 }
302
303 // --------------------------------------------------------------------
304
305 /**
306 * Output
307 *
308 * Outputs script directly
309 *
Derek Jones811f4752010-03-02 18:13:59 -0600310 * @param string The element to attach the event to
311 * @param string The code to execute
312 * @return string
313 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200314 protected function _output($array_js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600315 {
316 if ( ! is_array($array_js))
317 {
318 $array_js = array($array_js);
319 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200320
Derek Jones811f4752010-03-02 18:13:59 -0600321 foreach ($array_js as $js)
322 {
Andrey Andreev56454792012-05-17 14:32:19 +0300323 $this->jquery_code_for_compile[] = "\t".$js."\n";
Derek Jones811f4752010-03-02 18:13:59 -0600324 }
325 }
326
327 // --------------------------------------------------------------------
328
329 /**
330 * Resize
331 *
332 * Outputs a jQuery resize event
333 *
Derek Jones811f4752010-03-02 18:13:59 -0600334 * @param string The element to attach the event to
335 * @param string The code to execute
336 * @return string
337 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200338 protected function _resize($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600339 {
340 return $this->_add_event($element, $js, 'resize');
341 }
342
343 // --------------------------------------------------------------------
344
345 /**
346 * Scroll
347 *
348 * Outputs a jQuery scroll event
349 *
Derek Jones811f4752010-03-02 18:13:59 -0600350 * @param string The element to attach the event to
351 * @param string The code to execute
352 * @return string
353 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200354 protected function _scroll($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600355 {
356 return $this->_add_event($element, $js, 'scroll');
357 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200358
Derek Jones811f4752010-03-02 18:13:59 -0600359 // --------------------------------------------------------------------
360
361 /**
362 * Unload
363 *
364 * Outputs a jQuery unload event
365 *
Derek Jones811f4752010-03-02 18:13:59 -0600366 * @param string The element to attach the event to
367 * @param string The code to execute
368 * @return string
369 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200370 protected function _unload($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600371 {
372 return $this->_add_event($element, $js, 'unload');
373 }
374
Andrey Andreevad47f942011-12-25 19:13:48 +0200375 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600376 // Effects
Andrey Andreevad47f942011-12-25 19:13:48 +0200377 // --------------------------------------------------------------------
378
Derek Jones811f4752010-03-02 18:13:59 -0600379 /**
380 * Add Class
381 *
382 * Outputs a jQuery addClass event
383 *
Derek Jones811f4752010-03-02 18:13:59 -0600384 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200385 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600386 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200387 protected function _addClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600388 {
389 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300390 return '$('.$element.').addClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600391 }
392
393 // --------------------------------------------------------------------
394
395 /**
396 * Animate
397 *
398 * Outputs a jQuery animate event
399 *
Derek Jones811f4752010-03-02 18:13:59 -0600400 * @param string - element
401 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
402 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200403 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600404 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200405 protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
Derek Jones811f4752010-03-02 18:13:59 -0600406 {
407 $element = $this->_prep_element($element);
408 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200409
Derek Jones811f4752010-03-02 18:13:59 -0600410 $animations = "\t\t\t";
Andrey Andreevad47f942011-12-25 19:13:48 +0200411
Andrey Andreev56454792012-05-17 14:32:19 +0300412 foreach ($params as $param => $value)
Derek Jones811f4752010-03-02 18:13:59 -0600413 {
Andrey Andreev56454792012-05-17 14:32:19 +0300414 $animations .= $param.": '".$value."', ";
Derek Jones811f4752010-03-02 18:13:59 -0600415 }
416
417 $animations = substr($animations, 0, -2); // remove the last ", "
418
Alex Bilbied261b1e2012-06-02 11:12:16 +0100419 if ($speed !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600420 {
421 $speed = ', '.$speed;
422 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200423
Alex Bilbied261b1e2012-06-02 11:12:16 +0100424 if ($extra !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600425 {
426 $extra = ', '.$extra;
427 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200428
Andrey Andreev56454792012-05-17 14:32:19 +0300429 return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');';
Derek Jones811f4752010-03-02 18:13:59 -0600430 }
431
432 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200433
Derek Jones811f4752010-03-02 18:13:59 -0600434 /**
435 * Fade In
436 *
437 * Outputs a jQuery hide event
438 *
Derek Jones811f4752010-03-02 18:13:59 -0600439 * @param string - element
440 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
441 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200442 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600443 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200444 protected function _fadeIn($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600445 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200446 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600447 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200448
Alex Bilbied261b1e2012-06-02 11:12:16 +0100449 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600450 {
451 $callback = ", function(){\n{$callback}\n}";
452 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200453
454 return "$({$element}).fadeIn({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600455 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200456
Derek Jones811f4752010-03-02 18:13:59 -0600457 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200458
Derek Jones811f4752010-03-02 18:13:59 -0600459 /**
460 * Fade Out
461 *
462 * Outputs a jQuery hide event
463 *
Derek Jones811f4752010-03-02 18:13:59 -0600464 * @param string - element
465 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
466 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200467 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600468 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200469 protected function _fadeOut($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600470 {
471 $element = $this->_prep_element($element);
472 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200473
Alex Bilbied261b1e2012-06-02 11:12:16 +0100474 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600475 {
476 $callback = ", function(){\n{$callback}\n}";
477 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200478
Andrey Andreev56454792012-05-17 14:32:19 +0300479 return '$('.$element.').fadeOut('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600480 }
481
482 // --------------------------------------------------------------------
483
484 /**
485 * Hide
486 *
487 * Outputs a jQuery hide action
488 *
Derek Jones811f4752010-03-02 18:13:59 -0600489 * @param string - element
490 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
491 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200492 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600493 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200494 protected function _hide($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600495 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200496 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600497 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200498
Alex Bilbied261b1e2012-06-02 11:12:16 +0100499 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600500 {
501 $callback = ", function(){\n{$callback}\n}";
502 }
Derek Jones811f4752010-03-02 18:13:59 -0600503
Andrey Andreevad47f942011-12-25 19:13:48 +0200504 return "$({$element}).hide({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600505 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200506
Derek Jones811f4752010-03-02 18:13:59 -0600507 // --------------------------------------------------------------------
508
509 /**
510 * Remove Class
511 *
512 * Outputs a jQuery remove class event
513 *
Derek Jones811f4752010-03-02 18:13:59 -0600514 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200515 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600516 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200517 protected function _removeClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600518 {
519 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300520 return '$('.$element.').removeClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600521 }
522
523 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200524
Derek Jones811f4752010-03-02 18:13:59 -0600525 /**
526 * Slide Up
527 *
528 * Outputs a jQuery slideUp event
529 *
Derek Jones811f4752010-03-02 18:13:59 -0600530 * @param string - element
531 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
532 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200533 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600534 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200535 protected function _slideUp($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600536 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200537 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600538 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200539
Alex Bilbied261b1e2012-06-02 11:12:16 +0100540 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600541 {
542 $callback = ", function(){\n{$callback}\n}";
543 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200544
Andrey Andreev56454792012-05-17 14:32:19 +0300545 return '$('.$element.').slideUp('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600546 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200547
Derek Jones811f4752010-03-02 18:13:59 -0600548 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200549
Derek Jones811f4752010-03-02 18:13:59 -0600550 /**
551 * Slide Down
552 *
553 * Outputs a jQuery slideDown event
554 *
Derek Jones811f4752010-03-02 18:13:59 -0600555 * @param string - element
556 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
557 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200558 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600559 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200560 protected function _slideDown($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600561 {
562 $element = $this->_prep_element($element);
563 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200564
Alex Bilbied261b1e2012-06-02 11:12:16 +0100565 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600566 {
567 $callback = ", function(){\n{$callback}\n}";
568 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200569
Andrey Andreev56454792012-05-17 14:32:19 +0300570 return '$('.$element.').slideDown('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600571 }
572
573 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200574
Derek Jones811f4752010-03-02 18:13:59 -0600575 /**
576 * Slide Toggle
577 *
578 * Outputs a jQuery slideToggle event
579 *
Derek Jones811f4752010-03-02 18:13:59 -0600580 * @param string - element
581 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
582 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200583 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600584 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200585 protected function _slideToggle($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600586 {
587 $element = $this->_prep_element($element);
588 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200589
Alex Bilbied261b1e2012-06-02 11:12:16 +0100590 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600591 {
592 $callback = ", function(){\n{$callback}\n}";
593 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200594
Andrey Andreev56454792012-05-17 14:32:19 +0300595 return '$('.$element.').slideToggle('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600596 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200597
Derek Jones811f4752010-03-02 18:13:59 -0600598 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200599
Derek Jones811f4752010-03-02 18:13:59 -0600600 /**
601 * Toggle
602 *
603 * Outputs a jQuery toggle event
604 *
Derek Jones811f4752010-03-02 18:13:59 -0600605 * @param string - element
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 _toggle($element = 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600609 {
610 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300611 return '$('.$element.').toggle();';
Derek Jones811f4752010-03-02 18:13:59 -0600612 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200613
Derek Jones811f4752010-03-02 18:13:59 -0600614 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200615
Derek Jones811f4752010-03-02 18:13:59 -0600616 /**
617 * Toggle Class
618 *
619 * Outputs a jQuery toggle class event
620 *
Derek Jones811f4752010-03-02 18:13:59 -0600621 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200622 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600623 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200624 protected function _toggleClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600625 {
626 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300627 return '$('.$element.').toggleClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600628 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200629
Derek Jones811f4752010-03-02 18:13:59 -0600630 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200631
Derek Jones811f4752010-03-02 18:13:59 -0600632 /**
633 * Show
634 *
635 * Outputs a jQuery show event
636 *
Derek Jones811f4752010-03-02 18:13:59 -0600637 * @param string - element
638 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
639 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200640 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600641 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200642 protected function _show($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600643 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200644 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600645 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200646
Alex Bilbied261b1e2012-06-02 11:12:16 +0100647 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600648 {
649 $callback = ", function(){\n{$callback}\n}";
650 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200651
Andrey Andreev56454792012-05-17 14:32:19 +0300652 return '$('.$element.').show('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600653 }
654
655 // --------------------------------------------------------------------
656
657 /**
658 * Updater
659 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200660 * An Ajax call that populates the designated DOM node with
Derek Jones811f4752010-03-02 18:13:59 -0600661 * returned content
662 *
Derek Jones811f4752010-03-02 18:13:59 -0600663 * @param string The element to attach the event to
664 * @param string the controller to run the call against
665 * @param string optional parameters
666 * @return string
667 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200668
669 protected function _updater($container = 'this', $controller, $options = '')
670 {
Derek Jones811f4752010-03-02 18:13:59 -0600671 $container = $this->_prep_element($container);
Derek Jones811f4752010-03-02 18:13:59 -0600672 $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
Andrey Andreevad47f942011-12-25 19:13:48 +0200673
Derek Jones811f4752010-03-02 18:13:59 -0600674 // ajaxStart and ajaxStop are better choices here... but this is a stop gap
Alex Bilbied261b1e2012-06-02 11:12:16 +0100675 if ($this->CI->config->item('javascript_ajax_img') === '')
Derek Jones811f4752010-03-02 18:13:59 -0600676 {
Andrey Andreev56454792012-05-17 14:32:19 +0300677 $loading_notifier = 'Loading...';
Derek Jones811f4752010-03-02 18:13:59 -0600678 }
679 else
680 {
Andrey Andreev56454792012-05-17 14:32:19 +0300681 $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 -0600682 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200683
Andrey Andreev56454792012-05-17 14:32:19 +0300684 $updater = '$('.$container.").empty();\n" // anything that was in... get it out
685 ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
Derek Jones811f4752010-03-02 18:13:59 -0600686
687 $request_options = '';
Alex Bilbied261b1e2012-06-02 11:12:16 +0100688 if ($options !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600689 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200690 $request_options .= ', {'
Andrey Andreev56454792012-05-17 14:32:19 +0300691 .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
692 .'}';
Derek Jones811f4752010-03-02 18:13:59 -0600693 }
694
Andrey Andreevad47f942011-12-25 19:13:48 +0200695 return $updater."\t\t$($container).load('$controller'$request_options);";
Derek Jones811f4752010-03-02 18:13:59 -0600696 }
697
698
699 // --------------------------------------------------------------------
700 // Pre-written handy stuff
701 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200702
Derek Jones811f4752010-03-02 18:13:59 -0600703 /**
704 * Zebra tables
705 *
Derek Jones811f4752010-03-02 18:13:59 -0600706 * @param string table name
707 * @param string plugin location
708 * @return string
709 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200710 protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
Derek Jones811f4752010-03-02 18:13:59 -0600711 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100712 $class = ($class !== '') ? '.'.$class : '';
Derek Jones37f4b9c2011-07-01 17:56:50 -0500713 $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
Derek Jones811f4752010-03-02 18:13:59 -0600714
715 $this->jquery_code_for_compile[] = $zebra;
716
Alex Bilbied261b1e2012-06-02 11:12:16 +0100717 if ($hover !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600718 {
719 $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
720 }
721
722 return $zebra;
723 }
724
Derek Jones811f4752010-03-02 18:13:59 -0600725 // --------------------------------------------------------------------
726 // Plugins
727 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200728
Derek Jones811f4752010-03-02 18:13:59 -0600729 /**
730 * Corner Plugin
731 *
732 * http://www.malsup.com/jquery/corner/
733 *
Derek Jones811f4752010-03-02 18:13:59 -0600734 * @param string target
735 * @return string
736 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200737 public function corner($element = '', $corner_style = '')
Derek Jones811f4752010-03-02 18:13:59 -0600738 {
739 // may want to make this configurable down the road
740 $corner_location = '/plugins/jquery.corner.js';
741
Alex Bilbied261b1e2012-06-02 11:12:16 +0100742 if ($corner_style !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600743 {
744 $corner_style = '"'.$corner_style.'"';
745 }
746
Andrey Andreev56454792012-05-17 14:32:19 +0300747 return '$('.$this->_prep_element($element).').corner('.$corner_style.');';
Derek Jones811f4752010-03-02 18:13:59 -0600748 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200749
Derek Jones811f4752010-03-02 18:13:59 -0600750 // --------------------------------------------------------------------
751
752 /**
753 * modal window
754 *
755 * Load a thickbox modal window
756 *
Derek Jones811f4752010-03-02 18:13:59 -0600757 * @return void
758 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200759 public function modal($src, $relative = FALSE)
760 {
Derek Jones811f4752010-03-02 18:13:59 -0600761 $this->jquery_code_for_load[] = $this->external($src, $relative);
762 }
763
764 // --------------------------------------------------------------------
765
766 /**
767 * Effect
768 *
769 * Load an Effect library
770 *
Derek Jones811f4752010-03-02 18:13:59 -0600771 * @return void
772 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200773 public function effect($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600774 {
775 $this->jquery_code_for_load[] = $this->external($src, $relative);
776 }
777
778 // --------------------------------------------------------------------
779
780 /**
781 * Plugin
782 *
783 * Load a plugin library
784 *
Derek Jones811f4752010-03-02 18:13:59 -0600785 * @return void
786 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200787 public function plugin($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600788 {
789 $this->jquery_code_for_load[] = $this->external($src, $relative);
790 }
791
792 // --------------------------------------------------------------------
793
794 /**
795 * UI
796 *
797 * Load a user interface library
798 *
Derek Jones811f4752010-03-02 18:13:59 -0600799 * @return void
800 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200801 public function ui($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600802 {
803 $this->jquery_code_for_load[] = $this->external($src, $relative);
804 }
805 // --------------------------------------------------------------------
806
807 /**
808 * Sortable
809 *
810 * Creates a jQuery sortable
811 *
Derek Jones811f4752010-03-02 18:13:59 -0600812 * @return void
813 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200814 public function sortable($element, $options = array())
Derek Jones811f4752010-03-02 18:13:59 -0600815 {
816
817 if (count($options) > 0)
818 {
819 $sort_options = array();
820 foreach ($options as $k=>$v)
821 {
Andrey Andreev56454792012-05-17 14:32:19 +0300822 $sort_options[] = "\n\t\t".$k.': '.$v;
Derek Jones811f4752010-03-02 18:13:59 -0600823 }
Andrey Andreev56454792012-05-17 14:32:19 +0300824 $sort_options = implode(',', $sort_options);
Derek Jones811f4752010-03-02 18:13:59 -0600825 }
826 else
827 {
828 $sort_options = '';
829 }
830
Andrey Andreev56454792012-05-17 14:32:19 +0300831 return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});";
Derek Jones811f4752010-03-02 18:13:59 -0600832 }
833
834 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200835
Derek Jones811f4752010-03-02 18:13:59 -0600836 /**
837 * Table Sorter Plugin
838 *
Derek Jones811f4752010-03-02 18:13:59 -0600839 * @param string table name
840 * @param string plugin location
841 * @return string
842 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200843 public function tablesorter($table = '', $options = '')
Derek Jones811f4752010-03-02 18:13:59 -0600844 {
Andrey Andreev56454792012-05-17 14:32:19 +0300845 $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n";
Derek Jones811f4752010-03-02 18:13:59 -0600846 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200847
Derek Jones811f4752010-03-02 18:13:59 -0600848 // --------------------------------------------------------------------
849 // Class functions
850 // --------------------------------------------------------------------
851
852 /**
853 * Add Event
854 *
855 * Constructs the syntax for an event, and adds to into the array for compilation
856 *
Derek Jones811f4752010-03-02 18:13:59 -0600857 * @param string The element to attach the event to
858 * @param string The code to execute
859 * @param string The event to pass
860 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200861 */
862 protected function _add_event($element, $js, $event)
Derek Jones811f4752010-03-02 18:13:59 -0600863 {
864 if (is_array($js))
865 {
866 $js = implode("\n\t\t", $js);
867
868 }
869
Andrey Andreev56454792012-05-17 14:32:19 +0300870 $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
Derek Jones811f4752010-03-02 18:13:59 -0600871 $this->jquery_code_for_compile[] = $event;
872 return $event;
873 }
874
875 // --------------------------------------------------------------------
876
877 /**
878 * Compile
879 *
880 * As events are specified, they are stored in an array
881 * This funciton compiles them all for output on a page
882 *
Derek Jones811f4752010-03-02 18:13:59 -0600883 * @return string
884 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200885 protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600886 {
887 // External references
888 $external_scripts = implode('', $this->jquery_code_for_load);
889 $this->CI->load->vars(array('library_src' => $external_scripts));
890
Andrey Andreevad47f942011-12-25 19:13:48 +0200891 if (count($this->jquery_code_for_compile) === 0)
Derek Jones811f4752010-03-02 18:13:59 -0600892 {
893 // no inline references, let's just return
894 return;
895 }
896
897 // Inline references
Andrey Andreevad47f942011-12-25 19:13:48 +0200898 $script = '$(document).ready(function() {'."\n"
Andrey Andreev56454792012-05-17 14:32:19 +0300899 .implode('', $this->jquery_code_for_compile)
900 .'});';
Andrey Andreevad47f942011-12-25 19:13:48 +0200901
Derek Jones811f4752010-03-02 18:13:59 -0600902 $output = ($script_tags === FALSE) ? $script : $this->inline($script);
903
904 $this->CI->load->vars(array($view_var => $output));
905
906 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200907
Derek Jones811f4752010-03-02 18:13:59 -0600908 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200909
Derek Jones811f4752010-03-02 18:13:59 -0600910 /**
911 * Clear Compile
912 *
913 * Clears the array of script events collected for output
914 *
Derek Jones811f4752010-03-02 18:13:59 -0600915 * @return void
916 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200917 protected function _clear_compile()
Derek Jones811f4752010-03-02 18:13:59 -0600918 {
919 $this->jquery_code_for_compile = array();
920 }
921
922 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200923
Derek Jones811f4752010-03-02 18:13:59 -0600924 /**
925 * Document Ready
926 *
927 * A wrapper for writing document.ready()
928 *
Derek Jones811f4752010-03-02 18:13:59 -0600929 * @return string
930 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200931 protected function _document_ready($js)
Derek Jones811f4752010-03-02 18:13:59 -0600932 {
933 if ( ! is_array($js))
934 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200935 $js = array($js);
Derek Jones811f4752010-03-02 18:13:59 -0600936 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200937
Derek Jones811f4752010-03-02 18:13:59 -0600938 foreach ($js as $script)
939 {
940 $this->jquery_code_for_compile[] = $script;
941 }
942 }
943
944 // --------------------------------------------------------------------
945
946 /**
947 * Script Tag
948 *
949 * Outputs the script tag that loads the jquery.js file into an HTML document
950 *
Derek Jones811f4752010-03-02 18:13:59 -0600951 * @param string
952 * @return string
953 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200954 public function script($library_src = '', $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600955 {
956 $library_src = $this->external($library_src, $relative);
957 $this->jquery_code_for_load[] = $library_src;
958 return $library_src;
959 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200960
Derek Jones811f4752010-03-02 18:13:59 -0600961 // --------------------------------------------------------------------
962
963 /**
964 * Prep Element
965 *
966 * Puts HTML element in quotes for use in jQuery code
967 * unless the supplied element is the Javascript 'this'
968 * object, in which case no quotes are added
969 *
Derek Jones811f4752010-03-02 18:13:59 -0600970 * @param string
971 * @return string
972 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200973 protected function _prep_element($element)
Derek Jones811f4752010-03-02 18:13:59 -0600974 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100975 if ($element !== 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600976 {
977 $element = '"'.$element.'"';
978 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200979
Derek Jones811f4752010-03-02 18:13:59 -0600980 return $element;
981 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200982
Derek Jones811f4752010-03-02 18:13:59 -0600983 // --------------------------------------------------------------------
984
985 /**
986 * Validate Speed
987 *
988 * Ensures the speed parameter is valid for jQuery
989 *
Derek Jones811f4752010-03-02 18:13:59 -0600990 * @param string
991 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200992 */
993 protected function _validate_speed($speed)
Derek Jones811f4752010-03-02 18:13:59 -0600994 {
995 if (in_array($speed, array('slow', 'normal', 'fast')))
996 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200997 return '"'.$speed.'"';
Derek Jones811f4752010-03-02 18:13:59 -0600998 }
Andrey Andreev56454792012-05-17 14:32:19 +0300999 elseif (preg_match('/[^0-9]/', $speed))
Derek Jones811f4752010-03-02 18:13:59 -06001000 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001001 return '';
Derek Jones811f4752010-03-02 18:13:59 -06001002 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001003
Derek Jones811f4752010-03-02 18:13:59 -06001004 return $speed;
1005 }
1006
1007}
1008
1009/* End of file Jquery.php */
Andrey Andreev56454792012-05-17 14:32:19 +03001010/* Location: ./system/libraries/Jquery.php */