blob: 13f6c805727f1698ad6bbc67f5f9bcf4f663d98d [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Jones811f4752010-03-02 18:13:59 -06002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Jonesf4a4bd82011-10-20 12:18:42 -05006 *
7 * NOTICE OF LICENSE
Andrey Andreevad47f942011-12-25 19:13:48 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevad47f942011-12-25 19:13:48 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
Derek Jones811f4752010-03-02 18:13:59 -060018 *
19 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Jones811f4752010-03-02 18:13:59 -060028
29/**
30 * Jquery Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
Derek Jones811f4752010-03-02 18:13:59 -060034 * @category Loader
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
36 * @link http://codeigniter.com/user_guide/libraries/javascript.html
Derek Jones811f4752010-03-02 18:13:59 -060037 */
Greg Akeraacfe482010-03-03 12:26:31 -060038class CI_Jquery extends CI_Javascript {
Derek Jones811f4752010-03-02 18:13:59 -060039
Andrey 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
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030048 /**
49 * Constructor
50 *
51 * @param array $params
52 * @return void
53 */
Greg Akera9263282010-11-10 15:26:43 -060054 public function __construct($params)
Derek Jones811f4752010-03-02 18:13:59 -060055 {
Andrey Andreevad47f942011-12-25 19:13:48 +020056 $this->CI =& get_instance();
Derek Jones811f4752010-03-02 18:13:59 -060057 extract($params);
58
59 if ($autoload === TRUE)
60 {
Andrey Andreevad47f942011-12-25 19:13:48 +020061 $this->script();
Derek Jones811f4752010-03-02 18:13:59 -060062 }
Andrey Andreevad47f942011-12-25 19:13:48 +020063
Andrey Andreev56454792012-05-17 14:32:19 +030064 log_message('debug', 'Jquery Class Initialized');
Derek Jones811f4752010-03-02 18:13:59 -060065 }
Andrey Andreevad47f942011-12-25 19:13:48 +020066
67 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060068 // Event Code
Andrey Andreevad47f942011-12-25 19:13:48 +020069 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -060070
71 /**
72 * Blur
73 *
74 * Outputs a jQuery blur event
75 *
Derek Jones811f4752010-03-02 18:13:59 -060076 * @param string The element to attach the event to
77 * @param string The code to execute
78 * @return string
79 */
Andrey Andreevad47f942011-12-25 19:13:48 +020080 protected function _blur($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060081 {
82 return $this->_add_event($element, $js, 'blur');
83 }
Andrey Andreevad47f942011-12-25 19:13:48 +020084
Derek Jones811f4752010-03-02 18:13:59 -060085 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +020086
Derek Jones811f4752010-03-02 18:13:59 -060087 /**
88 * Change
89 *
90 * Outputs a jQuery change event
91 *
Derek Jones811f4752010-03-02 18:13:59 -060092 * @param string The element to attach the event to
93 * @param string The code to execute
94 * @return string
95 */
Andrey Andreevad47f942011-12-25 19:13:48 +020096 protected function _change($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -060097 {
98 return $this->_add_event($element, $js, 'change');
99 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200100
Derek Jones811f4752010-03-02 18:13:59 -0600101 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200102
Derek Jones811f4752010-03-02 18:13:59 -0600103 /**
104 * Click
105 *
106 * Outputs a jQuery click event
107 *
Derek Jones811f4752010-03-02 18:13:59 -0600108 * @param string The element to attach the event to
109 * @param string The code to execute
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300110 * @param bool whether or not to return false
Derek Jones811f4752010-03-02 18:13:59 -0600111 * @return string
112 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200113 protected function _click($element = 'this', $js = '', $ret_false = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600114 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300115 is_array($js) OR $js = array($js);
Derek Jones811f4752010-03-02 18:13:59 -0600116
117 if ($ret_false)
118 {
Andrey Andreev56454792012-05-17 14:32:19 +0300119 $js[] = 'return false;';
Derek Jones811f4752010-03-02 18:13:59 -0600120 }
121
122 return $this->_add_event($element, $js, 'click');
123 }
124
125 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200126
Derek Jones811f4752010-03-02 18:13:59 -0600127 /**
128 * Double Click
129 *
130 * Outputs a jQuery dblclick event
131 *
Derek Jones811f4752010-03-02 18:13:59 -0600132 * @param string The element to attach the event to
133 * @param string The code to execute
134 * @return string
135 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200136 protected function _dblclick($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600137 {
138 return $this->_add_event($element, $js, 'dblclick');
139 }
140
141 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200142
Derek Jones811f4752010-03-02 18:13:59 -0600143 /**
144 * Error
145 *
146 * Outputs a jQuery error event
147 *
Derek Jones811f4752010-03-02 18:13:59 -0600148 * @param string The element to attach the event to
149 * @param string The code to execute
150 * @return string
151 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200152 protected function _error($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600153 {
154 return $this->_add_event($element, $js, 'error');
155 }
156
157 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200158
Derek Jones811f4752010-03-02 18:13:59 -0600159 /**
160 * Focus
161 *
162 * Outputs a jQuery focus event
163 *
Derek Jones811f4752010-03-02 18:13:59 -0600164 * @param string The element to attach the event to
165 * @param string The code to execute
166 * @return string
167 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200168 protected function _focus($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600169 {
170 return $this->_add_event($element, $js, 'focus');
171 }
172
173 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200174
Derek Jones811f4752010-03-02 18:13:59 -0600175 /**
176 * Hover
177 *
178 * Outputs a jQuery hover event
179 *
Derek Jones811f4752010-03-02 18:13:59 -0600180 * @param string - element
181 * @param string - Javascript code for mouse over
182 * @param string - Javascript code for mouse out
Barry Mienydd671972010-10-04 16:33:58 +0200183 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600184 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200185 protected function _hover($element = 'this', $over, $out)
Derek Jones811f4752010-03-02 18:13:59 -0600186 {
Andrey Andreev56454792012-05-17 14:32:19 +0300187 $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 -0600188
189 $this->jquery_code_for_compile[] = $event;
190
191 return $event;
192 }
193
194 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200195
Derek Jones811f4752010-03-02 18:13:59 -0600196 /**
197 * Keydown
198 *
199 * Outputs a jQuery keydown event
200 *
Derek Jones811f4752010-03-02 18:13:59 -0600201 * @param string The element to attach the event to
202 * @param string The code to execute
203 * @return string
204 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200205 protected function _keydown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600206 {
207 return $this->_add_event($element, $js, 'keydown');
208 }
209
210 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200211
Derek Jones811f4752010-03-02 18:13:59 -0600212 /**
213 * Keyup
214 *
215 * Outputs a jQuery keydown event
216 *
Derek Jones811f4752010-03-02 18:13:59 -0600217 * @param string The element to attach the event to
218 * @param string The code to execute
219 * @return string
220 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200221 protected function _keyup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600222 {
223 return $this->_add_event($element, $js, 'keyup');
Andrey Andreevad47f942011-12-25 19:13:48 +0200224 }
Derek Jones811f4752010-03-02 18:13:59 -0600225
226 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200227
Derek Jones811f4752010-03-02 18:13:59 -0600228 /**
229 * Load
230 *
231 * Outputs a jQuery load event
232 *
Derek Jones811f4752010-03-02 18:13:59 -0600233 * @param string The element to attach the event to
234 * @param string The code to execute
235 * @return string
236 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200237 protected function _load($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600238 {
239 return $this->_add_event($element, $js, 'load');
Andrey Andreevad47f942011-12-25 19:13:48 +0200240 }
241
Derek Jones811f4752010-03-02 18:13:59 -0600242 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200243
Derek Jones811f4752010-03-02 18:13:59 -0600244 /**
245 * Mousedown
246 *
247 * Outputs a jQuery mousedown event
248 *
Derek Jones811f4752010-03-02 18:13:59 -0600249 * @param string The element to attach the event to
250 * @param string The code to execute
251 * @return string
252 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200253 protected function _mousedown($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600254 {
255 return $this->_add_event($element, $js, 'mousedown');
256 }
257
258 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200259
Derek Jones811f4752010-03-02 18:13:59 -0600260 /**
261 * Mouse Out
262 *
263 * Outputs a jQuery mouseout event
264 *
Derek Jones811f4752010-03-02 18:13:59 -0600265 * @param string The element to attach the event to
266 * @param string The code to execute
267 * @return string
268 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200269 protected function _mouseout($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600270 {
271 return $this->_add_event($element, $js, 'mouseout');
272 }
273
274 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200275
Derek Jones811f4752010-03-02 18:13:59 -0600276 /**
277 * Mouse Over
278 *
279 * Outputs a jQuery mouseover event
280 *
Derek Jones811f4752010-03-02 18:13:59 -0600281 * @param string The element to attach the event to
282 * @param string The code to execute
283 * @return string
284 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200285 protected function _mouseover($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600286 {
287 return $this->_add_event($element, $js, 'mouseover');
288 }
289
290 // --------------------------------------------------------------------
291
292 /**
293 * Mouseup
294 *
295 * Outputs a jQuery mouseup event
296 *
Derek Jones811f4752010-03-02 18:13:59 -0600297 * @param string The element to attach the event to
298 * @param string The code to execute
299 * @return string
300 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200301 protected function _mouseup($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600302 {
303 return $this->_add_event($element, $js, 'mouseup');
304 }
305
306 // --------------------------------------------------------------------
307
308 /**
309 * Output
310 *
311 * Outputs script directly
312 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300313 * @param array $array_js = array()
314 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600315 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300316 protected function _output($array_js = array())
Derek Jones811f4752010-03-02 18:13:59 -0600317 {
318 if ( ! is_array($array_js))
319 {
320 $array_js = array($array_js);
321 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200322
Derek Jones811f4752010-03-02 18:13:59 -0600323 foreach ($array_js as $js)
324 {
Andrey Andreev56454792012-05-17 14:32:19 +0300325 $this->jquery_code_for_compile[] = "\t".$js."\n";
Derek Jones811f4752010-03-02 18:13:59 -0600326 }
327 }
328
329 // --------------------------------------------------------------------
330
331 /**
332 * Resize
333 *
334 * Outputs a jQuery resize event
335 *
Derek Jones811f4752010-03-02 18:13:59 -0600336 * @param string The element to attach the event to
337 * @param string The code to execute
338 * @return string
339 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200340 protected function _resize($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600341 {
342 return $this->_add_event($element, $js, 'resize');
343 }
344
345 // --------------------------------------------------------------------
346
347 /**
348 * Scroll
349 *
350 * Outputs a jQuery scroll event
351 *
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 _scroll($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600357 {
358 return $this->_add_event($element, $js, 'scroll');
359 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200360
Derek Jones811f4752010-03-02 18:13:59 -0600361 // --------------------------------------------------------------------
362
363 /**
364 * Unload
365 *
366 * Outputs a jQuery unload event
367 *
Derek Jones811f4752010-03-02 18:13:59 -0600368 * @param string The element to attach the event to
369 * @param string The code to execute
370 * @return string
371 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200372 protected function _unload($element = 'this', $js = '')
Derek Jones811f4752010-03-02 18:13:59 -0600373 {
374 return $this->_add_event($element, $js, 'unload');
375 }
376
Andrey Andreevad47f942011-12-25 19:13:48 +0200377 // --------------------------------------------------------------------
Derek Jones811f4752010-03-02 18:13:59 -0600378 // Effects
Andrey Andreevad47f942011-12-25 19:13:48 +0200379 // --------------------------------------------------------------------
380
Derek Jones811f4752010-03-02 18:13:59 -0600381 /**
382 * Add Class
383 *
384 * Outputs a jQuery addClass event
385 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300386 * @param string $element = 'this'
387 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200388 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600389 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300390 protected function _addClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600391 {
392 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300393 return '$('.$element.').addClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600394 }
395
396 // --------------------------------------------------------------------
397
398 /**
399 * Animate
400 *
401 * Outputs a jQuery animate event
402 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300403 * @param string $element = 'this'
404 * @param array $params = array()
405 * @param string $speed = '' 'slow', 'normal', 'fast', or time in milliseconds
406 * @param string $extra = ''
Barry Mienydd671972010-10-04 16:33:58 +0200407 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600408 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200409 protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
Derek Jones811f4752010-03-02 18:13:59 -0600410 {
411 $element = $this->_prep_element($element);
412 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200413
Derek Jones811f4752010-03-02 18:13:59 -0600414 $animations = "\t\t\t";
Andrey Andreevad47f942011-12-25 19:13:48 +0200415
Andrey Andreev56454792012-05-17 14:32:19 +0300416 foreach ($params as $param => $value)
Derek Jones811f4752010-03-02 18:13:59 -0600417 {
Andrey Andreev56454792012-05-17 14:32:19 +0300418 $animations .= $param.": '".$value."', ";
Derek Jones811f4752010-03-02 18:13:59 -0600419 }
420
421 $animations = substr($animations, 0, -2); // remove the last ", "
422
Alex Bilbied261b1e2012-06-02 11:12:16 +0100423 if ($speed !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600424 {
425 $speed = ', '.$speed;
426 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200427
Alex Bilbied261b1e2012-06-02 11:12:16 +0100428 if ($extra !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600429 {
430 $extra = ', '.$extra;
431 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200432
Andrey Andreev56454792012-05-17 14:32:19 +0300433 return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');';
Derek Jones811f4752010-03-02 18:13:59 -0600434 }
435
436 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200437
Derek Jones811f4752010-03-02 18:13:59 -0600438 /**
439 * Fade In
440 *
441 * Outputs a jQuery hide event
442 *
Derek Jones811f4752010-03-02 18:13:59 -0600443 * @param string - element
444 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
445 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200446 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600447 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200448 protected function _fadeIn($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600449 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200450 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600451 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200452
Alex Bilbied261b1e2012-06-02 11:12:16 +0100453 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600454 {
455 $callback = ", function(){\n{$callback}\n}";
456 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200457
458 return "$({$element}).fadeIn({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600459 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200460
Derek Jones811f4752010-03-02 18:13:59 -0600461 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200462
Derek Jones811f4752010-03-02 18:13:59 -0600463 /**
464 * Fade Out
465 *
466 * Outputs a jQuery hide event
467 *
Derek Jones811f4752010-03-02 18:13:59 -0600468 * @param string - element
469 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
470 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200471 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600472 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200473 protected function _fadeOut($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600474 {
475 $element = $this->_prep_element($element);
476 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200477
Alex Bilbied261b1e2012-06-02 11:12:16 +0100478 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600479 {
480 $callback = ", function(){\n{$callback}\n}";
481 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200482
Andrey Andreev56454792012-05-17 14:32:19 +0300483 return '$('.$element.').fadeOut('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600484 }
485
486 // --------------------------------------------------------------------
487
488 /**
489 * Hide
490 *
491 * Outputs a jQuery hide action
492 *
Derek Jones811f4752010-03-02 18:13:59 -0600493 * @param string - element
494 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
495 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200496 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600497 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200498 protected function _hide($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600499 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200500 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600501 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200502
Alex Bilbied261b1e2012-06-02 11:12:16 +0100503 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600504 {
505 $callback = ", function(){\n{$callback}\n}";
506 }
Derek Jones811f4752010-03-02 18:13:59 -0600507
Andrey Andreevad47f942011-12-25 19:13:48 +0200508 return "$({$element}).hide({$speed}{$callback});";
Derek Jones811f4752010-03-02 18:13:59 -0600509 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200510
Derek Jones811f4752010-03-02 18:13:59 -0600511 // --------------------------------------------------------------------
512
513 /**
514 * Remove Class
515 *
516 * Outputs a jQuery remove class event
517 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300518 * @param string $element = 'this'
519 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200520 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600521 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300522 protected function _removeClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600523 {
524 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300525 return '$('.$element.').removeClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600526 }
527
528 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200529
Derek Jones811f4752010-03-02 18:13:59 -0600530 /**
531 * Slide Up
532 *
533 * Outputs a jQuery slideUp event
534 *
Derek Jones811f4752010-03-02 18:13:59 -0600535 * @param string - element
536 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
537 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200538 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600539 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200540 protected function _slideUp($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600541 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200542 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600543 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200544
Alex Bilbied261b1e2012-06-02 11:12:16 +0100545 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600546 {
547 $callback = ", function(){\n{$callback}\n}";
548 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200549
Andrey Andreev56454792012-05-17 14:32:19 +0300550 return '$('.$element.').slideUp('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600551 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200552
Derek Jones811f4752010-03-02 18:13:59 -0600553 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200554
Derek Jones811f4752010-03-02 18:13:59 -0600555 /**
556 * Slide Down
557 *
558 * Outputs a jQuery slideDown event
559 *
Derek Jones811f4752010-03-02 18:13:59 -0600560 * @param string - element
561 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
562 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200563 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600564 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200565 protected function _slideDown($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600566 {
567 $element = $this->_prep_element($element);
568 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200569
Alex Bilbied261b1e2012-06-02 11:12:16 +0100570 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600571 {
572 $callback = ", function(){\n{$callback}\n}";
573 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200574
Andrey Andreev56454792012-05-17 14:32:19 +0300575 return '$('.$element.').slideDown('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600576 }
577
578 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200579
Derek Jones811f4752010-03-02 18:13:59 -0600580 /**
581 * Slide Toggle
582 *
583 * Outputs a jQuery slideToggle event
584 *
Derek Jones811f4752010-03-02 18:13:59 -0600585 * @param string - element
586 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
587 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200588 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600589 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200590 protected function _slideToggle($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600591 {
592 $element = $this->_prep_element($element);
593 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200594
Alex Bilbied261b1e2012-06-02 11:12:16 +0100595 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600596 {
597 $callback = ", function(){\n{$callback}\n}";
598 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200599
Andrey Andreev56454792012-05-17 14:32:19 +0300600 return '$('.$element.').slideToggle('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600601 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200602
Derek Jones811f4752010-03-02 18:13:59 -0600603 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200604
Derek Jones811f4752010-03-02 18:13:59 -0600605 /**
606 * Toggle
607 *
608 * Outputs a jQuery toggle event
609 *
Derek Jones811f4752010-03-02 18:13:59 -0600610 * @param string - element
Barry Mienydd671972010-10-04 16:33:58 +0200611 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600612 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200613 protected function _toggle($element = 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600614 {
615 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300616 return '$('.$element.').toggle();';
Derek Jones811f4752010-03-02 18:13:59 -0600617 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200618
Derek Jones811f4752010-03-02 18:13:59 -0600619 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200620
Derek Jones811f4752010-03-02 18:13:59 -0600621 /**
622 * Toggle Class
623 *
624 * Outputs a jQuery toggle class event
625 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300626 * @param string $element = 'this'
627 * @param string $class = ''
Barry Mienydd671972010-10-04 16:33:58 +0200628 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600629 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300630 protected function _toggleClass($element = 'this', $class = '')
Derek Jones811f4752010-03-02 18:13:59 -0600631 {
632 $element = $this->_prep_element($element);
Andrey Andreev56454792012-05-17 14:32:19 +0300633 return '$('.$element.').toggleClass("'.$class.'");';
Derek Jones811f4752010-03-02 18:13:59 -0600634 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200635
Derek Jones811f4752010-03-02 18:13:59 -0600636 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200637
Derek Jones811f4752010-03-02 18:13:59 -0600638 /**
639 * Show
640 *
641 * Outputs a jQuery show event
642 *
Derek Jones811f4752010-03-02 18:13:59 -0600643 * @param string - element
644 * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
645 * @param string - Javascript callback function
Barry Mienydd671972010-10-04 16:33:58 +0200646 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600647 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200648 protected function _show($element = 'this', $speed = '', $callback = '')
Derek Jones811f4752010-03-02 18:13:59 -0600649 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200650 $element = $this->_prep_element($element);
Derek Jones811f4752010-03-02 18:13:59 -0600651 $speed = $this->_validate_speed($speed);
Andrey Andreevad47f942011-12-25 19:13:48 +0200652
Alex Bilbied261b1e2012-06-02 11:12:16 +0100653 if ($callback !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600654 {
655 $callback = ", function(){\n{$callback}\n}";
656 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200657
Andrey Andreev56454792012-05-17 14:32:19 +0300658 return '$('.$element.').show('.$speed.$callback.');';
Derek Jones811f4752010-03-02 18:13:59 -0600659 }
660
661 // --------------------------------------------------------------------
662
663 /**
664 * Updater
665 *
Andrey Andreevad47f942011-12-25 19:13:48 +0200666 * An Ajax call that populates the designated DOM node with
Derek Jones811f4752010-03-02 18:13:59 -0600667 * returned content
668 *
Derek Jones811f4752010-03-02 18:13:59 -0600669 * @param string The element to attach the event to
670 * @param string the controller to run the call against
671 * @param string optional parameters
672 * @return string
673 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200674
675 protected function _updater($container = 'this', $controller, $options = '')
676 {
Derek Jones811f4752010-03-02 18:13:59 -0600677 $container = $this->_prep_element($container);
Derek Jones811f4752010-03-02 18:13:59 -0600678 $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
Andrey Andreevad47f942011-12-25 19:13:48 +0200679
Derek Jones811f4752010-03-02 18:13:59 -0600680 // ajaxStart and ajaxStop are better choices here... but this is a stop gap
Alex Bilbied261b1e2012-06-02 11:12:16 +0100681 if ($this->CI->config->item('javascript_ajax_img') === '')
Derek Jones811f4752010-03-02 18:13:59 -0600682 {
Andrey Andreev56454792012-05-17 14:32:19 +0300683 $loading_notifier = 'Loading...';
Derek Jones811f4752010-03-02 18:13:59 -0600684 }
685 else
686 {
Andrey Andreev56454792012-05-17 14:32:19 +0300687 $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 -0600688 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200689
Andrey Andreev56454792012-05-17 14:32:19 +0300690 $updater = '$('.$container.").empty();\n" // anything that was in... get it out
691 ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image
Derek Jones811f4752010-03-02 18:13:59 -0600692
693 $request_options = '';
Alex Bilbied261b1e2012-06-02 11:12:16 +0100694 if ($options !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600695 {
Andrey Andreevad47f942011-12-25 19:13:48 +0200696 $request_options .= ', {'
Andrey Andreev56454792012-05-17 14:32:19 +0300697 .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'")
698 .'}';
Derek Jones811f4752010-03-02 18:13:59 -0600699 }
700
Andrey Andreevad47f942011-12-25 19:13:48 +0200701 return $updater."\t\t$($container).load('$controller'$request_options);";
Derek Jones811f4752010-03-02 18:13:59 -0600702 }
703
Derek Jones811f4752010-03-02 18:13:59 -0600704 // --------------------------------------------------------------------
705 // Pre-written handy stuff
706 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200707
Derek Jones811f4752010-03-02 18:13:59 -0600708 /**
709 * Zebra tables
710 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300711 * @param string $class = ''
712 * @param string $odd = 'odd'
713 * @param string $hover = ''
Derek Jones811f4752010-03-02 18:13:59 -0600714 * @return string
715 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200716 protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
Derek Jones811f4752010-03-02 18:13:59 -0600717 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100718 $class = ($class !== '') ? '.'.$class : '';
vkeranovbfbe8b22012-10-27 18:25:08 +0300719 $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
Derek Jones811f4752010-03-02 18:13:59 -0600720
721 $this->jquery_code_for_compile[] = $zebra;
722
Alex Bilbied261b1e2012-06-02 11:12:16 +0100723 if ($hover !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600724 {
725 $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
726 }
727
728 return $zebra;
729 }
730
Derek Jones811f4752010-03-02 18:13:59 -0600731 // --------------------------------------------------------------------
732 // Plugins
733 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200734
Derek Jones811f4752010-03-02 18:13:59 -0600735 /**
736 * Corner Plugin
737 *
738 * http://www.malsup.com/jquery/corner/
739 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300740 * @param string $element = ''
741 * @param string $corner_style = ''
Derek Jones811f4752010-03-02 18:13:59 -0600742 * @return string
743 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200744 public function corner($element = '', $corner_style = '')
Derek Jones811f4752010-03-02 18:13:59 -0600745 {
746 // may want to make this configurable down the road
747 $corner_location = '/plugins/jquery.corner.js';
748
Alex Bilbied261b1e2012-06-02 11:12:16 +0100749 if ($corner_style !== '')
Derek Jones811f4752010-03-02 18:13:59 -0600750 {
751 $corner_style = '"'.$corner_style.'"';
752 }
753
Andrey Andreev56454792012-05-17 14:32:19 +0300754 return '$('.$this->_prep_element($element).').corner('.$corner_style.');';
Derek Jones811f4752010-03-02 18:13:59 -0600755 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200756
Derek Jones811f4752010-03-02 18:13:59 -0600757 // --------------------------------------------------------------------
758
759 /**
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300760 * Modal window
Derek Jones811f4752010-03-02 18:13:59 -0600761 *
762 * Load a thickbox modal window
763 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300764 * @param string $src
765 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600766 * @return void
767 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200768 public function modal($src, $relative = FALSE)
769 {
Derek Jones811f4752010-03-02 18:13:59 -0600770 $this->jquery_code_for_load[] = $this->external($src, $relative);
771 }
772
773 // --------------------------------------------------------------------
774
775 /**
776 * Effect
777 *
778 * Load an Effect library
779 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300780 * @param string $src
781 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600782 * @return void
783 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200784 public function effect($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600785 {
786 $this->jquery_code_for_load[] = $this->external($src, $relative);
787 }
788
789 // --------------------------------------------------------------------
790
791 /**
792 * Plugin
793 *
794 * Load a plugin library
795 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300796 * @param string $src
797 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600798 * @return void
799 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200800 public function plugin($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600801 {
802 $this->jquery_code_for_load[] = $this->external($src, $relative);
803 }
804
805 // --------------------------------------------------------------------
806
807 /**
808 * UI
809 *
810 * Load a user interface library
811 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300812 * @param string $src
813 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600814 * @return void
815 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200816 public function ui($src, $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600817 {
818 $this->jquery_code_for_load[] = $this->external($src, $relative);
819 }
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300820
Derek Jones811f4752010-03-02 18:13:59 -0600821 // --------------------------------------------------------------------
822
823 /**
824 * Sortable
825 *
826 * Creates a jQuery sortable
827 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300828 * @param string $element
829 * @param array $options = array()
830 * @return string
Derek Jones811f4752010-03-02 18:13:59 -0600831 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200832 public function sortable($element, $options = array())
Derek Jones811f4752010-03-02 18:13:59 -0600833 {
Derek Jones811f4752010-03-02 18:13:59 -0600834 if (count($options) > 0)
835 {
836 $sort_options = array();
837 foreach ($options as $k=>$v)
838 {
Andrey Andreev56454792012-05-17 14:32:19 +0300839 $sort_options[] = "\n\t\t".$k.': '.$v;
Derek Jones811f4752010-03-02 18:13:59 -0600840 }
Andrey Andreev56454792012-05-17 14:32:19 +0300841 $sort_options = implode(',', $sort_options);
Derek Jones811f4752010-03-02 18:13:59 -0600842 }
843 else
844 {
845 $sort_options = '';
846 }
847
Andrey Andreev56454792012-05-17 14:32:19 +0300848 return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});";
Derek Jones811f4752010-03-02 18:13:59 -0600849 }
850
851 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200852
Derek Jones811f4752010-03-02 18:13:59 -0600853 /**
854 * Table Sorter Plugin
855 *
Derek Jones811f4752010-03-02 18:13:59 -0600856 * @param string table name
857 * @param string plugin location
858 * @return string
859 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200860 public function tablesorter($table = '', $options = '')
Derek Jones811f4752010-03-02 18:13:59 -0600861 {
Andrey Andreev56454792012-05-17 14:32:19 +0300862 $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n";
Derek Jones811f4752010-03-02 18:13:59 -0600863 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200864
Derek Jones811f4752010-03-02 18:13:59 -0600865 // --------------------------------------------------------------------
866 // Class functions
867 // --------------------------------------------------------------------
868
869 /**
870 * Add Event
871 *
872 * Constructs the syntax for an event, and adds to into the array for compilation
873 *
Derek Jones811f4752010-03-02 18:13:59 -0600874 * @param string The element to attach the event to
875 * @param string The code to execute
876 * @param string The event to pass
877 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +0200878 */
879 protected function _add_event($element, $js, $event)
Derek Jones811f4752010-03-02 18:13:59 -0600880 {
881 if (is_array($js))
882 {
883 $js = implode("\n\t\t", $js);
884
885 }
886
Andrey Andreev56454792012-05-17 14:32:19 +0300887 $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n";
Derek Jones811f4752010-03-02 18:13:59 -0600888 $this->jquery_code_for_compile[] = $event;
889 return $event;
890 }
891
892 // --------------------------------------------------------------------
893
894 /**
895 * Compile
896 *
897 * As events are specified, they are stored in an array
898 * This funciton compiles them all for output on a page
899 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300900 * @param string $view_var = 'script_foot'
901 * @param bool $script_tags = TRUE
902 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600903 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200904 protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
Derek Jones811f4752010-03-02 18:13:59 -0600905 {
906 // External references
907 $external_scripts = implode('', $this->jquery_code_for_load);
908 $this->CI->load->vars(array('library_src' => $external_scripts));
909
Andrey Andreevad47f942011-12-25 19:13:48 +0200910 if (count($this->jquery_code_for_compile) === 0)
Derek Jones811f4752010-03-02 18:13:59 -0600911 {
912 // no inline references, let's just return
913 return;
914 }
915
916 // Inline references
Andrey Andreevad47f942011-12-25 19:13:48 +0200917 $script = '$(document).ready(function() {'."\n"
Andrey Andreev56454792012-05-17 14:32:19 +0300918 .implode('', $this->jquery_code_for_compile)
919 .'});';
Andrey Andreevad47f942011-12-25 19:13:48 +0200920
Derek Jones811f4752010-03-02 18:13:59 -0600921 $output = ($script_tags === FALSE) ? $script : $this->inline($script);
922
923 $this->CI->load->vars(array($view_var => $output));
Derek Jones811f4752010-03-02 18:13:59 -0600924 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200925
Derek Jones811f4752010-03-02 18:13:59 -0600926 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200927
Derek Jones811f4752010-03-02 18:13:59 -0600928 /**
929 * Clear Compile
930 *
931 * Clears the array of script events collected for output
932 *
Derek Jones811f4752010-03-02 18:13:59 -0600933 * @return void
934 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200935 protected function _clear_compile()
Derek Jones811f4752010-03-02 18:13:59 -0600936 {
937 $this->jquery_code_for_compile = array();
938 }
939
940 // --------------------------------------------------------------------
Andrey Andreevad47f942011-12-25 19:13:48 +0200941
Derek Jones811f4752010-03-02 18:13:59 -0600942 /**
943 * Document Ready
944 *
945 * A wrapper for writing document.ready()
946 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300947 * @param array $js
948 * @return void
Derek Jones811f4752010-03-02 18:13:59 -0600949 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200950 protected function _document_ready($js)
Derek Jones811f4752010-03-02 18:13:59 -0600951 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300952 is_array($js) OR $js = array($js);
Andrey Andreevad47f942011-12-25 19:13:48 +0200953
Derek Jones811f4752010-03-02 18:13:59 -0600954 foreach ($js as $script)
955 {
956 $this->jquery_code_for_compile[] = $script;
957 }
958 }
959
960 // --------------------------------------------------------------------
961
962 /**
963 * Script Tag
964 *
965 * Outputs the script tag that loads the jquery.js file into an HTML document
966 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300967 * @param string $library_src = ''
968 * @param bool $relative = FALSE
Derek Jones811f4752010-03-02 18:13:59 -0600969 * @return string
970 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200971 public function script($library_src = '', $relative = FALSE)
Derek Jones811f4752010-03-02 18:13:59 -0600972 {
973 $library_src = $this->external($library_src, $relative);
974 $this->jquery_code_for_load[] = $library_src;
975 return $library_src;
976 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200977
Derek Jones811f4752010-03-02 18:13:59 -0600978 // --------------------------------------------------------------------
979
980 /**
981 * Prep Element
982 *
983 * Puts HTML element in quotes for use in jQuery code
984 * unless the supplied element is the Javascript 'this'
985 * object, in which case no quotes are added
986 *
Derek Jones811f4752010-03-02 18:13:59 -0600987 * @param string
988 * @return string
989 */
Andrey Andreevad47f942011-12-25 19:13:48 +0200990 protected function _prep_element($element)
Derek Jones811f4752010-03-02 18:13:59 -0600991 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100992 if ($element !== 'this')
Derek Jones811f4752010-03-02 18:13:59 -0600993 {
994 $element = '"'.$element.'"';
995 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200996
Derek Jones811f4752010-03-02 18:13:59 -0600997 return $element;
998 }
Andrey Andreevad47f942011-12-25 19:13:48 +0200999
Derek Jones811f4752010-03-02 18:13:59 -06001000 // --------------------------------------------------------------------
1001
1002 /**
1003 * Validate Speed
1004 *
1005 * Ensures the speed parameter is valid for jQuery
1006 *
Derek Jones811f4752010-03-02 18:13:59 -06001007 * @param string
1008 * @return string
Andrey Andreevad47f942011-12-25 19:13:48 +02001009 */
1010 protected function _validate_speed($speed)
Derek Jones811f4752010-03-02 18:13:59 -06001011 {
1012 if (in_array($speed, array('slow', 'normal', 'fast')))
1013 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001014 return '"'.$speed.'"';
Derek Jones811f4752010-03-02 18:13:59 -06001015 }
Andrey Andreev56454792012-05-17 14:32:19 +03001016 elseif (preg_match('/[^0-9]/', $speed))
Derek Jones811f4752010-03-02 18:13:59 -06001017 {
Andrey Andreevad47f942011-12-25 19:13:48 +02001018 return '';
Derek Jones811f4752010-03-02 18:13:59 -06001019 }
Andrey Andreevad47f942011-12-25 19:13:48 +02001020
Derek Jones811f4752010-03-02 18:13:59 -06001021 return $speed;
1022 }
1023
1024}
1025
1026/* End of file Jquery.php */
Andrey Andreev56454792012-05-17 14:32:19 +03001027/* Location: ./system/libraries/Jquery.php */