blob: 05057bec21f01f9594ea883871d179a7c023cc38 [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 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05005 * An open source application development framework for PHP 5.1.6 or newer
6 *
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
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @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
Derek Jonesf4a4bd82011-10-20 12:18:42 -050028// ------------------------------------------------------------------------
29
Derek Jones811f4752010-03-02 18:13:59 -060030/**
31 * Jquery Class
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
Derek Jones811f4752010-03-02 18:13:59 -060035 * @category Loader
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
37 * @link http://codeigniter.com/user_guide/libraries/javascript.html
Derek Jones811f4752010-03-02 18:13:59 -060038 */
Andrey Andreevad47f942011-12-25 19:13:48 +020039
Greg Akeraacfe482010-03-03 12:26:31 -060040class CI_Jquery extends CI_Javascript {
Derek Jones811f4752010-03-02 18:13:59 -060041
Andrey Andreevad47f942011-12-25 19:13:48 +020042 protected $_javascript_folder = 'js';
43 public $jquery_code_for_load = array();
44 public $jquery_code_for_compile = array();
45 public $jquery_corner_active = FALSE;
46 public $jquery_table_sorter_active = FALSE;
47 public $jquery_table_sorter_pager_active = FALSE;
48 public $jquery_ajax_img = '';
Derek Jones811f4752010-03-02 18:13:59 -060049
Greg Akera9263282010-11-10 15:26:43 -060050 public function __construct($params)
Derek Jones811f4752010-03-02 18:13:59 -060051 {
Andrey Andreevad47f942011-12-25 19:13:48 +020052 $this->CI =& get_instance();
Derek Jones811f4752010-03-02 18:13:59 -060053 extract($params);
54
55 if ($autoload === TRUE)
56 {
Andrey Andreevad47f942011-12-25 19:13:48 +020057 $this->script();
Derek Jones811f4752010-03-02 18:13:59 -060058 }
Andrey Andreevad47f942011-12-25 19:13:48 +020059
Derek Jones811f4752010-03-02 18:13:59 -060060 log_message('debug', "Jquery Class Initialized");
61 }
Andrey Andreevad47f942011-12-25 19:13:48 +020062
63 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060064 // Event Code
Andrey Andreevad47f942011-12-25 19:13:48 +020065 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060066
67 /**
68 * Blur
69 *
70 * Outputs a jQuery blur event
71 *
Andrey Andreevad47f942011-12-25 19:13:48 +020072 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -060073 * @param string The element to attach the event to
74 * @param string The code to execute
75 * @return string
76 */
Andrey Andreevad47f942011-12-25 19:13:48 +020077 protected function _blur($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060078 {
79 return $this->_add_event($element, $js, 'blur');
80 }
Andrey Andreevad47f942011-12-25 19:13:48 +020081
Derek Jones811f4752010-03-02 18:13:59 -060082 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +020083
Derek Jones811f4752010-03-02 18:13:59 -060084 /**
85 * Change
86 *
87 * Outputs a jQuery change event
88 *
Andrey Andreevad47f942011-12-25 19:13:48 +020089 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -060090 * @param string The element to attach the event to
91 * @param string The code to execute
92 * @return string
93 */
Andrey Andreevad47f942011-12-25 19:13:48 +020094 protected function _change($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060095 {
96 return $this->_add_event($element, $js, 'change');
97 }
Andrey Andreevad47f942011-12-25 19:13:48 +020098
Derek Jones811f4752010-03-02 18:13:59 -060099 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200100
Derek Jones811f4752010-03-02 18:13:59 -0600101 /**
102 * Click
103 *
104 * Outputs a jQuery click event
105 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200106 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600107 * @param string The element to attach the event to
108 * @param string The code to execute
109 * @param boolean whether or not to return false
110 * @return string
111 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200112 protected function _click($element = 'this', $js = '', $ret_false = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600113 {
114 if ( ! is_array($js))
115 {
116 $js = array($js);
117 }
118
119 if ($ret_false)
120 {
121 $js[] = "return false;";
122 }
123
124 return $this->_add_event($element, $js, 'click');
125 }
126
127 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200128
Derek Jones811f4752010-03-02 18:13:59 -0600129 /**
130 * Double Click
131 *
132 * Outputs a jQuery dblclick event
133 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200134 * @access protected
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 _dblclick($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600140 {
141 return $this->_add_event($element, $js, 'dblclick');
142 }
143
144 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200145
Derek Jones811f4752010-03-02 18:13:59 -0600146 /**
147 * Error
148 *
149 * Outputs a jQuery error event
150 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200151 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600152 * @param string The element to attach the event to
153 * @param string The code to execute
154 * @return string
155 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200156 protected function _error($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600157 {
158 return $this->_add_event($element, $js, 'error');
159 }
160
161 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200162
Derek Jones811f4752010-03-02 18:13:59 -0600163 /**
164 * Focus
165 *
166 * Outputs a jQuery focus event
167 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200168 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600169 * @param string The element to attach the event to
170 * @param string The code to execute
171 * @return string
172 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200173 protected function _focus($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600174 {
175 return $this->_add_event($element, $js, 'focus');
176 }
177
178 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200179
Derek Jones811f4752010-03-02 18:13:59 -0600180 /**
181 * Hover
182 *
183 * Outputs a jQuery hover event
184 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200185 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600186 * @param string - element
187 * @param string - Javascript code for mouse over
188 * @param string - Javascript code for mouse out
Barry Mienydd671972010-10-04 16:33:58 +0200189 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600190 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200191 protected function _hover($element = 'this', $over, $out)
Derek Jones811f4752010-03-02 18:13:59 -0600192 {
193 $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";
194
195 $this->jquery_code_for_compile[] = $event;
196
197 return $event;
198 }
199
200 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200201
Derek Jones811f4752010-03-02 18:13:59 -0600202 /**
203 * Keydown
204 *
205 * Outputs a jQuery keydown event
206 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200207 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600208 * @param string The element to attach the event to
209 * @param string The code to execute
210 * @return string
211 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200212 protected function _keydown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600213 {
214 return $this->_add_event($element, $js, 'keydown');
215 }
216
217 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200218
Derek Jones811f4752010-03-02 18:13:59 -0600219 /**
220 * Keyup
221 *
222 * Outputs a jQuery keydown event
223 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200224 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600225 * @param string The element to attach the event to
226 * @param string The code to execute
227 * @return string
228 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200229 protected function _keyup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600230 {
231 return $this->_add_event($element, $js, 'keyup');
Andrey Andreevad47f942011-12-25 19:13:48 +0200232 }
Derek Jones811f4752010-03-02 18:13:59 -0600233
234 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200235
Derek Jones811f4752010-03-02 18:13:59 -0600236 /**
237 * Load
238 *
239 * Outputs a jQuery load event
240 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200241 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600242 * @param string The element to attach the event to
243 * @param string The code to execute
244 * @return string
245 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200246 protected function _load($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600247 {
248 return $this->_add_event($element, $js, 'load');
Andrey Andreevad47f942011-12-25 19:13:48 +0200249 }
250
Derek Jones811f4752010-03-02 18:13:59 -0600251 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200252
Derek Jones811f4752010-03-02 18:13:59 -0600253 /**
254 * Mousedown
255 *
256 * Outputs a jQuery mousedown event
257 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200258 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600259 * @param string The element to attach the event to
260 * @param string The code to execute
261 * @return string
262 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200263 protected function _mousedown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600264 {
265 return $this->_add_event($element, $js, 'mousedown');
266 }
267
268 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200269
Derek Jones811f4752010-03-02 18:13:59 -0600270 /**
271 * Mouse Out
272 *
273 * Outputs a jQuery mouseout event
274 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200275 * @access protected
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 _mouseout($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600281 {
282 return $this->_add_event($element, $js, 'mouseout');
283 }
284
285 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200286
Derek Jones811f4752010-03-02 18:13:59 -0600287 /**
288 * Mouse Over
289 *
290 * Outputs a jQuery mouseover event
291 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200292 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600293 * @param string The element to attach the event to
294 * @param string The code to execute
295 * @return string
296 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200297 protected function _mouseover($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600298 {
299 return $this->_add_event($element, $js, 'mouseover');
300 }
301
302 // --------------------------------------------------------------------
303
304 /**
305 * Mouseup
306 *
307 * Outputs a jQuery mouseup event
308 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200309 * @access protected
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 _mouseup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600315 {
316 return $this->_add_event($element, $js, 'mouseup');
317 }
318
319 // --------------------------------------------------------------------
320
321 /**
322 * Output
323 *
324 * Outputs script directly
325 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200326 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600327 * @param string The element to attach the event to
328 * @param string The code to execute
329 * @return string
330 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200331 protected function _output($array_js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600332 {
333 if ( ! is_array($array_js))
334 {
335 $array_js = array($array_js);
336 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200337
Derek Jones811f4752010-03-02 18:13:59 -0600338 foreach ($array_js as $js)
339 {
340 $this->jquery_code_for_compile[] = "\t$js\n";
341 }
342 }
343
344 // --------------------------------------------------------------------
345
346 /**
347 * Resize
348 *
349 * Outputs a jQuery resize event
350 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200351 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600352 * @param string The element to attach the event to
353 * @param string The code to execute
354 * @return string
355 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200356 protected function _resize($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600357 {
358 return $this->_add_event($element, $js, 'resize');
359 }
360
361 // --------------------------------------------------------------------
362
363 /**
364 * Scroll
365 *
366 * Outputs a jQuery scroll event
367 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200368 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600369 * @param string The element to attach the event to
370 * @param string The code to execute
371 * @return string
372 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200373 protected function _scroll($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600374 {
375 return $this->_add_event($element, $js, 'scroll');
376 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200377
Derek Jones811f4752010-03-02 18:13:59 -0600378 // --------------------------------------------------------------------
379
380 /**
381 * Unload
382 *
383 * Outputs a jQuery unload event
384 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200385 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600386 * @param string The element to attach the event to
387 * @param string The code to execute
388 * @return string
389 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200390 protected function _unload($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600391 {
392 return $this->_add_event($element, $js, 'unload');
393 }
394
Andrey Andreevad47f942011-12-25 19:13:48 +0200395 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600396 // Effects
Andrey Andreevad47f942011-12-25 19:13:48 +0200397 // --------------------------------------------------------------------
398
Derek Jones811f4752010-03-02 18:13:59 -0600399 /**
400 * Add Class
401 *
402 * Outputs a jQuery addClass event
403 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200404 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600405 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200406 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600407 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200408 protected function _addClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600409 {
410 $element = $this->_prep_element($element);
Andrey Andreevad47f942011-12-25 19:13:48 +0200411 return "$({$element}).addClass(\"$class\");";
Derek Jones811f4752010-03-02 18:13:59 -0600412 }
413
414 // --------------------------------------------------------------------
415
416 /**
417 * Animate
418 *
419 * Outputs a jQuery animate event
420 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200421 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600422 * @param string - element
423 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
424 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200425 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600426 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200427 protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
Derek Jones811f4752010-03-02 18:13:59 -0600428 {
429 $element = $this->_prep_element($element);
430 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200431
Derek Jones811f4752010-03-02 18:13:59 -0600432 $animations = "\t\t\t";
Andrey Andreevad47f942011-12-25 19:13:48 +0200433
Derek Jones811f4752010-03-02 18:13:59 -0600434 foreach ($params as $param=>$value)
435 {
436 $animations .= $param.': \''.$value.'\', ';
437 }
438
439 $animations = substr($animations, 0, -2); // remove the last ", "
440
441 if ($speed != '')
442 {
443 $speed = ', '.$speed;
444 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200445
Derek Jones811f4752010-03-02 18:13:59 -0600446 if ($extra != '')
447 {
448 $extra = ', '.$extra;
449 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200450
451 return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
Derek Jones811f4752010-03-02 18:13:59 -0600452 }
453
454 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200455
Derek Jones811f4752010-03-02 18:13:59 -0600456 /**
457 * Fade In
458 *
459 * Outputs a jQuery hide event
460 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200461 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600462 * @param string - element
463 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
464 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200465 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600466 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200467 protected function _fadeIn($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600468 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200469 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600470 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200471
Derek Jones811f4752010-03-02 18:13:59 -0600472 if ($callback != '')
473 {
474 $callback = ", function(){\n{$callback}\n}";
475 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200476
477 return "$({$element}).fadeIn({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600478 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200479
Derek Jones811f4752010-03-02 18:13:59 -0600480 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200481
Derek Jones811f4752010-03-02 18:13:59 -0600482 /**
483 * Fade Out
484 *
485 * Outputs a jQuery hide event
486 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200487 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600488 * @param string - element
489 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
490 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200491 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600492 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200493 protected function _fadeOut($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600494 {
495 $element = $this->_prep_element($element);
496 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200497
Derek Jones811f4752010-03-02 18:13:59 -0600498 if ($callback != '')
499 {
500 $callback = ", function(){\n{$callback}\n}";
501 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200502
503 return "$({$element}).fadeOut({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600504 }
505
506 // --------------------------------------------------------------------
507
508 /**
509 * Hide
510 *
511 * Outputs a jQuery hide action
512 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200513 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600514 * @param string - element
515 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
516 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200517 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600518 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200519 protected function _hide($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600520 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200521 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600522 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200523
Derek Jones811f4752010-03-02 18:13:59 -0600524 if ($callback != '')
525 {
526 $callback = ", function(){\n{$callback}\n}";
527 }
Derek Jones811f4752010-03-02 18:13:59 -0600528
Andrey Andreevad47f942011-12-25 19:13:48 +0200529 return "$({$element}).hide({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600530 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200531
Derek Jones811f4752010-03-02 18:13:59 -0600532 // --------------------------------------------------------------------
533
534 /**
535 * Remove Class
536 *
537 * Outputs a jQuery remove class event
538 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200539 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600540 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200541 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600542 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200543 protected function _removeClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600544 {
545 $element = $this->_prep_element($element);
Andrey Andreevad47f942011-12-25 19:13:48 +0200546 return "$({$element}).removeClass(\"$class\");";
Derek Jones811f4752010-03-02 18:13:59 -0600547 }
548
549 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200550
Derek Jones811f4752010-03-02 18:13:59 -0600551 /**
552 * Slide Up
553 *
554 * Outputs a jQuery slideUp event
555 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200556 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600557 * @param string - element
558 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
559 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200560 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600561 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200562 protected function _slideUp($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600563 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200564 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600565 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200566
Derek Jones811f4752010-03-02 18:13:59 -0600567 if ($callback != '')
568 {
569 $callback = ", function(){\n{$callback}\n}";
570 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200571
572 return "$({$element}).slideUp({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600573 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200574
Derek Jones811f4752010-03-02 18:13:59 -0600575 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200576
Derek Jones811f4752010-03-02 18:13:59 -0600577 /**
578 * Slide Down
579 *
580 * Outputs a jQuery slideDown event
581 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200582 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600583 * @param string - element
584 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
585 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200586 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600587 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200588 protected function _slideDown($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600589 {
590 $element = $this->_prep_element($element);
591 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200592
Derek Jones811f4752010-03-02 18:13:59 -0600593 if ($callback != '')
594 {
595 $callback = ", function(){\n{$callback}\n}";
596 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200597
598 return "$({$element}).slideDown({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600599 }
600
601 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200602
Derek Jones811f4752010-03-02 18:13:59 -0600603 /**
604 * Slide Toggle
605 *
606 * Outputs a jQuery slideToggle event
607 *
608 * @access public
609 * @param string - element
610 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
611 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200612 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600613 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200614 protected function _slideToggle($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600615 {
616 $element = $this->_prep_element($element);
617 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200618
Derek Jones811f4752010-03-02 18:13:59 -0600619 if ($callback != '')
620 {
621 $callback = ", function(){\n{$callback}\n}";
622 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200623
624 return "$({$element}).slideToggle({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600625 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200626
Derek Jones811f4752010-03-02 18:13:59 -0600627 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200628
Derek Jones811f4752010-03-02 18:13:59 -0600629 /**
630 * Toggle
631 *
632 * Outputs a jQuery toggle event
633 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200634 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600635 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200636 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600637 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200638 protected function _toggle($element = 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600639 {
640 $element = $this->_prep_element($element);
Andrey Andreevad47f942011-12-25 19:13:48 +0200641 return "$({$element}).toggle();";
Derek Jones811f4752010-03-02 18:13:59 -0600642 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200643
Derek Jones811f4752010-03-02 18:13:59 -0600644 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200645
Derek Jones811f4752010-03-02 18:13:59 -0600646 /**
647 * Toggle Class
648 *
649 * Outputs a jQuery toggle class event
650 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200651 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600652 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200653 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600654 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200655 protected function _toggleClass($element = 'this', $class='')
Derek Jones811f4752010-03-02 18:13:59 -0600656 {
657 $element = $this->_prep_element($element);
Andrey Andreevad47f942011-12-25 19:13:48 +0200658 return "$({$element}).toggleClass(\"$class\");";
Derek Jones811f4752010-03-02 18:13:59 -0600659 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200660
Derek Jones811f4752010-03-02 18:13:59 -0600661 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200662
Derek Jones811f4752010-03-02 18:13:59 -0600663 /**
664 * Show
665 *
666 * Outputs a jQuery show event
667 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200668 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600669 * @param string - element
670 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
671 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200672 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600673 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200674 protected function _show($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600675 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200676 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600677 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200678
Derek Jones811f4752010-03-02 18:13:59 -0600679 if ($callback != '')
680 {
681 $callback = ", function(){\n{$callback}\n}";
682 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200683
684 return "$({$element}).show({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600685 }
686
687 // --------------------------------------------------------------------
688
689 /**
690 * Updater
691 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200692 * An Ajax call that populates the designated DOM node with
Derek Jones811f4752010-03-02 18:13:59 -0600693 * returned content
694 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200695 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600696 * @param string The element to attach the event to
697 * @param string the controller to run the call against
698 * @param string optional parameters
699 * @return string
700 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200701
702 protected function _updater($container = 'this', $controller, $options = '')
703 {
Derek Jones811f4752010-03-02 18:13:59 -0600704 $container = $this->_prep_element($container);
Derek Jones811f4752010-03-02 18:13:59 -0600705 $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
Andrey Andreevad47f942011-12-25 19:13:48 +0200706
Derek Jones811f4752010-03-02 18:13:59 -0600707 // ajaxStart and ajaxStop are better choices here... but this is a stop gap
708 if ($this->CI->config->item('javascript_ajax_img') == '')
709 {
710 $loading_notifier = "Loading...";
711 }
712 else
713 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200714 $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 -0600715 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200716
717 $updater = "$($container).empty();\n" // anything that was in... get it out
718 . "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image
Derek Jones811f4752010-03-02 18:13:59 -0600719
720 $request_options = '';
721 if ($options != '')
722 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200723 $request_options .= ', {'
724 . (is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'")
725 . '}';
Derek Jones811f4752010-03-02 18:13:59 -0600726 }
727
Andrey Andreevad47f942011-12-25 19:13:48 +0200728 return $updater."\t\t$($container).load('$controller'$request_options);";
Derek Jones811f4752010-03-02 18:13:59 -0600729 }
730
731
732 // --------------------------------------------------------------------
733 // Pre-written handy stuff
734 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200735
Derek Jones811f4752010-03-02 18:13:59 -0600736 /**
737 * Zebra tables
738 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200739 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600740 * @param string table name
741 * @param string plugin location
742 * @return string
743 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200744 protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
Derek Jones811f4752010-03-02 18:13:59 -0600745 {
746 $class = ($class != '') ? '.'.$class : '';
Derek Jones37f4b9c2011-07-01 17:56:50 -0500747 $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
Derek Jones811f4752010-03-02 18:13:59 -0600748
749 $this->jquery_code_for_compile[] = $zebra;
750
751 if ($hover != '')
752 {
753 $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
754 }
755
756 return $zebra;
757 }
758
Derek Jones811f4752010-03-02 18:13:59 -0600759 // --------------------------------------------------------------------
760 // Plugins
761 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200762
Derek Jones811f4752010-03-02 18:13:59 -0600763 /**
764 * Corner Plugin
765 *
766 * http://www.malsup.com/jquery/corner/
767 *
768 * @access public
769 * @param string target
770 * @return string
771 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200772 public function corner($element = '', $corner_style = '')
Derek Jones811f4752010-03-02 18:13:59 -0600773 {
774 // may want to make this configurable down the road
775 $corner_location = '/plugins/jquery.corner.js';
776
777 if ($corner_style != '')
778 {
779 $corner_style = '"'.$corner_style.'"';
780 }
781
782 return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");";
783 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200784
Derek Jones811f4752010-03-02 18:13:59 -0600785 // --------------------------------------------------------------------
786
787 /**
788 * modal window
789 *
790 * Load a thickbox modal window
791 *
792 * @access public
793 * @return void
794 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200795 public function modal($src, $relative = FALSE)
796 {
Derek Jones811f4752010-03-02 18:13:59 -0600797 $this->jquery_code_for_load[] = $this->external($src, $relative);
798 }
799
800 // --------------------------------------------------------------------
801
802 /**
803 * Effect
804 *
805 * Load an Effect library
806 *
807 * @access public
808 * @return void
809 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200810 public function effect($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600811 {
812 $this->jquery_code_for_load[] = $this->external($src, $relative);
813 }
814
815 // --------------------------------------------------------------------
816
817 /**
818 * Plugin
819 *
820 * Load a plugin library
821 *
822 * @access public
823 * @return void
824 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200825 public function plugin($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600826 {
827 $this->jquery_code_for_load[] = $this->external($src, $relative);
828 }
829
830 // --------------------------------------------------------------------
831
832 /**
833 * UI
834 *
835 * Load a user interface library
836 *
837 * @access public
838 * @return void
839 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200840 public function ui($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600841 {
842 $this->jquery_code_for_load[] = $this->external($src, $relative);
843 }
844 // --------------------------------------------------------------------
845
846 /**
847 * Sortable
848 *
849 * Creates a jQuery sortable
850 *
851 * @access public
852 * @return void
853 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200854 public function sortable($element, $options = array())
Derek Jones811f4752010-03-02 18:13:59 -0600855 {
856
857 if (count($options) > 0)
858 {
859 $sort_options = array();
860 foreach ($options as $k=>$v)
861 {
862 $sort_options[] = "\n\t\t".$k.': '.$v."";
863 }
864 $sort_options = implode(",", $sort_options);
865 }
866 else
867 {
868 $sort_options = '';
869 }
870
871 return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});";
872 }
873
874 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200875
Derek Jones811f4752010-03-02 18:13:59 -0600876 /**
877 * Table Sorter Plugin
878 *
879 * @access public
880 * @param string table name
881 * @param string plugin location
882 * @return string
883 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200884 public function tablesorter($table = '', $options = '')
Derek Jones811f4752010-03-02 18:13:59 -0600885 {
886 $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n";
887 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200888
Derek Jones811f4752010-03-02 18:13:59 -0600889 // --------------------------------------------------------------------
890 // Class functions
891 // --------------------------------------------------------------------
892
893 /**
894 * Add Event
895 *
896 * Constructs the syntax for an event, and adds to into the array for compilation
897 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200898 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600899 * @param string The element to attach the event to
900 * @param string The code to execute
901 * @param string The event to pass
902 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200903 */
904 protected function _add_event($element, $js, $event)
Derek Jones811f4752010-03-02 18:13:59 -0600905 {
906 if (is_array($js))
907 {
908 $js = implode("\n\t\t", $js);
909
910 }
911
912 $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n";
913 $this->jquery_code_for_compile[] = $event;
914 return $event;
915 }
916
917 // --------------------------------------------------------------------
918
919 /**
920 * Compile
921 *
922 * As events are specified, they are stored in an array
923 * This funciton compiles them all for output on a page
924 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200925 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600926 * @return string
927 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200928 protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600929 {
930 // External references
931 $external_scripts = implode('', $this->jquery_code_for_load);
932 $this->CI->load->vars(array('library_src' => $external_scripts));
933
Andrey Andreevad47f942011-12-25 19:13:48 +0200934 if (count($this->jquery_code_for_compile) === 0)
Derek Jones811f4752010-03-02 18:13:59 -0600935 {
936 // no inline references, let's just return
937 return;
938 }
939
940 // Inline references
Andrey Andreevad47f942011-12-25 19:13:48 +0200941 $script = '$(document).ready(function() {'."\n"
942 . implode('', $this->jquery_code_for_compile)
943 . '});';
944
Derek Jones811f4752010-03-02 18:13:59 -0600945 $output = ($script_tags === FALSE) ? $script : $this->inline($script);
946
947 $this->CI->load->vars(array($view_var => $output));
948
949 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200950
Derek Jones811f4752010-03-02 18:13:59 -0600951 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200952
Derek Jones811f4752010-03-02 18:13:59 -0600953 /**
954 * Clear Compile
955 *
956 * Clears the array of script events collected for output
957 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200958 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600959 * @return void
960 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200961 protected function _clear_compile()
Derek Jones811f4752010-03-02 18:13:59 -0600962 {
963 $this->jquery_code_for_compile = array();
964 }
965
966 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200967
Derek Jones811f4752010-03-02 18:13:59 -0600968 /**
969 * Document Ready
970 *
971 * A wrapper for writing document.ready()
972 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200973 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -0600974 * @return string
975 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200976 protected function _document_ready($js)
Derek Jones811f4752010-03-02 18:13:59 -0600977 {
978 if ( ! is_array($js))
979 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200980 $js = array($js);
Derek Jones811f4752010-03-02 18:13:59 -0600981 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200982
Derek Jones811f4752010-03-02 18:13:59 -0600983 foreach ($js as $script)
984 {
985 $this->jquery_code_for_compile[] = $script;
986 }
987 }
988
989 // --------------------------------------------------------------------
990
991 /**
992 * Script Tag
993 *
994 * Outputs the script tag that loads the jquery.js file into an HTML document
995 *
996 * @access public
997 * @param string
998 * @return string
999 */
Andrey Andreevad47f942011-12-25 19:13:48 +02001000 public function script($library_src = '', $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -06001001 {
1002 $library_src = $this->external($library_src, $relative);
1003 $this->jquery_code_for_load[] = $library_src;
1004 return $library_src;
1005 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001006
Derek Jones811f4752010-03-02 18:13:59 -06001007 // --------------------------------------------------------------------
1008
1009 /**
1010 * Prep Element
1011 *
1012 * Puts HTML element in quotes for use in jQuery code
1013 * unless the supplied element is the Javascript 'this'
1014 * object, in which case no quotes are added
1015 *
Andrey Andreevad47f942011-12-25 19:13:48 +02001016 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -06001017 * @param string
1018 * @return string
1019 */
Andrey Andreevad47f942011-12-25 19:13:48 +02001020 protected function _prep_element($element)
Derek Jones811f4752010-03-02 18:13:59 -06001021 {
1022 if ($element != 'this')
1023 {
1024 $element = '"'.$element.'"';
1025 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001026
Derek Jones811f4752010-03-02 18:13:59 -06001027 return $element;
1028 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001029
Derek Jones811f4752010-03-02 18:13:59 -06001030 // --------------------------------------------------------------------
1031
1032 /**
1033 * Validate Speed
1034 *
1035 * Ensures the speed parameter is valid for jQuery
1036 *
Andrey Andreevad47f942011-12-25 19:13:48 +02001037 * @access protected
Derek Jones811f4752010-03-02 18:13:59 -06001038 * @param string
1039 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +02001040 */
1041 protected function _validate_speed($speed)
Derek Jones811f4752010-03-02 18:13:59 -06001042 {
1043 if (in_array($speed, array('slow', 'normal', 'fast')))
1044 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001045 return '"'.$speed.'"';
Derek Jones811f4752010-03-02 18:13:59 -06001046 }
1047 elseif (preg_match("/[^0-9]/", $speed))
1048 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001049 return '';
Derek Jones811f4752010-03-02 18:13:59 -06001050 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001051
Derek Jones811f4752010-03-02 18:13:59 -06001052 return $speed;
1053 }
1054
1055}
1056
1057/* End of file Jquery.php */
Andrey Andreevad47f942011-12-25 19:13:48 +02001058/* Location: ./system/libraries/Jquery.php */