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