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 | * |
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 |
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 | |
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 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [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 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 42 | protected $_javascript_folder = 'js'; |
| 43 | public $jquery_code_for_load = array(); |
| 44 | public $jquery_code_for_compile = array(); |
| 45 | public $jquery_corner_active = FALSE; |
| 46 | public $jquery_table_sorter_active = FALSE; |
| 47 | public $jquery_table_sorter_pager_active = FALSE; |
| 48 | public $jquery_ajax_img = ''; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 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 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [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 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 57 | $this->script(); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 58 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 59 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 60 | log_message('debug', "Jquery Class Initialized"); |
| 61 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 62 | |
| 63 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 64 | // Event Code |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [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 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 72 | * @param string The element to attach the event to |
| 73 | * @param string The code to execute |
| 74 | * @return string |
| 75 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 76 | protected function _blur($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 77 | { |
| 78 | return $this->_add_event($element, $js, 'blur'); |
| 79 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 80 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 81 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 82 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 83 | /** |
| 84 | * Change |
| 85 | * |
| 86 | * Outputs a jQuery change event |
| 87 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 88 | * @param string The element to attach the event to |
| 89 | * @param string The code to execute |
| 90 | * @return string |
| 91 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 92 | protected function _change($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 93 | { |
| 94 | return $this->_add_event($element, $js, 'change'); |
| 95 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 96 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 97 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 98 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 99 | /** |
| 100 | * Click |
| 101 | * |
| 102 | * Outputs a jQuery click event |
| 103 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 104 | * @param string The element to attach the event to |
| 105 | * @param string The code to execute |
| 106 | * @param boolean whether or not to return false |
| 107 | * @return string |
| 108 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 109 | protected function _click($element = 'this', $js = '', $ret_false = TRUE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 110 | { |
| 111 | if ( ! is_array($js)) |
| 112 | { |
| 113 | $js = array($js); |
| 114 | } |
| 115 | |
| 116 | if ($ret_false) |
| 117 | { |
| 118 | $js[] = "return false;"; |
| 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 | { |
| 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"; |
| 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 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 312 | * @param string The element to attach the event to |
| 313 | * @param string The code to execute |
| 314 | * @return string |
| 315 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 316 | protected function _output($array_js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 317 | { |
| 318 | if ( ! is_array($array_js)) |
| 319 | { |
| 320 | $array_js = array($array_js); |
| 321 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 322 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 323 | foreach ($array_js as $js) |
| 324 | { |
| 325 | $this->jquery_code_for_compile[] = "\t$js\n"; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // -------------------------------------------------------------------- |
| 330 | |
| 331 | /** |
| 332 | * Resize |
| 333 | * |
| 334 | * Outputs a jQuery resize event |
| 335 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 336 | * @param string The element to attach the event to |
| 337 | * @param string The code to execute |
| 338 | * @return string |
| 339 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 340 | protected function _resize($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 341 | { |
| 342 | return $this->_add_event($element, $js, 'resize'); |
| 343 | } |
| 344 | |
| 345 | // -------------------------------------------------------------------- |
| 346 | |
| 347 | /** |
| 348 | * Scroll |
| 349 | * |
| 350 | * Outputs a jQuery scroll event |
| 351 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 352 | * @param string The element to attach the event to |
| 353 | * @param string The code to execute |
| 354 | * @return string |
| 355 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 356 | protected function _scroll($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 357 | { |
| 358 | return $this->_add_event($element, $js, 'scroll'); |
| 359 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 360 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 361 | // -------------------------------------------------------------------- |
| 362 | |
| 363 | /** |
| 364 | * Unload |
| 365 | * |
| 366 | * Outputs a jQuery unload event |
| 367 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 368 | * @param string The element to attach the event to |
| 369 | * @param string The code to execute |
| 370 | * @return string |
| 371 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 372 | protected function _unload($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 373 | { |
| 374 | return $this->_add_event($element, $js, 'unload'); |
| 375 | } |
| 376 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 377 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 378 | // Effects |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 379 | // -------------------------------------------------------------------- |
| 380 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 381 | /** |
| 382 | * Add Class |
| 383 | * |
| 384 | * Outputs a jQuery addClass event |
| 385 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 386 | * @param string - element |
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 | ad47f94 | 2011-12-25 19:13:48 +0200 | [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 | ad47f94 | 2011-12-25 19:13:48 +0200 | [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 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 402 | * @param string - element |
| 403 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 404 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 406 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 407 | protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 408 | { |
| 409 | $element = $this->_prep_element($element); |
| 410 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 411 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 412 | $animations = "\t\t\t"; |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 413 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 414 | foreach ($params as $param=>$value) |
| 415 | { |
| 416 | $animations .= $param.': \''.$value.'\', '; |
| 417 | } |
| 418 | |
| 419 | $animations = substr($animations, 0, -2); // remove the last ", " |
| 420 | |
| 421 | if ($speed != '') |
| 422 | { |
| 423 | $speed = ', '.$speed; |
| 424 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 425 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 426 | if ($extra != '') |
| 427 | { |
| 428 | $extra = ', '.$extra; |
| 429 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 430 | |
| 431 | return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 435 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 436 | /** |
| 437 | * Fade In |
| 438 | * |
| 439 | * Outputs a jQuery hide event |
| 440 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 441 | * @param string - element |
| 442 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 443 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 444 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 445 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 446 | protected function _fadeIn($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 447 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 448 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 449 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 450 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 451 | if ($callback != '') |
| 452 | { |
| 453 | $callback = ", function(){\n{$callback}\n}"; |
| 454 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 455 | |
| 456 | return "$({$element}).fadeIn({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 457 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 458 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 459 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 460 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 461 | /** |
| 462 | * Fade Out |
| 463 | * |
| 464 | * Outputs a jQuery hide event |
| 465 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 466 | * @param string - element |
| 467 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 468 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 469 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 470 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 471 | protected function _fadeOut($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 472 | { |
| 473 | $element = $this->_prep_element($element); |
| 474 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 475 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 476 | if ($callback != '') |
| 477 | { |
| 478 | $callback = ", function(){\n{$callback}\n}"; |
| 479 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 480 | |
| 481 | return "$({$element}).fadeOut({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // -------------------------------------------------------------------- |
| 485 | |
| 486 | /** |
| 487 | * Hide |
| 488 | * |
| 489 | * Outputs a jQuery hide action |
| 490 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 491 | * @param string - element |
| 492 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 493 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 494 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 495 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 496 | protected function _hide($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 497 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 498 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 499 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 500 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 501 | if ($callback != '') |
| 502 | { |
| 503 | $callback = ", function(){\n{$callback}\n}"; |
| 504 | } |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 505 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 506 | return "$({$element}).hide({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 507 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 508 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 509 | // -------------------------------------------------------------------- |
| 510 | |
| 511 | /** |
| 512 | * Remove Class |
| 513 | * |
| 514 | * Outputs a jQuery remove class event |
| 515 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 516 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 517 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 518 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 519 | protected function _removeClass($element = 'this', $class='') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 520 | { |
| 521 | $element = $this->_prep_element($element); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 522 | return "$({$element}).removeClass(\"$class\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 526 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 527 | /** |
| 528 | * Slide Up |
| 529 | * |
| 530 | * Outputs a jQuery slideUp event |
| 531 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 532 | * @param string - element |
| 533 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 534 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 535 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 536 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 537 | protected function _slideUp($element = 'this', $speed = '', $callback = '') |
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 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 540 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 541 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 542 | if ($callback != '') |
| 543 | { |
| 544 | $callback = ", function(){\n{$callback}\n}"; |
| 545 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 546 | |
| 547 | return "$({$element}).slideUp({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 548 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 549 | |
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 | /** |
| 553 | * Slide Down |
| 554 | * |
| 555 | * Outputs a jQuery slideDown event |
| 556 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 557 | * @param string - element |
| 558 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 559 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 560 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 561 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 562 | protected function _slideDown($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 563 | { |
| 564 | $element = $this->_prep_element($element); |
| 565 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 566 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 567 | if ($callback != '') |
| 568 | { |
| 569 | $callback = ", function(){\n{$callback}\n}"; |
| 570 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 571 | |
| 572 | return "$({$element}).slideDown({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 576 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 577 | /** |
| 578 | * Slide Toggle |
| 579 | * |
| 580 | * Outputs a jQuery slideToggle event |
| 581 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 582 | * @param string - element |
| 583 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 584 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 585 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 586 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 587 | protected function _slideToggle($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 588 | { |
| 589 | $element = $this->_prep_element($element); |
| 590 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 591 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 592 | if ($callback != '') |
| 593 | { |
| 594 | $callback = ", function(){\n{$callback}\n}"; |
| 595 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 596 | |
| 597 | return "$({$element}).slideToggle({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 598 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 599 | |
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 | /** |
| 603 | * Toggle |
| 604 | * |
| 605 | * Outputs a jQuery toggle event |
| 606 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 607 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 608 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 609 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 610 | protected function _toggle($element = 'this') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 611 | { |
| 612 | $element = $this->_prep_element($element); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 613 | return "$({$element}).toggle();"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 614 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 615 | |
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 | /** |
| 619 | * Toggle Class |
| 620 | * |
| 621 | * Outputs a jQuery toggle class event |
| 622 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 623 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 624 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 625 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 626 | protected function _toggleClass($element = 'this', $class='') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 627 | { |
| 628 | $element = $this->_prep_element($element); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 629 | return "$({$element}).toggleClass(\"$class\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 630 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 631 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 632 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 633 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 634 | /** |
| 635 | * Show |
| 636 | * |
| 637 | * Outputs a jQuery show event |
| 638 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 639 | * @param string - element |
| 640 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 641 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 642 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 643 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 644 | protected function _show($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 645 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 646 | $element = $this->_prep_element($element); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 647 | $speed = $this->_validate_speed($speed); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 648 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 649 | if ($callback != '') |
| 650 | { |
| 651 | $callback = ", function(){\n{$callback}\n}"; |
| 652 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 653 | |
| 654 | return "$({$element}).show({$speed}{$callback});"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | // -------------------------------------------------------------------- |
| 658 | |
| 659 | /** |
| 660 | * Updater |
| 661 | * |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 662 | * An Ajax call that populates the designated DOM node with |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 663 | * returned content |
| 664 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 665 | * @param string The element to attach the event to |
| 666 | * @param string the controller to run the call against |
| 667 | * @param string optional parameters |
| 668 | * @return string |
| 669 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 670 | |
| 671 | protected function _updater($container = 'this', $controller, $options = '') |
| 672 | { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 673 | $container = $this->_prep_element($container); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 674 | $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 675 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 676 | // ajaxStart and ajaxStop are better choices here... but this is a stop gap |
| 677 | if ($this->CI->config->item('javascript_ajax_img') == '') |
| 678 | { |
| 679 | $loading_notifier = "Loading..."; |
| 680 | } |
| 681 | else |
| 682 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 683 | $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] | 684 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 685 | |
| 686 | $updater = "$($container).empty();\n" // anything that was in... get it out |
| 687 | . "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 688 | |
| 689 | $request_options = ''; |
| 690 | if ($options != '') |
| 691 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 692 | $request_options .= ', {' |
| 693 | . (is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'") |
| 694 | . '}'; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 695 | } |
| 696 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 697 | return $updater."\t\t$($container).load('$controller'$request_options);"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
| 701 | // -------------------------------------------------------------------- |
| 702 | // Pre-written handy stuff |
| 703 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 704 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 705 | /** |
| 706 | * Zebra tables |
| 707 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 708 | * @param string table name |
| 709 | * @param string plugin location |
| 710 | * @return string |
| 711 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 712 | protected function _zebraTables($class = '', $odd = 'odd', $hover = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 713 | { |
| 714 | $class = ($class != '') ? '.'.$class : ''; |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 715 | $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 716 | |
| 717 | $this->jquery_code_for_compile[] = $zebra; |
| 718 | |
| 719 | if ($hover != '') |
| 720 | { |
| 721 | $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); |
| 722 | } |
| 723 | |
| 724 | return $zebra; |
| 725 | } |
| 726 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 727 | // -------------------------------------------------------------------- |
| 728 | // Plugins |
| 729 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 730 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 731 | /** |
| 732 | * Corner Plugin |
| 733 | * |
| 734 | * http://www.malsup.com/jquery/corner/ |
| 735 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 736 | * @param string target |
| 737 | * @return string |
| 738 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 739 | public function corner($element = '', $corner_style = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 740 | { |
| 741 | // may want to make this configurable down the road |
| 742 | $corner_location = '/plugins/jquery.corner.js'; |
| 743 | |
| 744 | if ($corner_style != '') |
| 745 | { |
| 746 | $corner_style = '"'.$corner_style.'"'; |
| 747 | } |
| 748 | |
| 749 | return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; |
| 750 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 751 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 752 | // -------------------------------------------------------------------- |
| 753 | |
| 754 | /** |
| 755 | * modal window |
| 756 | * |
| 757 | * Load a thickbox modal window |
| 758 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 759 | * @return void |
| 760 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 761 | public function modal($src, $relative = FALSE) |
| 762 | { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 763 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 764 | } |
| 765 | |
| 766 | // -------------------------------------------------------------------- |
| 767 | |
| 768 | /** |
| 769 | * Effect |
| 770 | * |
| 771 | * Load an Effect library |
| 772 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 773 | * @return void |
| 774 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 775 | public function effect($src, $relative = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 776 | { |
| 777 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 778 | } |
| 779 | |
| 780 | // -------------------------------------------------------------------- |
| 781 | |
| 782 | /** |
| 783 | * Plugin |
| 784 | * |
| 785 | * Load a plugin library |
| 786 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 787 | * @return void |
| 788 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 789 | public function plugin($src, $relative = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 790 | { |
| 791 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 792 | } |
| 793 | |
| 794 | // -------------------------------------------------------------------- |
| 795 | |
| 796 | /** |
| 797 | * UI |
| 798 | * |
| 799 | * Load a user interface library |
| 800 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 801 | * @return void |
| 802 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 803 | public function ui($src, $relative = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 804 | { |
| 805 | $this->jquery_code_for_load[] = $this->external($src, $relative); |
| 806 | } |
| 807 | // -------------------------------------------------------------------- |
| 808 | |
| 809 | /** |
| 810 | * Sortable |
| 811 | * |
| 812 | * Creates a jQuery sortable |
| 813 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 814 | * @return void |
| 815 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 816 | public function sortable($element, $options = array()) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 817 | { |
| 818 | |
| 819 | if (count($options) > 0) |
| 820 | { |
| 821 | $sort_options = array(); |
| 822 | foreach ($options as $k=>$v) |
| 823 | { |
| 824 | $sort_options[] = "\n\t\t".$k.': '.$v.""; |
| 825 | } |
| 826 | $sort_options = implode(",", $sort_options); |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | $sort_options = ''; |
| 831 | } |
| 832 | |
| 833 | return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});"; |
| 834 | } |
| 835 | |
| 836 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 837 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 838 | /** |
| 839 | * Table Sorter Plugin |
| 840 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 841 | * @param string table name |
| 842 | * @param string plugin location |
| 843 | * @return string |
| 844 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 845 | public function tablesorter($table = '', $options = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 846 | { |
| 847 | $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; |
| 848 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 849 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 850 | // -------------------------------------------------------------------- |
| 851 | // Class functions |
| 852 | // -------------------------------------------------------------------- |
| 853 | |
| 854 | /** |
| 855 | * Add Event |
| 856 | * |
| 857 | * Constructs the syntax for an event, and adds to into the array for compilation |
| 858 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 859 | * @param string The element to attach the event to |
| 860 | * @param string The code to execute |
| 861 | * @param string The event to pass |
| 862 | * @return string |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 863 | */ |
| 864 | protected function _add_event($element, $js, $event) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 865 | { |
| 866 | if (is_array($js)) |
| 867 | { |
| 868 | $js = implode("\n\t\t", $js); |
| 869 | |
| 870 | } |
| 871 | |
| 872 | $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n"; |
| 873 | $this->jquery_code_for_compile[] = $event; |
| 874 | return $event; |
| 875 | } |
| 876 | |
| 877 | // -------------------------------------------------------------------- |
| 878 | |
| 879 | /** |
| 880 | * Compile |
| 881 | * |
| 882 | * As events are specified, they are stored in an array |
| 883 | * This funciton compiles them all for output on a page |
| 884 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 885 | * @return string |
| 886 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 887 | protected function _compile($view_var = 'script_foot', $script_tags = TRUE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 888 | { |
| 889 | // External references |
| 890 | $external_scripts = implode('', $this->jquery_code_for_load); |
| 891 | $this->CI->load->vars(array('library_src' => $external_scripts)); |
| 892 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 893 | if (count($this->jquery_code_for_compile) === 0) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 894 | { |
| 895 | // no inline references, let's just return |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | // Inline references |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 900 | $script = '$(document).ready(function() {'."\n" |
| 901 | . implode('', $this->jquery_code_for_compile) |
| 902 | . '});'; |
| 903 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 904 | $output = ($script_tags === FALSE) ? $script : $this->inline($script); |
| 905 | |
| 906 | $this->CI->load->vars(array($view_var => $output)); |
| 907 | |
| 908 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 909 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 910 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 911 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 912 | /** |
| 913 | * Clear Compile |
| 914 | * |
| 915 | * Clears the array of script events collected for output |
| 916 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 917 | * @return void |
| 918 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 919 | protected function _clear_compile() |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 920 | { |
| 921 | $this->jquery_code_for_compile = array(); |
| 922 | } |
| 923 | |
| 924 | // -------------------------------------------------------------------- |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 925 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 926 | /** |
| 927 | * Document Ready |
| 928 | * |
| 929 | * A wrapper for writing document.ready() |
| 930 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 931 | * @return string |
| 932 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 933 | protected function _document_ready($js) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 934 | { |
| 935 | if ( ! is_array($js)) |
| 936 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 937 | $js = array($js); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 938 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 939 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 940 | foreach ($js as $script) |
| 941 | { |
| 942 | $this->jquery_code_for_compile[] = $script; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // -------------------------------------------------------------------- |
| 947 | |
| 948 | /** |
| 949 | * Script Tag |
| 950 | * |
| 951 | * Outputs the script tag that loads the jquery.js file into an HTML document |
| 952 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 953 | * @param string |
| 954 | * @return string |
| 955 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 956 | public function script($library_src = '', $relative = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 957 | { |
| 958 | $library_src = $this->external($library_src, $relative); |
| 959 | $this->jquery_code_for_load[] = $library_src; |
| 960 | return $library_src; |
| 961 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 962 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 963 | // -------------------------------------------------------------------- |
| 964 | |
| 965 | /** |
| 966 | * Prep Element |
| 967 | * |
| 968 | * Puts HTML element in quotes for use in jQuery code |
| 969 | * unless the supplied element is the Javascript 'this' |
| 970 | * object, in which case no quotes are added |
| 971 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 972 | * @param string |
| 973 | * @return string |
| 974 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 975 | protected function _prep_element($element) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 976 | { |
| 977 | if ($element != 'this') |
| 978 | { |
| 979 | $element = '"'.$element.'"'; |
| 980 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 981 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 982 | return $element; |
| 983 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 984 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 985 | // -------------------------------------------------------------------- |
| 986 | |
| 987 | /** |
| 988 | * Validate Speed |
| 989 | * |
| 990 | * Ensures the speed parameter is valid for jQuery |
| 991 | * |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 992 | * @param string |
| 993 | * @return string |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 994 | */ |
| 995 | protected function _validate_speed($speed) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 996 | { |
| 997 | if (in_array($speed, array('slow', 'normal', 'fast'))) |
| 998 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 999 | return '"'.$speed.'"'; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1000 | } |
| 1001 | elseif (preg_match("/[^0-9]/", $speed)) |
| 1002 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 1003 | return ''; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1004 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 1005 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 1006 | return $speed; |
| 1007 | } |
| 1008 | |
| 1009 | } |
| 1010 | |
| 1011 | /* End of file Jquery.php */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame] | 1012 | /* Location: ./system/libraries/Jquery.php */ |