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