Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
| 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * 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 Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 18 | * |
| 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 23 | * @link http://codeigniter.com |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 28 | // ------------------------------------------------------------------------ |
| 29 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 30 | /** |
| 31 | * Jquery Class |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 35 | * @category Loader |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 36 | * @author EllisLab Dev Team |
| 37 | * @link http://codeigniter.com/user_guide/libraries/javascript.html |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 38 | */ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 39 | |
Greg Aker | aacfe48 | 2010-03-03 12:26:31 -0600 | [diff] [blame] | 40 | class CI_Jquery extends CI_Javascript { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 41 | |
| 42 | var $_javascript_folder = 'js'; |
| 43 | var $jquery_code_for_load = array(); |
| 44 | var $jquery_code_for_compile = array(); |
| 45 | var $jquery_corner_active = FALSE; |
| 46 | var $jquery_table_sorter_active = FALSE; |
| 47 | var $jquery_table_sorter_pager_active = FALSE; |
| 48 | var $jquery_ajax_img = ''; |
| 49 | |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 50 | public function __construct($params) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 51 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 52 | $this->CI =& get_instance(); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 53 | extract($params); |
| 54 | |
| 55 | if ($autoload === TRUE) |
| 56 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 57 | $this->script(); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 58 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 59 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 60 | log_message('debug', "Jquery Class Initialized"); |
| 61 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 62 | |
| 63 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 64 | // Event Code |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 65 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Blur |
| 69 | * |
| 70 | * Outputs a jQuery blur event |
| 71 | * |
| 72 | * @access private |
| 73 | * @param string The element to attach the event to |
| 74 | * @param string The code to execute |
| 75 | * @return string |
| 76 | */ |
| 77 | function _blur($element = 'this', $js = '') |
| 78 | { |
| 79 | return $this->_add_event($element, $js, 'blur'); |
| 80 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 81 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 82 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 83 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 84 | /** |
| 85 | * Change |
| 86 | * |
| 87 | * Outputs a jQuery change event |
| 88 | * |
| 89 | * @access private |
| 90 | * @param string The element to attach the event to |
| 91 | * @param string The code to execute |
| 92 | * @return string |
| 93 | */ |
| 94 | function _change($element = 'this', $js = '') |
| 95 | { |
| 96 | return $this->_add_event($element, $js, 'change'); |
| 97 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 98 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 99 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 100 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 101 | /** |
| 102 | * Click |
| 103 | * |
| 104 | * Outputs a jQuery click event |
| 105 | * |
| 106 | * @access private |
| 107 | * @param string The element to attach the event to |
| 108 | * @param string The code to execute |
| 109 | * @param boolean whether or not to return false |
| 110 | * @return string |
| 111 | */ |
| 112 | function _click($element = 'this', $js = '', $ret_false = TRUE) |
| 113 | { |
| 114 | if ( ! is_array($js)) |
| 115 | { |
| 116 | $js = array($js); |
| 117 | } |
| 118 | |
| 119 | if ($ret_false) |
| 120 | { |
| 121 | $js[] = "return false;"; |
| 122 | } |
| 123 | |
| 124 | return $this->_add_event($element, $js, 'click'); |
| 125 | } |
| 126 | |
| 127 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 128 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 129 | /** |
| 130 | * Double Click |
| 131 | * |
| 132 | * Outputs a jQuery dblclick event |
| 133 | * |
| 134 | * @access private |
| 135 | * @param string The element to attach the event to |
| 136 | * @param string The code to execute |
| 137 | * @return string |
| 138 | */ |
| 139 | function _dblclick($element = 'this', $js = '') |
| 140 | { |
| 141 | return $this->_add_event($element, $js, 'dblclick'); |
| 142 | } |
| 143 | |
| 144 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 145 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 146 | /** |
| 147 | * Error |
| 148 | * |
| 149 | * Outputs a jQuery error event |
| 150 | * |
| 151 | * @access private |
| 152 | * @param string The element to attach the event to |
| 153 | * @param string The code to execute |
| 154 | * @return string |
| 155 | */ |
| 156 | function _error($element = 'this', $js = '') |
| 157 | { |
| 158 | return $this->_add_event($element, $js, 'error'); |
| 159 | } |
| 160 | |
| 161 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 162 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 163 | /** |
| 164 | * Focus |
| 165 | * |
| 166 | * Outputs a jQuery focus event |
| 167 | * |
| 168 | * @access private |
| 169 | * @param string The element to attach the event to |
| 170 | * @param string The code to execute |
| 171 | * @return string |
| 172 | */ |
| 173 | function _focus($element = 'this', $js = '') |
| 174 | { |
| 175 | return $this->_add_event($element, $js, 'focus'); |
| 176 | } |
| 177 | |
| 178 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 179 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 180 | /** |
| 181 | * Hover |
| 182 | * |
| 183 | * Outputs a jQuery hover event |
| 184 | * |
| 185 | * @access private |
| 186 | * @param string - element |
| 187 | * @param string - Javascript code for mouse over |
| 188 | * @param string - Javascript code for mouse out |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 189 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 190 | */ |
| 191 | function _hover($element = 'this', $over, $out) |
| 192 | { |
| 193 | $event = "\n\t$(" . $this->_prep_element($element) . ").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
| 194 | |
| 195 | $this->jquery_code_for_compile[] = $event; |
| 196 | |
| 197 | return $event; |
| 198 | } |
| 199 | |
| 200 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 201 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 202 | /** |
| 203 | * Keydown |
| 204 | * |
| 205 | * Outputs a jQuery keydown event |
| 206 | * |
| 207 | * @access private |
| 208 | * @param string The element to attach the event to |
| 209 | * @param string The code to execute |
| 210 | * @return string |
| 211 | */ |
| 212 | function _keydown($element = 'this', $js = '') |
| 213 | { |
| 214 | return $this->_add_event($element, $js, 'keydown'); |
| 215 | } |
| 216 | |
| 217 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 218 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 219 | /** |
| 220 | * Keyup |
| 221 | * |
| 222 | * Outputs a jQuery keydown event |
| 223 | * |
| 224 | * @access private |
| 225 | * @param string The element to attach the event to |
| 226 | * @param string The code to execute |
| 227 | * @return string |
| 228 | */ |
| 229 | function _keyup($element = 'this', $js = '') |
| 230 | { |
| 231 | return $this->_add_event($element, $js, 'keyup'); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 232 | } |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 233 | |
| 234 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 235 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 236 | /** |
| 237 | * Load |
| 238 | * |
| 239 | * Outputs a jQuery load event |
| 240 | * |
| 241 | * @access private |
| 242 | * @param string The element to attach the event to |
| 243 | * @param string The code to execute |
| 244 | * @return string |
| 245 | */ |
| 246 | function _load($element = 'this', $js = '') |
| 247 | { |
| 248 | return $this->_add_event($element, $js, 'load'); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 249 | } |
| 250 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 251 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 252 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 253 | /** |
| 254 | * Mousedown |
| 255 | * |
| 256 | * Outputs a jQuery mousedown event |
| 257 | * |
| 258 | * @access private |
| 259 | * @param string The element to attach the event to |
| 260 | * @param string The code to execute |
| 261 | * @return string |
| 262 | */ |
| 263 | function _mousedown($element = 'this', $js = '') |
| 264 | { |
| 265 | return $this->_add_event($element, $js, 'mousedown'); |
| 266 | } |
| 267 | |
| 268 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 269 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 270 | /** |
| 271 | * Mouse Out |
| 272 | * |
| 273 | * Outputs a jQuery mouseout event |
| 274 | * |
| 275 | * @access private |
| 276 | * @param string The element to attach the event to |
| 277 | * @param string The code to execute |
| 278 | * @return string |
| 279 | */ |
| 280 | function _mouseout($element = 'this', $js = '') |
| 281 | { |
| 282 | return $this->_add_event($element, $js, 'mouseout'); |
| 283 | } |
| 284 | |
| 285 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 286 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 287 | /** |
| 288 | * Mouse Over |
| 289 | * |
| 290 | * Outputs a jQuery mouseover event |
| 291 | * |
| 292 | * @access private |
| 293 | * @param string The element to attach the event to |
| 294 | * @param string The code to execute |
| 295 | * @return string |
| 296 | */ |
| 297 | function _mouseover($element = 'this', $js = '') |
| 298 | { |
| 299 | return $this->_add_event($element, $js, 'mouseover'); |
| 300 | } |
| 301 | |
| 302 | // -------------------------------------------------------------------- |
| 303 | |
| 304 | /** |
| 305 | * Mouseup |
| 306 | * |
| 307 | * Outputs a jQuery mouseup event |
| 308 | * |
| 309 | * @access private |
| 310 | * @param string The element to attach the event to |
| 311 | * @param string The code to execute |
| 312 | * @return string |
| 313 | */ |
| 314 | function _mouseup($element = 'this', $js = '') |
| 315 | { |
| 316 | return $this->_add_event($element, $js, 'mouseup'); |
| 317 | } |
| 318 | |
| 319 | // -------------------------------------------------------------------- |
| 320 | |
| 321 | /** |
| 322 | * Output |
| 323 | * |
| 324 | * Outputs script directly |
| 325 | * |
| 326 | * @access private |
| 327 | * @param string The element to attach the event to |
| 328 | * @param string The code to execute |
| 329 | * @return string |
| 330 | */ |
| 331 | function _output($array_js = '') |
| 332 | { |
| 333 | if ( ! is_array($array_js)) |
| 334 | { |
| 335 | $array_js = array($array_js); |
| 336 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 337 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 338 | foreach ($array_js as $js) |
| 339 | { |
| 340 | $this->jquery_code_for_compile[] = "\t$js\n"; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // -------------------------------------------------------------------- |
| 345 | |
| 346 | /** |
| 347 | * Resize |
| 348 | * |
| 349 | * Outputs a jQuery resize event |
| 350 | * |
| 351 | * @access private |
| 352 | * @param string The element to attach the event to |
| 353 | * @param string The code to execute |
| 354 | * @return string |
| 355 | */ |
| 356 | function _resize($element = 'this', $js = '') |
| 357 | { |
| 358 | return $this->_add_event($element, $js, 'resize'); |
| 359 | } |
| 360 | |
| 361 | // -------------------------------------------------------------------- |
| 362 | |
| 363 | /** |
| 364 | * Scroll |
| 365 | * |
| 366 | * Outputs a jQuery scroll event |
| 367 | * |
| 368 | * @access private |
| 369 | * @param string The element to attach the event to |
| 370 | * @param string The code to execute |
| 371 | * @return string |
| 372 | */ |
| 373 | function _scroll($element = 'this', $js = '') |
| 374 | { |
| 375 | return $this->_add_event($element, $js, 'scroll'); |
| 376 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 377 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 378 | // -------------------------------------------------------------------- |
| 379 | |
| 380 | /** |
| 381 | * Unload |
| 382 | * |
| 383 | * Outputs a jQuery unload event |
| 384 | * |
| 385 | * @access private |
| 386 | * @param string The element to attach the event to |
| 387 | * @param string The code to execute |
| 388 | * @return string |
| 389 | */ |
| 390 | function _unload($element = 'this', $js = '') |
| 391 | { |
| 392 | return $this->_add_event($element, $js, 'unload'); |
| 393 | } |
| 394 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 395 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 396 | // Effects |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 397 | // -------------------------------------------------------------------- |
| 398 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 399 | /** |
| 400 | * Add Class |
| 401 | * |
| 402 | * Outputs a jQuery addClass event |
| 403 | * |
| 404 | * @access private |
| 405 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 406 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 407 | */ |
| 408 | function _addClass($element = 'this', $class='') |
| 409 | { |
| 410 | $element = $this->_prep_element($element); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 411 | $str = "$({$element}).addClass(\"$class\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 412 | return $str; |
| 413 | } |
| 414 | |
| 415 | // -------------------------------------------------------------------- |
| 416 | |
| 417 | /** |
| 418 | * Animate |
| 419 | * |
| 420 | * Outputs a jQuery animate event |
| 421 | * |
| 422 | * @access private |
| 423 | * @param string - element |
| 424 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 425 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 426 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 427 | */ |
| 428 | function _animate($element = 'this', $params = array(), $speed = '', $extra = '') |
| 429 | { |
| 430 | $element = $this->_prep_element($element); |
| 431 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 432 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 433 | $animations = "\t\t\t"; |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 434 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 435 | foreach ($params as $param=>$value) |
| 436 | { |
| 437 | $animations .= $param.': \''.$value.'\', '; |
| 438 | } |
| 439 | |
| 440 | $animations = substr($animations, 0, -2); // remove the last ", " |
| 441 | |
| 442 | if ($speed != '') |
| 443 | { |
| 444 | $speed = ', '.$speed; |
| 445 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 446 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 447 | if ($extra != '') |
| 448 | { |
| 449 | $extra = ', '.$extra; |
| 450 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 451 | |
| 452 | $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
| 453 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 454 | return $str; |
| 455 | } |
| 456 | |
| 457 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 458 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 459 | /** |
| 460 | * Fade In |
| 461 | * |
| 462 | * Outputs a jQuery hide event |
| 463 | * |
| 464 | * @access private |
| 465 | * @param string - element |
| 466 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 467 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 468 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 469 | */ |
| 470 | function _fadeIn($element = 'this', $speed = '', $callback = '') |
| 471 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 472 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 473 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 474 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 475 | if ($callback != '') |
| 476 | { |
| 477 | $callback = ", function(){\n{$callback}\n}"; |
| 478 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 479 | |
| 480 | $str = "$({$element}).fadeIn({$speed}{$callback});"; |
| 481 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 482 | return $str; |
| 483 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 484 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 485 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 486 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 487 | /** |
| 488 | * Fade Out |
| 489 | * |
| 490 | * Outputs a jQuery hide event |
| 491 | * |
| 492 | * @access private |
| 493 | * @param string - element |
| 494 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 495 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 496 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 497 | */ |
| 498 | function _fadeOut($element = 'this', $speed = '', $callback = '') |
| 499 | { |
| 500 | $element = $this->_prep_element($element); |
| 501 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 502 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 503 | if ($callback != '') |
| 504 | { |
| 505 | $callback = ", function(){\n{$callback}\n}"; |
| 506 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 507 | |
| 508 | $str = "$({$element}).fadeOut({$speed}{$callback});"; |
| 509 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 510 | return $str; |
| 511 | } |
| 512 | |
| 513 | // -------------------------------------------------------------------- |
| 514 | |
| 515 | /** |
| 516 | * Hide |
| 517 | * |
| 518 | * Outputs a jQuery hide action |
| 519 | * |
| 520 | * @access private |
| 521 | * @param string - element |
| 522 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 523 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 524 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 525 | */ |
| 526 | function _hide($element = 'this', $speed = '', $callback = '') |
| 527 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 528 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 529 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 530 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 531 | if ($callback != '') |
| 532 | { |
| 533 | $callback = ", function(){\n{$callback}\n}"; |
| 534 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 535 | |
| 536 | $str = "$({$element}).hide({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 537 | |
| 538 | return $str; |
| 539 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 540 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 541 | // -------------------------------------------------------------------- |
| 542 | |
| 543 | /** |
| 544 | * Remove Class |
| 545 | * |
| 546 | * Outputs a jQuery remove class event |
| 547 | * |
| 548 | * @access private |
| 549 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 550 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 551 | */ |
| 552 | function _removeClass($element = 'this', $class='') |
| 553 | { |
| 554 | $element = $this->_prep_element($element); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 555 | $str = "$({$element}).removeClass(\"$class\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 556 | return $str; |
| 557 | } |
| 558 | |
| 559 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 560 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 561 | /** |
| 562 | * Slide Up |
| 563 | * |
| 564 | * Outputs a jQuery slideUp event |
| 565 | * |
| 566 | * @access private |
| 567 | * @param string - element |
| 568 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 569 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 570 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 571 | */ |
| 572 | function _slideUp($element = 'this', $speed = '', $callback = '') |
| 573 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 574 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 575 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 576 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 577 | if ($callback != '') |
| 578 | { |
| 579 | $callback = ", function(){\n{$callback}\n}"; |
| 580 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 581 | |
| 582 | $str = "$({$element}).slideUp({$speed}{$callback});"; |
| 583 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 584 | return $str; |
| 585 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 586 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 587 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 588 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 589 | /** |
| 590 | * Slide Down |
| 591 | * |
| 592 | * Outputs a jQuery slideDown event |
| 593 | * |
| 594 | * @access private |
| 595 | * @param string - element |
| 596 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 597 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 598 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 599 | */ |
| 600 | function _slideDown($element = 'this', $speed = '', $callback = '') |
| 601 | { |
| 602 | $element = $this->_prep_element($element); |
| 603 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 604 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 605 | if ($callback != '') |
| 606 | { |
| 607 | $callback = ", function(){\n{$callback}\n}"; |
| 608 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 609 | |
| 610 | $str = "$({$element}).slideDown({$speed}{$callback});"; |
| 611 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 612 | return $str; |
| 613 | } |
| 614 | |
| 615 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 616 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 617 | /** |
| 618 | * Slide Toggle |
| 619 | * |
| 620 | * Outputs a jQuery slideToggle event |
| 621 | * |
| 622 | * @access public |
| 623 | * @param string - element |
| 624 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 625 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 626 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 627 | */ |
| 628 | function _slideToggle($element = 'this', $speed = '', $callback = '') |
| 629 | { |
| 630 | $element = $this->_prep_element($element); |
| 631 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 632 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 633 | if ($callback != '') |
| 634 | { |
| 635 | $callback = ", function(){\n{$callback}\n}"; |
| 636 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 637 | |
| 638 | $str = "$({$element}).slideToggle({$speed}{$callback});"; |
| 639 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 640 | return $str; |
| 641 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 642 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 643 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 644 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 645 | /** |
| 646 | * Toggle |
| 647 | * |
| 648 | * Outputs a jQuery toggle event |
| 649 | * |
| 650 | * @access private |
| 651 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 652 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 653 | */ |
| 654 | function _toggle($element = 'this') |
| 655 | { |
| 656 | $element = $this->_prep_element($element); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 657 | $str = "$({$element}).toggle();"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 658 | return $str; |
| 659 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 660 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 661 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 662 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 663 | /** |
| 664 | * Toggle Class |
| 665 | * |
| 666 | * Outputs a jQuery toggle class event |
| 667 | * |
| 668 | * @access private |
| 669 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 670 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 671 | */ |
| 672 | function _toggleClass($element = 'this', $class='') |
| 673 | { |
| 674 | $element = $this->_prep_element($element); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 675 | $str = "$({$element}).toggleClass(\"$class\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 676 | return $str; |
| 677 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 678 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 679 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 680 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 681 | /** |
| 682 | * Show |
| 683 | * |
| 684 | * Outputs a jQuery show event |
| 685 | * |
| 686 | * @access private |
| 687 | * @param string - element |
| 688 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 689 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 690 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 691 | */ |
| 692 | function _show($element = 'this', $speed = '', $callback = '') |
| 693 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 694 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 695 | $speed = $this->_validate_speed($speed); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 696 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 697 | if ($callback != '') |
| 698 | { |
| 699 | $callback = ", function(){\n{$callback}\n}"; |
| 700 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 701 | |
| 702 | $str = "$({$element}).show({$speed}{$callback});"; |
| 703 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 704 | return $str; |
| 705 | } |
| 706 | |
| 707 | // -------------------------------------------------------------------- |
| 708 | |
| 709 | /** |
| 710 | * Updater |
| 711 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 712 | * An Ajax call that populates the designated DOM node with |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 713 | * returned content |
| 714 | * |
| 715 | * @access private |
| 716 | * @param string The element to attach the event to |
| 717 | * @param string the controller to run the call against |
| 718 | * @param string optional parameters |
| 719 | * @return string |
| 720 | */ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 721 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 722 | function _updater($container = 'this', $controller, $options = '') |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 723 | { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 724 | $container = $this->_prep_element($container); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 725 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 726 | $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 727 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 728 | // ajaxStart and ajaxStop are better choices here... but this is a stop gap |
| 729 | if ($this->CI->config->item('javascript_ajax_img') == '') |
| 730 | { |
| 731 | $loading_notifier = "Loading..."; |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | $loading_notifier = '<img src=\'' . $this->CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />'; |
| 736 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 737 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 738 | $updater = "$($container).empty();\n"; // anything that was in... get it out |
| 739 | $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image |
| 740 | |
| 741 | $request_options = ''; |
| 742 | if ($options != '') |
| 743 | { |
| 744 | $request_options .= ", {"; |
| 745 | $request_options .= (is_array($options)) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'"; |
| 746 | $request_options .= "}"; |
| 747 | } |
| 748 | |
| 749 | $updater .= "\t\t$($container).load('$controller'$request_options);"; |
| 750 | return $updater; |
| 751 | } |
| 752 | |
| 753 | |
| 754 | // -------------------------------------------------------------------- |
| 755 | // Pre-written handy stuff |
| 756 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 757 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 758 | /** |
| 759 | * Zebra tables |
| 760 | * |
| 761 | * @access private |
| 762 | * @param string table name |
| 763 | * @param string plugin location |
| 764 | * @return string |
| 765 | */ |
| 766 | function _zebraTables($class = '', $odd = 'odd', $hover = '') |
| 767 | { |
| 768 | $class = ($class != '') ? '.'.$class : ''; |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 769 | |
| 770 | $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 771 | |
| 772 | $this->jquery_code_for_compile[] = $zebra; |
| 773 | |
| 774 | if ($hover != '') |
| 775 | { |
| 776 | $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); |
| 777 | } |
| 778 | |
| 779 | return $zebra; |
| 780 | } |
| 781 | |
| 782 | |
| 783 | |
| 784 | // -------------------------------------------------------------------- |
| 785 | // Plugins |
| 786 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 787 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 788 | /** |
| 789 | * Corner Plugin |
| 790 | * |
| 791 | * http://www.malsup.com/jquery/corner/ |
| 792 | * |
| 793 | * @access public |
| 794 | * @param string target |
| 795 | * @return string |
| 796 | */ |
| 797 | function corner($element = '', $corner_style = '') |
| 798 | { |
| 799 | // may want to make this configurable down the road |
| 800 | $corner_location = '/plugins/jquery.corner.js'; |
| 801 | |
| 802 | if ($corner_style != '') |
| 803 | { |
| 804 | $corner_style = '"'.$corner_style.'"'; |
| 805 | } |
| 806 | |
| 807 | return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; |
| 808 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 809 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 810 | // -------------------------------------------------------------------- |
| 811 | |
| 812 | /** |
| 813 | * modal window |
| 814 | * |
| 815 | * Load a thickbox modal window |
| 816 | * |
| 817 | * @access public |
| 818 | * @return void |
| 819 | */ |
| 820 | function modal($src, $relative = FALSE) |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 821 | { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 822 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 823 | } |
| 824 | |
| 825 | // -------------------------------------------------------------------- |
| 826 | |
| 827 | /** |
| 828 | * Effect |
| 829 | * |
| 830 | * Load an Effect library |
| 831 | * |
| 832 | * @access public |
| 833 | * @return void |
| 834 | */ |
| 835 | function effect($src, $relative = FALSE) |
| 836 | { |
| 837 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 838 | } |
| 839 | |
| 840 | // -------------------------------------------------------------------- |
| 841 | |
| 842 | /** |
| 843 | * Plugin |
| 844 | * |
| 845 | * Load a plugin library |
| 846 | * |
| 847 | * @access public |
| 848 | * @return void |
| 849 | */ |
| 850 | function plugin($src, $relative = FALSE) |
| 851 | { |
| 852 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 853 | } |
| 854 | |
| 855 | // -------------------------------------------------------------------- |
| 856 | |
| 857 | /** |
| 858 | * UI |
| 859 | * |
| 860 | * Load a user interface library |
| 861 | * |
| 862 | * @access public |
| 863 | * @return void |
| 864 | */ |
| 865 | function ui($src, $relative = FALSE) |
| 866 | { |
| 867 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 868 | } |
| 869 | // -------------------------------------------------------------------- |
| 870 | |
| 871 | /** |
| 872 | * Sortable |
| 873 | * |
| 874 | * Creates a jQuery sortable |
| 875 | * |
| 876 | * @access public |
| 877 | * @return void |
| 878 | */ |
| 879 | function sortable($element, $options = array()) |
| 880 | { |
| 881 | |
| 882 | if (count($options) > 0) |
| 883 | { |
| 884 | $sort_options = array(); |
| 885 | foreach ($options as $k=>$v) |
| 886 | { |
| 887 | $sort_options[] = "\n\t\t".$k.': '.$v.""; |
| 888 | } |
| 889 | $sort_options = implode(",", $sort_options); |
| 890 | } |
| 891 | else |
| 892 | { |
| 893 | $sort_options = ''; |
| 894 | } |
| 895 | |
| 896 | return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});"; |
| 897 | } |
| 898 | |
| 899 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 900 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 901 | /** |
| 902 | * Table Sorter Plugin |
| 903 | * |
| 904 | * @access public |
| 905 | * @param string table name |
| 906 | * @param string plugin location |
| 907 | * @return string |
| 908 | */ |
| 909 | function tablesorter($table = '', $options = '') |
| 910 | { |
| 911 | $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; |
| 912 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 913 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 914 | // -------------------------------------------------------------------- |
| 915 | // Class functions |
| 916 | // -------------------------------------------------------------------- |
| 917 | |
| 918 | /** |
| 919 | * Add Event |
| 920 | * |
| 921 | * Constructs the syntax for an event, and adds to into the array for compilation |
| 922 | * |
| 923 | * @access private |
| 924 | * @param string The element to attach the event to |
| 925 | * @param string The code to execute |
| 926 | * @param string The event to pass |
| 927 | * @return string |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 928 | */ |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 929 | function _add_event($element, $js, $event) |
| 930 | { |
| 931 | if (is_array($js)) |
| 932 | { |
| 933 | $js = implode("\n\t\t", $js); |
| 934 | |
| 935 | } |
| 936 | |
| 937 | $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n"; |
| 938 | $this->jquery_code_for_compile[] = $event; |
| 939 | return $event; |
| 940 | } |
| 941 | |
| 942 | // -------------------------------------------------------------------- |
| 943 | |
| 944 | /** |
| 945 | * Compile |
| 946 | * |
| 947 | * As events are specified, they are stored in an array |
| 948 | * This funciton compiles them all for output on a page |
| 949 | * |
| 950 | * @access private |
| 951 | * @return string |
| 952 | */ |
| 953 | function _compile($view_var = 'script_foot', $script_tags = TRUE) |
| 954 | { |
| 955 | // External references |
| 956 | $external_scripts = implode('', $this->jquery_code_for_load); |
| 957 | $this->CI->load->vars(array('library_src' => $external_scripts)); |
| 958 | |
| 959 | if (count($this->jquery_code_for_compile) == 0 ) |
| 960 | { |
| 961 | // no inline references, let's just return |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | // Inline references |
| 966 | $script = '$(document).ready(function() {' . "\n"; |
| 967 | $script .= implode('', $this->jquery_code_for_compile); |
| 968 | $script .= '});'; |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 969 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 970 | $output = ($script_tags === FALSE) ? $script : $this->inline($script); |
| 971 | |
| 972 | $this->CI->load->vars(array($view_var => $output)); |
| 973 | |
| 974 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 975 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 976 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 977 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 978 | /** |
| 979 | * Clear Compile |
| 980 | * |
| 981 | * Clears the array of script events collected for output |
| 982 | * |
| 983 | * @access public |
| 984 | * @return void |
| 985 | */ |
| 986 | function _clear_compile() |
| 987 | { |
| 988 | $this->jquery_code_for_compile = array(); |
| 989 | } |
| 990 | |
| 991 | // -------------------------------------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 992 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 993 | /** |
| 994 | * Document Ready |
| 995 | * |
| 996 | * A wrapper for writing document.ready() |
| 997 | * |
| 998 | * @access private |
| 999 | * @return string |
| 1000 | */ |
| 1001 | function _document_ready($js) |
| 1002 | { |
| 1003 | if ( ! is_array($js)) |
| 1004 | { |
| 1005 | $js = array ($js); |
| 1006 | |
| 1007 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1008 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1009 | foreach ($js as $script) |
| 1010 | { |
| 1011 | $this->jquery_code_for_compile[] = $script; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | // -------------------------------------------------------------------- |
| 1016 | |
| 1017 | /** |
| 1018 | * Script Tag |
| 1019 | * |
| 1020 | * Outputs the script tag that loads the jquery.js file into an HTML document |
| 1021 | * |
| 1022 | * @access public |
| 1023 | * @param string |
| 1024 | * @return string |
| 1025 | */ |
| 1026 | function script($library_src = '', $relative = FALSE) |
| 1027 | { |
| 1028 | $library_src = $this->external($library_src, $relative); |
| 1029 | $this->jquery_code_for_load[] = $library_src; |
| 1030 | return $library_src; |
| 1031 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1032 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1033 | // -------------------------------------------------------------------- |
| 1034 | |
| 1035 | /** |
| 1036 | * Prep Element |
| 1037 | * |
| 1038 | * Puts HTML element in quotes for use in jQuery code |
| 1039 | * unless the supplied element is the Javascript 'this' |
| 1040 | * object, in which case no quotes are added |
| 1041 | * |
| 1042 | * @access public |
| 1043 | * @param string |
| 1044 | * @return string |
| 1045 | */ |
| 1046 | function _prep_element($element) |
| 1047 | { |
| 1048 | if ($element != 'this') |
| 1049 | { |
| 1050 | $element = '"'.$element.'"'; |
| 1051 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1052 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1053 | return $element; |
| 1054 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1055 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1056 | // -------------------------------------------------------------------- |
| 1057 | |
| 1058 | /** |
| 1059 | * Validate Speed |
| 1060 | * |
| 1061 | * Ensures the speed parameter is valid for jQuery |
| 1062 | * |
| 1063 | * @access private |
| 1064 | * @param string |
| 1065 | * @return string |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1066 | */ |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1067 | function _validate_speed($speed) |
| 1068 | { |
| 1069 | if (in_array($speed, array('slow', 'normal', 'fast'))) |
| 1070 | { |
| 1071 | $speed = '"'.$speed.'"'; |
| 1072 | } |
| 1073 | elseif (preg_match("/[^0-9]/", $speed)) |
| 1074 | { |
| 1075 | $speed = ''; |
| 1076 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1077 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1078 | return $speed; |
| 1079 | } |
| 1080 | |
| 1081 | } |
| 1082 | |
| 1083 | /* End of file Jquery.php */ |
| 1084 | /* Location: ./system/libraries/Jquery.php */ |