blob: ed02fadb778ee87745ed5f7b2317c02f9fac35b2 [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 */
Greg Akeraacfe482010-03-03 12:26:31 -060037class CI_Jquery extends CI_Javascript {
Derek Jones811f4752010-03-02 18:13:59 -060038
Andrey Andreevad47f942011-12-25 19:13:48 +020039 protected $_javascript_folder = 'js';
40 public $jquery_code_for_load = array();
41 public $jquery_code_for_compile = array();
42 public $jquery_corner_active = FALSE;
43 public $jquery_table_sorter_active = FALSE;
44 public $jquery_table_sorter_pager_active = FALSE;
45 public $jquery_ajax_img = '';
Derek Jones811f4752010-03-02 18:13:59 -060046
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030047 /**
48 * Constructor
49 *
50 * @param array $params
51 * @return void
52 */
Greg Akera9263282010-11-10 15:26:43 -060053 public function __construct($params)
Derek Jones811f4752010-03-02 18:13:59 -060054 {
Andrey Andreevad47f942011-12-25 19:13:48 +020055 $this->CI =& get_instance();
Derek Jones811f4752010-03-02 18:13:59 -060056 extract($params);
57
58 if ($autoload === TRUE)
59 {
Andrey Andreevad47f942011-12-25 19:13:48 +020060 $this->script();
Derek Jones811f4752010-03-02 18:13:59 -060061 }
Andrey Andreevad47f942011-12-25 19:13:48 +020062
Andrey Andreev56454792012-05-17 14:32:19 +030063 log_message('debug', 'Jquery Class Initialized');
Derek Jones811f4752010-03-02 18:13:59 -060064 }
Andrey Andreevad47f942011-12-25 19:13:48 +020065
66 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060067 // Event Code
Andrey Andreevad47f942011-12-25 19:13:48 +020068 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060069
70 /**
71 * Blur
72 *
73 * Outputs a jQuery blur event
74 *
Derek Jones811f4752010-03-02 18:13:59 -060075 * @param string The element to attach the event to
76 * @param string The code to execute
77 * @return string
78 */
Andrey Andreevad47f942011-12-25 19:13:48 +020079 protected function _blur($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060080 {
81 return $this->_add_event($element, $js, 'blur');
82 }
Andrey Andreevad47f942011-12-25 19:13:48 +020083
Derek Jones811f4752010-03-02 18:13:59 -060084 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +020085
Derek Jones811f4752010-03-02 18:13:59 -060086 /**
87 * Change
88 *
89 * Outputs a jQuery change event
90 *
Derek Jones811f4752010-03-02 18:13:59 -060091 * @param string The element to attach the event to
92 * @param string The code to execute
93 * @return string
94 */
Andrey Andreevad47f942011-12-25 19:13:48 +020095 protected function _change($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060096 {
97 return $this->_add_event($element, $js, 'change');
98 }
Andrey Andreevad47f942011-12-25 19:13:48 +020099
Derek Jones811f4752010-03-02 18:13:59 -0600100 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200101
Derek Jones811f4752010-03-02 18:13:59 -0600102 /**
103 * Click
104 *
105 * Outputs a jQuery click event
106 *
Derek Jones811f4752010-03-02 18:13:59 -0600107 * @param string The element to attach the event to
108 * @param string The code to execute
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300109 * @param bool whether or not to return false
Derek Jones811f4752010-03-02 18:13:59 -0600110 * @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 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300114 is_array($js) OR $js = array($js);
Derek Jones811f4752010-03-02 18:13:59 -0600115
116 if ($ret_false)
117 {
Andrey Andreev56454792012-05-17 14:32:19 +0300118 $js[] = 'return false;';
Derek Jones811f4752010-03-02 18:13:59 -0600119 }
120
121 return $this->_add_event($element, $js, 'click');
122 }
123
124 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200125
Derek Jones811f4752010-03-02 18:13:59 -0600126 /**
127 * Double Click
128 *
129 * Outputs a jQuery dblclick event
130 *
Derek Jones811f4752010-03-02 18:13:59 -0600131 * @param string The element to attach the event to
132 * @param string The code to execute
133 * @return string
134 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200135 protected function _dblclick($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600136 {
137 return $this->_add_event($element, $js, 'dblclick');
138 }
139
140 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200141
Derek Jones811f4752010-03-02 18:13:59 -0600142 /**
143 * Error
144 *
145 * Outputs a jQuery error event
146 *
Derek Jones811f4752010-03-02 18:13:59 -0600147 * @param string The element to attach the event to
148 * @param string The code to execute
149 * @return string
150 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200151 protected function _error($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600152 {
153 return $this->_add_event($element, $js, 'error');
154 }
155
156 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200157
Derek Jones811f4752010-03-02 18:13:59 -0600158 /**
159 * Focus
160 *
161 * Outputs a jQuery focus event
162 *
Derek Jones811f4752010-03-02 18:13:59 -0600163 * @param string The element to attach the event to
164 * @param string The code to execute
165 * @return string
166 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200167 protected function _focus($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600168 {
169 return $this->_add_event($element, $js, 'focus');
170 }
171
172 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200173
Derek Jones811f4752010-03-02 18:13:59 -0600174 /**
175 * Hover
176 *
177 * Outputs a jQuery hover event
178 *
Derek Jones811f4752010-03-02 18:13:59 -0600179 * @param string - element
180 * @param string - Javascript code for mouse over
181 * @param string - Javascript code for mouse out
Barry Mienydd671972010-10-04 16:33:58 +0200182 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600183 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200184 protected function _hover($element = 'this', $over, $out)
Derek Jones811f4752010-03-02 18:13:59 -0600185 {
Andrey Andreev56454792012-05-17 14:32:19 +0300186 $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 -0600187
188 $this->jquery_code_for_compile[] = $event;
189
190 return $event;
191 }
192
193 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200194
Derek Jones811f4752010-03-02 18:13:59 -0600195 /**
196 * Keydown
197 *
198 * Outputs a jQuery keydown event
199 *
Derek Jones811f4752010-03-02 18:13:59 -0600200 * @param string The element to attach the event to
201 * @param string The code to execute
202 * @return string
203 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200204 protected function _keydown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600205 {
206 return $this->_add_event($element, $js, 'keydown');
207 }
208
209 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200210
Derek Jones811f4752010-03-02 18:13:59 -0600211 /**
212 * Keyup
213 *
214 * Outputs a jQuery keydown event
215 *
Derek Jones811f4752010-03-02 18:13:59 -0600216 * @param string The element to attach the event to
217 * @param string The code to execute
218 * @return string
219 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200220 protected function _keyup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600221 {
222 return $this->_add_event($element, $js, 'keyup');
Andrey Andreevad47f942011-12-25 19:13:48 +0200223 }
Derek Jones811f4752010-03-02 18:13:59 -0600224
225 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200226
Derek Jones811f4752010-03-02 18:13:59 -0600227 /**
228 * Load
229 *
230 * Outputs a jQuery load event
231 *
Derek Jones811f4752010-03-02 18:13:59 -0600232 * @param string The element to attach the event to
233 * @param string The code to execute
234 * @return string
235 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200236 protected function _load($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600237 {
238 return $this->_add_event($element, $js, 'load');
Andrey Andreevad47f942011-12-25 19:13:48 +0200239 }
240
Derek Jones811f4752010-03-02 18:13:59 -0600241 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200242
Derek Jones811f4752010-03-02 18:13:59 -0600243 /**
244 * Mousedown
245 *
246 * Outputs a jQuery mousedown event
247 *
Derek Jones811f4752010-03-02 18:13:59 -0600248 * @param string The element to attach the event to
249 * @param string The code to execute
250 * @return string
251 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200252 protected function _mousedown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600253 {
254 return $this->_add_event($element, $js, 'mousedown');
255 }
256
257 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200258
Derek Jones811f4752010-03-02 18:13:59 -0600259 /**
260 * Mouse Out
261 *
262 * Outputs a jQuery mouseout event
263 *
Derek Jones811f4752010-03-02 18:13:59 -0600264 * @param string The element to attach the event to
265 * @param string The code to execute
266 * @return string
267 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200268 protected function _mouseout($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600269 {
270 return $this->_add_event($element, $js, 'mouseout');
271 }
272
273 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200274
Derek Jones811f4752010-03-02 18:13:59 -0600275 /**
276 * Mouse Over
277 *
278 * Outputs a jQuery mouseover event
279 *
Derek Jones811f4752010-03-02 18:13:59 -0600280 * @param string The element to attach the event to
281 * @param string The code to execute
282 * @return string
283 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200284 protected function _mouseover($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600285 {
286 return $this->_add_event($element, $js, 'mouseover');
287 }
288
289 // --------------------------------------------------------------------
290
291 /**
292 * Mouseup
293 *
294 * Outputs a jQuery mouseup event
295 *
Derek Jones811f4752010-03-02 18:13:59 -0600296 * @param string The element to attach the event to
297 * @param string The code to execute
298 * @return string
299 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200300 protected function _mouseup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600301 {
302 return $this->_add_event($element, $js, 'mouseup');
303 }
304
305 // --------------------------------------------------------------------
306
307 /**
308 * Output
309 *
310 * Outputs script directly
311 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300312 * @param array $array_js = array()
313 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600314 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300315 protected function _output($array_js = array())
Derek Jones811f4752010-03-02 18:13:59 -0600316 {
317 if ( ! is_array($array_js))
318 {
319 $array_js = array($array_js);
320 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200321
Derek Jones811f4752010-03-02 18:13:59 -0600322 foreach ($array_js as $js)
323 {
Andrey Andreev56454792012-05-17 14:32:19 +0300324 $this->jquery_code_for_compile[] = "\t".$js."\n";
Derek Jones811f4752010-03-02 18:13:59 -0600325 }
326 }
327
328 // --------------------------------------------------------------------
329
330 /**
331 * Resize
332 *
333 * Outputs a jQuery resize event
334 *
Derek Jones811f4752010-03-02 18:13:59 -0600335 * @param string The element to attach the event to
336 * @param string The code to execute
337 * @return string
338 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200339 protected function _resize($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600340 {
341 return $this->_add_event($element, $js, 'resize');
342 }
343
344 // --------------------------------------------------------------------
345
346 /**
347 * Scroll
348 *
349 * Outputs a jQuery scroll event
350 *
Derek Jones811f4752010-03-02 18:13:59 -0600351 * @param string The element to attach the event to
352 * @param string The code to execute
353 * @return string
354 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200355 protected function _scroll($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600356 {
357 return $this->_add_event($element, $js, 'scroll');
358 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200359
Derek Jones811f4752010-03-02 18:13:59 -0600360 // --------------------------------------------------------------------
361
362 /**
363 * Unload
364 *
365 * Outputs a jQuery unload event
366 *
Derek Jones811f4752010-03-02 18:13:59 -0600367 * @param string The element to attach the event to
368 * @param string The code to execute
369 * @return string
370 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200371 protected function _unload($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600372 {
373 return $this->_add_event($element, $js, 'unload');
374 }
375
Andrey Andreevad47f942011-12-25 19:13:48 +0200376 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600377 // Effects
Andrey Andreevad47f942011-12-25 19:13:48 +0200378 // --------------------------------------------------------------------
379
Derek Jones811f4752010-03-02 18:13:59 -0600380 /**
381 * Add Class
382 *
383 * Outputs a jQuery addClass event
384 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300385 * @param string $element = 'this'
386 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200387 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600388 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300389 protected function _addClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600390 {
391 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300392 return '$('.$element.').addClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600393 }
394
395 // --------------------------------------------------------------------
396
397 /**
398 * Animate
399 *
400 * Outputs a jQuery animate event
401 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300402 * @param string $element = 'this'
403 * @param array $params = array()
404 * @param string $speed = '' 'slow', 'normal', 'fast', or time in milliseconds
405 * @param string $extra = ''
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 _animate($element = 'this', $params = array(), $speed = '', $extra = '')
Derek Jones811f4752010-03-02 18:13:59 -0600409 {
410 $element = $this->_prep_element($element);
411 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200412
Derek Jones811f4752010-03-02 18:13:59 -0600413 $animations = "\t\t\t";
Andrey Andreevad47f942011-12-25 19:13:48 +0200414
Andrey Andreev56454792012-05-17 14:32:19 +0300415 foreach ($params as $param => $value)
Derek Jones811f4752010-03-02 18:13:59 -0600416 {
Andrey Andreev56454792012-05-17 14:32:19 +0300417 $animations .= $param.": '".$value."', ";
Derek Jones811f4752010-03-02 18:13:59 -0600418 }
419
420 $animations = substr($animations, 0, -2); // remove the last ", "
421
Alex Bilbied261b1e2012-06-02 11:12:16 +0100422 if ($speed !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600423 {
424 $speed = ', '.$speed;
425 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200426
Alex Bilbied261b1e2012-06-02 11:12:16 +0100427 if ($extra !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600428 {
429 $extra = ', '.$extra;
430 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200431
Andrey Andreev56454792012-05-17 14:32:19 +0300432 return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');';
Derek Jones811f4752010-03-02 18:13:59 -0600433 }
434
435 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200436
Derek Jones811f4752010-03-02 18:13:59 -0600437 /**
438 * Fade In
439 *
440 * Outputs a jQuery hide event
441 *
Derek Jones811f4752010-03-02 18:13:59 -0600442 * @param string - element
443 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
444 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200445 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600446 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200447 protected function _fadeIn($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600448 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200449 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600450 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200451
Alex Bilbied261b1e2012-06-02 11:12:16 +0100452 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600453 {
454 $callback = ", function(){\n{$callback}\n}";
455 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200456
457 return "$({$element}).fadeIn({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600458 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200459
Derek Jones811f4752010-03-02 18:13:59 -0600460 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200461
Derek Jones811f4752010-03-02 18:13:59 -0600462 /**
463 * Fade Out
464 *
465 * Outputs a jQuery hide event
466 *
Derek Jones811f4752010-03-02 18:13:59 -0600467 * @param string - element
468 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
469 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200470 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600471 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200472 protected function _fadeOut($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600473 {
474 $element = $this->_prep_element($element);
475 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200476
Alex Bilbied261b1e2012-06-02 11:12:16 +0100477 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600478 {
479 $callback = ", function(){\n{$callback}\n}";
480 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200481
Andrey Andreev56454792012-05-17 14:32:19 +0300482 return '$('.$element.').fadeOut('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600483 }
484
485 // --------------------------------------------------------------------
486
487 /**
488 * Hide
489 *
490 * Outputs a jQuery hide action
491 *
Derek Jones811f4752010-03-02 18:13:59 -0600492 * @param string - element
493 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
494 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200495 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600496 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200497 protected function _hide($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600498 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200499 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600500 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200501
Alex Bilbied261b1e2012-06-02 11:12:16 +0100502 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600503 {
504 $callback = ", function(){\n{$callback}\n}";
505 }
Derek Jones811f4752010-03-02 18:13:59 -0600506
Andrey Andreevad47f942011-12-25 19:13:48 +0200507 return "$({$element}).hide({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600508 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200509
Derek Jones811f4752010-03-02 18:13:59 -0600510 // --------------------------------------------------------------------
511
512 /**
513 * Remove Class
514 *
515 * Outputs a jQuery remove class event
516 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300517 * @param string $element = 'this'
518 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200519 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600520 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300521 protected function _removeClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600522 {
523 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300524 return '$('.$element.').removeClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600525 }
526
527 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200528
Derek Jones811f4752010-03-02 18:13:59 -0600529 /**
530 * Slide Up
531 *
532 * Outputs a jQuery slideUp event
533 *
Derek Jones811f4752010-03-02 18:13:59 -0600534 * @param string - element
535 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
536 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200537 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600538 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200539 protected function _slideUp($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600540 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200541 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600542 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200543
Alex Bilbied261b1e2012-06-02 11:12:16 +0100544 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600545 {
546 $callback = ", function(){\n{$callback}\n}";
547 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200548
Andrey Andreev56454792012-05-17 14:32:19 +0300549 return '$('.$element.').slideUp('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600550 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200551
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 * Slide Down
556 *
557 * Outputs a jQuery slideDown event
558 *
Derek Jones811f4752010-03-02 18:13:59 -0600559 * @param string - element
560 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
561 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200562 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600563 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200564 protected function _slideDown($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600565 {
566 $element = $this->_prep_element($element);
567 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200568
Alex Bilbied261b1e2012-06-02 11:12:16 +0100569 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600570 {
571 $callback = ", function(){\n{$callback}\n}";
572 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200573
Andrey Andreev56454792012-05-17 14:32:19 +0300574 return '$('.$element.').slideDown('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600575 }
576
577 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200578
Derek Jones811f4752010-03-02 18:13:59 -0600579 /**
580 * Slide Toggle
581 *
582 * Outputs a jQuery slideToggle event
583 *
Derek Jones811f4752010-03-02 18:13:59 -0600584 * @param string - element
585 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
586 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200587 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600588 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200589 protected function _slideToggle($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600590 {
591 $element = $this->_prep_element($element);
592 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200593
Alex Bilbied261b1e2012-06-02 11:12:16 +0100594 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600595 {
596 $callback = ", function(){\n{$callback}\n}";
597 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200598
Andrey Andreev56454792012-05-17 14:32:19 +0300599 return '$('.$element.').slideToggle('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600600 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200601
Derek Jones811f4752010-03-02 18:13:59 -0600602 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200603
Derek Jones811f4752010-03-02 18:13:59 -0600604 /**
605 * Toggle
606 *
607 * Outputs a jQuery toggle event
608 *
Derek Jones811f4752010-03-02 18:13:59 -0600609 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200610 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600611 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200612 protected function _toggle($element = 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600613 {
614 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300615 return '$('.$element.').toggle();';
Derek Jones811f4752010-03-02 18:13:59 -0600616 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200617
Derek Jones811f4752010-03-02 18:13:59 -0600618 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200619
Derek Jones811f4752010-03-02 18:13:59 -0600620 /**
621 * Toggle Class
622 *
623 * Outputs a jQuery toggle class event
624 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300625 * @param string $element = 'this'
626 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200627 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600628 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300629 protected function _toggleClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600630 {
631 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300632 return '$('.$element.').toggleClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600633 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200634
Derek Jones811f4752010-03-02 18:13:59 -0600635 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200636
Derek Jones811f4752010-03-02 18:13:59 -0600637 /**
638 * Show
639 *
640 * Outputs a jQuery show event
641 *
Derek Jones811f4752010-03-02 18:13:59 -0600642 * @param string - element
643 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
644 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200645 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600646 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200647 protected function _show($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600648 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200649 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600650 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200651
Alex Bilbied261b1e2012-06-02 11:12:16 +0100652 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600653 {
654 $callback = ", function(){\n{$callback}\n}";
655 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200656
Andrey Andreev56454792012-05-17 14:32:19 +0300657 return '$('.$element.').show('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600658 }
659
660 // --------------------------------------------------------------------
661
662 /**
663 * Updater
664 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200665 * An Ajax call that populates the designated DOM node with
Derek Jones811f4752010-03-02 18:13:59 -0600666 * returned content
667 *
Derek Jones811f4752010-03-02 18:13:59 -0600668 * @param string The element to attach the event to
669 * @param string the controller to run the call against
670 * @param string optional parameters
671 * @return string
672 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200673
674 protected function _updater($container = 'this', $controller, $options = '')
675 {
Derek Jones811f4752010-03-02 18:13:59 -0600676 $container = $this->_prep_element($container);
Derek Jones811f4752010-03-02 18:13:59 -0600677 $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
Andrey Andreevad47f942011-12-25 19:13:48 +0200678
Derek Jones811f4752010-03-02 18:13:59 -0600679 // ajaxStart and ajaxStop are better choices here... but this is a stop gap
Alex Bilbied261b1e2012-06-02 11:12:16 +0100680 if ($this->CI->config->item('javascript_ajax_img') === '')
Derek Jones811f4752010-03-02 18:13:59 -0600681 {
Andrey Andreev56454792012-05-17 14:32:19 +0300682 $loading_notifier = 'Loading...';
Derek Jones811f4752010-03-02 18:13:59 -0600683 }
684 else
685 {
Andrey Andreev56454792012-05-17 14:32:19 +0300686 $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 -0600687 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200688
Andrey Andreev56454792012-05-17 14:32:19 +0300689 $updater = '$('.$container.").empty();\n" // anything that was in... get it out
690 ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
Derek Jones811f4752010-03-02 18:13:59 -0600691
692 $request_options = '';
Alex Bilbied261b1e2012-06-02 11:12:16 +0100693 if ($options !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600694 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200695 $request_options .= ', {'
Andrey Andreev56454792012-05-17 14:32:19 +0300696 .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
697 .'}';
Derek Jones811f4752010-03-02 18:13:59 -0600698 }
699
Andrey Andreevad47f942011-12-25 19:13:48 +0200700 return $updater."\t\t$($container).load('$controller'$request_options);";
Derek Jones811f4752010-03-02 18:13:59 -0600701 }
702
Derek Jones811f4752010-03-02 18:13:59 -0600703 // --------------------------------------------------------------------
704 // Pre-written handy stuff
705 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200706
Derek Jones811f4752010-03-02 18:13:59 -0600707 /**
708 * Zebra tables
709 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300710 * @param string $class = ''
711 * @param string $odd = 'odd'
712 * @param string $hover = ''
Derek Jones811f4752010-03-02 18:13:59 -0600713 * @return string
714 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200715 protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
Derek Jones811f4752010-03-02 18:13:59 -0600716 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100717 $class = ($class !== '') ? '.'.$class : '';
vkeranovbfbe8b22012-10-27 18:25:08 +0300718 $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
Derek Jones811f4752010-03-02 18:13:59 -0600719
720 $this->jquery_code_for_compile[] = $zebra;
721
Alex Bilbied261b1e2012-06-02 11:12:16 +0100722 if ($hover !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600723 {
724 $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
725 }
726
727 return $zebra;
728 }
729
Derek Jones811f4752010-03-02 18:13:59 -0600730 // --------------------------------------------------------------------
731 // Plugins
732 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200733
Derek Jones811f4752010-03-02 18:13:59 -0600734 /**
735 * Corner Plugin
736 *
737 * http://www.malsup.com/jquery/corner/
738 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300739 * @param string $element = ''
740 * @param string $corner_style = ''
Derek Jones811f4752010-03-02 18:13:59 -0600741 * @return string
742 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200743 public function corner($element = '', $corner_style = '')
Derek Jones811f4752010-03-02 18:13:59 -0600744 {
745 // may want to make this configurable down the road
746 $corner_location = '/plugins/jquery.corner.js';
747
Alex Bilbied261b1e2012-06-02 11:12:16 +0100748 if ($corner_style !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600749 {
750 $corner_style = '"'.$corner_style.'"';
751 }
752
Andrey Andreev56454792012-05-17 14:32:19 +0300753 return '$('.$this->_prep_element($element).').corner('.$corner_style.');';
Derek Jones811f4752010-03-02 18:13:59 -0600754 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200755
Derek Jones811f4752010-03-02 18:13:59 -0600756 // --------------------------------------------------------------------
757
758 /**
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300759 * Modal window
Derek Jones811f4752010-03-02 18:13:59 -0600760 *
761 * Load a thickbox modal window
762 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300763 * @param string $src
764 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600765 * @return void
766 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200767 public function modal($src, $relative = FALSE)
768 {
Derek Jones811f4752010-03-02 18:13:59 -0600769 $this->jquery_code_for_load[] = $this->external($src, $relative);
770 }
771
772 // --------------------------------------------------------------------
773
774 /**
775 * Effect
776 *
777 * Load an Effect library
778 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300779 * @param string $src
780 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600781 * @return void
782 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200783 public function effect($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600784 {
785 $this->jquery_code_for_load[] = $this->external($src, $relative);
786 }
787
788 // --------------------------------------------------------------------
789
790 /**
791 * Plugin
792 *
793 * Load a plugin library
794 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300795 * @param string $src
796 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600797 * @return void
798 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200799 public function plugin($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600800 {
801 $this->jquery_code_for_load[] = $this->external($src, $relative);
802 }
803
804 // --------------------------------------------------------------------
805
806 /**
807 * UI
808 *
809 * Load a user interface library
810 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300811 * @param string $src
812 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600813 * @return void
814 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200815 public function ui($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600816 {
817 $this->jquery_code_for_load[] = $this->external($src, $relative);
818 }
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300819
Derek Jones811f4752010-03-02 18:13:59 -0600820 // --------------------------------------------------------------------
821
822 /**
823 * Sortable
824 *
825 * Creates a jQuery sortable
826 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300827 * @param string $element
828 * @param array $options = array()
829 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600830 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200831 public function sortable($element, $options = array())
Derek Jones811f4752010-03-02 18:13:59 -0600832 {
Derek Jones811f4752010-03-02 18:13:59 -0600833 if (count($options) > 0)
834 {
835 $sort_options = array();
836 foreach ($options as $k=>$v)
837 {
Andrey Andreev56454792012-05-17 14:32:19 +0300838 $sort_options[] = "\n\t\t".$k.': '.$v;
Derek Jones811f4752010-03-02 18:13:59 -0600839 }
Andrey Andreev56454792012-05-17 14:32:19 +0300840 $sort_options = implode(',', $sort_options);
Derek Jones811f4752010-03-02 18:13:59 -0600841 }
842 else
843 {
844 $sort_options = '';
845 }
846
Andrey Andreev56454792012-05-17 14:32:19 +0300847 return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});";
Derek Jones811f4752010-03-02 18:13:59 -0600848 }
849
850 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200851
Derek Jones811f4752010-03-02 18:13:59 -0600852 /**
853 * Table Sorter Plugin
854 *
Derek Jones811f4752010-03-02 18:13:59 -0600855 * @param string table name
856 * @param string plugin location
857 * @return string
858 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200859 public function tablesorter($table = '', $options = '')
Derek Jones811f4752010-03-02 18:13:59 -0600860 {
Andrey Andreev56454792012-05-17 14:32:19 +0300861 $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n";
Derek Jones811f4752010-03-02 18:13:59 -0600862 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200863
Derek Jones811f4752010-03-02 18:13:59 -0600864 // --------------------------------------------------------------------
865 // Class functions
866 // --------------------------------------------------------------------
867
868 /**
869 * Add Event
870 *
871 * Constructs the syntax for an event, and adds to into the array for compilation
872 *
Derek Jones811f4752010-03-02 18:13:59 -0600873 * @param string The element to attach the event to
874 * @param string The code to execute
875 * @param string The event to pass
876 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200877 */
878 protected function _add_event($element, $js, $event)
Derek Jones811f4752010-03-02 18:13:59 -0600879 {
880 if (is_array($js))
881 {
882 $js = implode("\n\t\t", $js);
883
884 }
885
Andrey Andreev56454792012-05-17 14:32:19 +0300886 $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
Derek Jones811f4752010-03-02 18:13:59 -0600887 $this->jquery_code_for_compile[] = $event;
888 return $event;
889 }
890
891 // --------------------------------------------------------------------
892
893 /**
894 * Compile
895 *
896 * As events are specified, they are stored in an array
897 * This funciton compiles them all for output on a page
898 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300899 * @param string $view_var = 'script_foot'
900 * @param bool $script_tags = TRUE
901 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600902 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200903 protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600904 {
905 // External references
906 $external_scripts = implode('', $this->jquery_code_for_load);
907 $this->CI->load->vars(array('library_src' => $external_scripts));
908
Andrey Andreevad47f942011-12-25 19:13:48 +0200909 if (count($this->jquery_code_for_compile) === 0)
Derek Jones811f4752010-03-02 18:13:59 -0600910 {
911 // no inline references, let's just return
912 return;
913 }
914
915 // Inline references
Andrey Andreevad47f942011-12-25 19:13:48 +0200916 $script = '$(document).ready(function() {'."\n"
Andrey Andreev56454792012-05-17 14:32:19 +0300917 .implode('', $this->jquery_code_for_compile)
918 .'});';
Andrey Andreevad47f942011-12-25 19:13:48 +0200919
Derek Jones811f4752010-03-02 18:13:59 -0600920 $output = ($script_tags === FALSE) ? $script : $this->inline($script);
921
922 $this->CI->load->vars(array($view_var => $output));
Derek Jones811f4752010-03-02 18:13:59 -0600923 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200924
Derek Jones811f4752010-03-02 18:13:59 -0600925 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200926
Derek Jones811f4752010-03-02 18:13:59 -0600927 /**
928 * Clear Compile
929 *
930 * Clears the array of script events collected for output
931 *
Derek Jones811f4752010-03-02 18:13:59 -0600932 * @return void
933 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200934 protected function _clear_compile()
Derek Jones811f4752010-03-02 18:13:59 -0600935 {
936 $this->jquery_code_for_compile = array();
937 }
938
939 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200940
Derek Jones811f4752010-03-02 18:13:59 -0600941 /**
942 * Document Ready
943 *
944 * A wrapper for writing document.ready()
945 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300946 * @param array $js
947 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600948 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200949 protected function _document_ready($js)
Derek Jones811f4752010-03-02 18:13:59 -0600950 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300951 is_array($js) OR $js = array($js);
Andrey Andreevad47f942011-12-25 19:13:48 +0200952
Derek Jones811f4752010-03-02 18:13:59 -0600953 foreach ($js as $script)
954 {
955 $this->jquery_code_for_compile[] = $script;
956 }
957 }
958
959 // --------------------------------------------------------------------
960
961 /**
962 * Script Tag
963 *
964 * Outputs the script tag that loads the jquery.js file into an HTML document
965 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300966 * @param string $library_src = ''
967 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600968 * @return string
969 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200970 public function script($library_src = '', $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600971 {
972 $library_src = $this->external($library_src, $relative);
973 $this->jquery_code_for_load[] = $library_src;
974 return $library_src;
975 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200976
Derek Jones811f4752010-03-02 18:13:59 -0600977 // --------------------------------------------------------------------
978
979 /**
980 * Prep Element
981 *
982 * Puts HTML element in quotes for use in jQuery code
983 * unless the supplied element is the Javascript 'this'
984 * object, in which case no quotes are added
985 *
Derek Jones811f4752010-03-02 18:13:59 -0600986 * @param string
987 * @return string
988 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200989 protected function _prep_element($element)
Derek Jones811f4752010-03-02 18:13:59 -0600990 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100991 if ($element !== 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600992 {
993 $element = '"'.$element.'"';
994 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200995
Derek Jones811f4752010-03-02 18:13:59 -0600996 return $element;
997 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200998
Derek Jones811f4752010-03-02 18:13:59 -0600999 // --------------------------------------------------------------------
1000
1001 /**
1002 * Validate Speed
1003 *
1004 * Ensures the speed parameter is valid for jQuery
1005 *
Derek Jones811f4752010-03-02 18:13:59 -06001006 * @param string
1007 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +02001008 */
1009 protected function _validate_speed($speed)
Derek Jones811f4752010-03-02 18:13:59 -06001010 {
1011 if (in_array($speed, array('slow', 'normal', 'fast')))
1012 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001013 return '"'.$speed.'"';
Derek Jones811f4752010-03-02 18:13:59 -06001014 }
Andrey Andreev56454792012-05-17 14:32:19 +03001015 elseif (preg_match('/[^0-9]/', $speed))
Derek Jones811f4752010-03-02 18:13:59 -06001016 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001017 return '';
Derek Jones811f4752010-03-02 18:13:59 -06001018 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001019
Derek Jones811f4752010-03-02 18:13:59 -06001020 return $speed;
1021 }
1022
1023}
1024
1025/* End of file Jquery.php */
Andrey Andreev56454792012-05-17 14:32:19 +03001026/* Location: ./system/libraries/Jquery.php */