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