Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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. |
| 18 | * |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 27 | |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 28 | // ------------------------------------------------------------------------ |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 29 | |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 30 | /** |
| 31 | * Javascript Class |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category Javascript |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
fesplugas | 3934a4a | 2010-10-04 09:07:49 +0200 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/libraries/javascript.html |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 38 | */ |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 39 | class CI_Javascript { |
| 40 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 41 | protected $_javascript_location = 'js'; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 42 | |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 43 | public function __construct($params = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 44 | { |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 45 | $defaults = array('js_library_driver' => 'jquery', 'autoload' => TRUE); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 46 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 47 | foreach ($defaults as $key => $val) |
| 48 | { |
| 49 | if (isset($params[$key]) && $params[$key] !== "") |
| 50 | { |
| 51 | $defaults[$key] = $params[$key]; |
| 52 | } |
| 53 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 54 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 55 | extract($defaults); |
| 56 | |
| 57 | $this->CI =& get_instance(); |
| 58 | |
| 59 | // load the requested js library |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 60 | $this->CI->load->library('javascript/'.$js_library_driver, array('autoload' => $autoload)); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 61 | // make js to refer to current library |
| 62 | $this->js =& $this->CI->$js_library_driver; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 63 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 64 | log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 65 | } |
| 66 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 67 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 68 | // Event Code |
| 69 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Blur |
| 73 | * |
| 74 | * Outputs a javascript library blur event |
| 75 | * |
| 76 | * @access public |
| 77 | * @param string The element to attach the event to |
| 78 | * @param string The code to execute |
| 79 | * @return string |
| 80 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 81 | public function blur($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 82 | { |
| 83 | return $this->js->_blur($element, $js); |
| 84 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 85 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 86 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 87 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 88 | /** |
| 89 | * Change |
| 90 | * |
| 91 | * Outputs a javascript library change event |
| 92 | * |
| 93 | * @access public |
| 94 | * @param string The element to attach the event to |
| 95 | * @param string The code to execute |
| 96 | * @return string |
| 97 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 98 | public function change($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 99 | { |
| 100 | return $this->js->_change($element, $js); |
| 101 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 102 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 103 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 105 | /** |
| 106 | * Click |
| 107 | * |
| 108 | * Outputs a javascript library click event |
| 109 | * |
| 110 | * @access public |
| 111 | * @param string The element to attach the event to |
| 112 | * @param string The code to execute |
| 113 | * @param boolean whether or not to return false |
| 114 | * @return string |
| 115 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 116 | public function click($element = 'this', $js = '', $ret_false = TRUE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 117 | { |
| 118 | return $this->js->_click($element, $js, $ret_false); |
| 119 | } |
| 120 | |
| 121 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 122 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 123 | /** |
| 124 | * Double Click |
| 125 | * |
| 126 | * Outputs a javascript library dblclick event |
| 127 | * |
| 128 | * @access public |
| 129 | * @param string The element to attach the event to |
| 130 | * @param string The code to execute |
| 131 | * @return string |
| 132 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 133 | public function dblclick($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 134 | { |
| 135 | return $this->js->_dblclick($element, $js); |
| 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 139 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 140 | /** |
| 141 | * Error |
| 142 | * |
| 143 | * Outputs a javascript library error event |
| 144 | * |
| 145 | * @access public |
| 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 | public function error($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 151 | { |
| 152 | return $this->js->_error($element, $js); |
| 153 | } |
| 154 | |
| 155 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 156 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 157 | /** |
| 158 | * Focus |
| 159 | * |
| 160 | * Outputs a javascript library focus event |
| 161 | * |
| 162 | * @access public |
| 163 | * @param string The element to attach the event to |
| 164 | * @param string The code to execute |
| 165 | * @return string |
| 166 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 167 | public function focus($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 168 | { |
| 169 | return $this->js->__add_event($focus, $js); |
| 170 | } |
| 171 | |
| 172 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 173 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 174 | /** |
| 175 | * Hover |
| 176 | * |
| 177 | * Outputs a javascript library hover event |
| 178 | * |
| 179 | * @access public |
| 180 | * @param string - element |
| 181 | * @param string - Javascript code for mouse over |
| 182 | * @param string - Javascript code for mouse out |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 183 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 184 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 185 | public function hover($element = 'this', $over, $out) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 186 | { |
| 187 | return $this->js->__hover($element, $over, $out); |
| 188 | } |
| 189 | |
| 190 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 191 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 192 | /** |
| 193 | * Keydown |
| 194 | * |
| 195 | * Outputs a javascript library keydown event |
| 196 | * |
| 197 | * @access public |
| 198 | * @param string The element to attach the event to |
| 199 | * @param string The code to execute |
| 200 | * @return string |
| 201 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 202 | public function keydown($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 203 | { |
| 204 | return $this->js->_keydown($element, $js); |
| 205 | } |
| 206 | |
| 207 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 208 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 209 | /** |
| 210 | * Keyup |
| 211 | * |
| 212 | * Outputs a javascript library keydown event |
| 213 | * |
| 214 | * @access public |
| 215 | * @param string The element to attach the event to |
| 216 | * @param string The code to execute |
| 217 | * @return string |
| 218 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 219 | public function keyup($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 220 | { |
| 221 | return $this->js->_keyup($element, $js); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | } |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 223 | |
| 224 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 225 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 226 | /** |
| 227 | * Load |
| 228 | * |
| 229 | * Outputs a javascript library load event |
| 230 | * |
| 231 | * @access public |
| 232 | * @param string The element to attach the event to |
| 233 | * @param string The code to execute |
| 234 | * @return string |
| 235 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 236 | public function load($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 237 | { |
| 238 | return $this->js->_load($element, $js); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 241 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 242 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 243 | /** |
| 244 | * Mousedown |
| 245 | * |
| 246 | * Outputs a javascript library mousedown event |
| 247 | * |
| 248 | * @access public |
| 249 | * @param string The element to attach the event to |
| 250 | * @param string The code to execute |
| 251 | * @return string |
| 252 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 253 | public function mousedown($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 254 | { |
| 255 | return $this->js->_mousedown($element, $js); |
| 256 | } |
| 257 | |
| 258 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 260 | /** |
| 261 | * Mouse Out |
| 262 | * |
| 263 | * Outputs a javascript library mouseout event |
| 264 | * |
| 265 | * @access public |
| 266 | * @param string The element to attach the event to |
| 267 | * @param string The code to execute |
| 268 | * @return string |
| 269 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 270 | public function mouseout($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 271 | { |
| 272 | return $this->js->_mouseout($element, $js); |
| 273 | } |
| 274 | |
| 275 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 276 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 277 | /** |
| 278 | * Mouse Over |
| 279 | * |
| 280 | * Outputs a javascript library mouseover event |
| 281 | * |
| 282 | * @access public |
| 283 | * @param string The element to attach the event to |
| 284 | * @param string The code to execute |
| 285 | * @return string |
| 286 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 287 | public function mouseover($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 288 | { |
| 289 | return $this->js->_mouseover($element, $js); |
| 290 | } |
| 291 | |
| 292 | // -------------------------------------------------------------------- |
| 293 | |
| 294 | /** |
| 295 | * Mouseup |
| 296 | * |
| 297 | * Outputs a javascript library mouseup event |
| 298 | * |
| 299 | * @access public |
| 300 | * @param string The element to attach the event to |
| 301 | * @param string The code to execute |
| 302 | * @return string |
| 303 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 304 | public function mouseup($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 305 | { |
| 306 | return $this->js->_mouseup($element, $js); |
| 307 | } |
| 308 | |
| 309 | // -------------------------------------------------------------------- |
| 310 | |
| 311 | /** |
| 312 | * Output |
| 313 | * |
| 314 | * Outputs the called javascript to the screen |
| 315 | * |
| 316 | * @access public |
| 317 | * @param string The code to output |
| 318 | * @return string |
| 319 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 320 | public function output($js) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 321 | { |
| 322 | return $this->js->_output($js); |
| 323 | } |
| 324 | |
| 325 | // -------------------------------------------------------------------- |
| 326 | |
| 327 | /** |
| 328 | * Ready |
| 329 | * |
| 330 | * Outputs a javascript library mouseup event |
| 331 | * |
| 332 | * @access public |
| 333 | * @param string The element to attach the event to |
| 334 | * @param string The code to execute |
| 335 | * @return string |
| 336 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 337 | public function ready($js) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 338 | { |
| 339 | return $this->js->_document_ready($js); |
| 340 | } |
| 341 | |
| 342 | // -------------------------------------------------------------------- |
| 343 | |
| 344 | /** |
| 345 | * Resize |
| 346 | * |
| 347 | * Outputs a javascript library resize event |
| 348 | * |
| 349 | * @access public |
| 350 | * @param string The element to attach the event to |
| 351 | * @param string The code to execute |
| 352 | * @return string |
| 353 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 354 | public function resize($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 355 | { |
| 356 | return $this->js->_resize($element, $js); |
| 357 | } |
| 358 | |
| 359 | // -------------------------------------------------------------------- |
| 360 | |
| 361 | /** |
| 362 | * Scroll |
| 363 | * |
| 364 | * Outputs a javascript library scroll event |
| 365 | * |
| 366 | * @access public |
| 367 | * @param string The element to attach the event to |
| 368 | * @param string The code to execute |
| 369 | * @return string |
| 370 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 371 | public function scroll($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 372 | { |
| 373 | return $this->js->_scroll($element, $js); |
| 374 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 375 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 376 | // -------------------------------------------------------------------- |
| 377 | |
| 378 | /** |
| 379 | * Unload |
| 380 | * |
| 381 | * Outputs a javascript library unload event |
| 382 | * |
| 383 | * @access public |
| 384 | * @param string The element to attach the event to |
| 385 | * @param string The code to execute |
| 386 | * @return string |
| 387 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 388 | public function unload($element = 'this', $js = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 389 | { |
| 390 | return $this->js->_unload($element, $js); |
| 391 | } |
| 392 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 393 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 394 | // Effects |
| 395 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 396 | |
| 397 | |
| 398 | /** |
| 399 | * Add Class |
| 400 | * |
| 401 | * Outputs a javascript library addClass event |
| 402 | * |
| 403 | * @access public |
| 404 | * @param string - element |
| 405 | * @param string - Class to add |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 406 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 407 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 408 | public function addClass($element = 'this', $class = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 409 | { |
| 410 | return $this->js->_addClass($element, $class); |
| 411 | } |
| 412 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 413 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 414 | |
| 415 | /** |
| 416 | * Animate |
| 417 | * |
| 418 | * Outputs a javascript library animate event |
| 419 | * |
| 420 | * @access public |
| 421 | * @param string - element |
| 422 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 423 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 424 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 425 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 426 | public function animate($element = 'this', $params = array(), $speed = '', $extra = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 427 | { |
| 428 | return $this->js->_animate($element, $params, $speed, $extra); |
| 429 | } |
| 430 | |
| 431 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 432 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 433 | /** |
| 434 | * Fade In |
| 435 | * |
| 436 | * Outputs a javascript library hide event |
| 437 | * |
| 438 | * @access public |
| 439 | * @param string - element |
| 440 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 441 | * @param string - Javascript callback function |
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 | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 444 | public function fadeIn($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 445 | { |
| 446 | return $this->js->_fadeIn($element, $speed, $callback); |
| 447 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 448 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 449 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 450 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 451 | /** |
| 452 | * Fade Out |
| 453 | * |
| 454 | * Outputs a javascript library hide event |
| 455 | * |
| 456 | * @access public |
| 457 | * @param string - element |
| 458 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 459 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 460 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 461 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 462 | public function fadeOut($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 463 | { |
| 464 | return $this->js->_fadeOut($element, $speed, $callback); |
| 465 | } |
| 466 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 467 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 468 | /** |
| 469 | * Slide Up |
| 470 | * |
| 471 | * Outputs a javascript library slideUp event |
| 472 | * |
| 473 | * @access public |
| 474 | * @param string - element |
| 475 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 476 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 477 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 478 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 479 | public function slideUp($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 480 | { |
| 481 | return $this->js->_slideUp($element, $speed, $callback); |
| 482 | |
| 483 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 484 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 485 | // -------------------------------------------------------------------- |
| 486 | |
| 487 | /** |
| 488 | * Remove Class |
| 489 | * |
| 490 | * Outputs a javascript library removeClass event |
| 491 | * |
| 492 | * @access public |
| 493 | * @param string - element |
| 494 | * @param string - Class to add |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 495 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 496 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 497 | public function removeClass($element = 'this', $class = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 498 | { |
| 499 | return $this->js->_removeClass($element, $class); |
| 500 | } |
| 501 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 502 | // -------------------------------------------------------------------- |
| 503 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 504 | /** |
| 505 | * Slide Down |
| 506 | * |
| 507 | * Outputs a javascript library slideDown event |
| 508 | * |
| 509 | * @access public |
| 510 | * @param string - element |
| 511 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 512 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 513 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 514 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 515 | public function slideDown($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 516 | { |
| 517 | return $this->js->_slideDown($element, $speed, $callback); |
| 518 | } |
| 519 | |
| 520 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 521 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 522 | /** |
| 523 | * Slide Toggle |
| 524 | * |
| 525 | * Outputs a javascript library slideToggle event |
| 526 | * |
| 527 | * @access public |
| 528 | * @param string - element |
| 529 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 530 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 531 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 532 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 533 | public function slideToggle($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 534 | { |
| 535 | return $this->js->_slideToggle($element, $speed, $callback); |
| 536 | |
| 537 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 538 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 539 | // -------------------------------------------------------------------- |
| 540 | |
| 541 | /** |
| 542 | * Hide |
| 543 | * |
| 544 | * Outputs a javascript library hide action |
| 545 | * |
| 546 | * @access public |
| 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 | public function hide($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 553 | { |
| 554 | return $this->js->_hide($element, $speed, $callback); |
| 555 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 556 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 557 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 558 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 559 | /** |
| 560 | * Toggle |
| 561 | * |
| 562 | * Outputs a javascript library toggle event |
| 563 | * |
| 564 | * @access public |
| 565 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 566 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 567 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 568 | public function toggle($element = 'this') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 569 | { |
| 570 | return $this->js->_toggle($element); |
| 571 | |
| 572 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 573 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 574 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 575 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 576 | /** |
| 577 | * Toggle Class |
| 578 | * |
| 579 | * Outputs a javascript library toggle class event |
| 580 | * |
| 581 | * @access public |
| 582 | * @param string - element |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 583 | * @return string |
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 | public function toggleClass($element = 'this', $class='') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 586 | { |
| 587 | return $this->js->_toggleClass($element, $class); |
| 588 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 589 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 590 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 591 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 592 | /** |
| 593 | * Show |
| 594 | * |
| 595 | * Outputs a javascript library show event |
| 596 | * |
| 597 | * @access public |
| 598 | * @param string - element |
| 599 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 600 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 601 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 602 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 603 | public function show($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 604 | { |
| 605 | return $this->js->_show($element, $speed, $callback); |
| 606 | } |
| 607 | |
| 608 | |
| 609 | // -------------------------------------------------------------------- |
| 610 | |
| 611 | /** |
| 612 | * Compile |
| 613 | * |
| 614 | * gather together all script needing to be output |
| 615 | * |
| 616 | * @access public |
| 617 | * @param string The element to attach the event to |
| 618 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 619 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 620 | public function compile($view_var = 'script_foot', $script_tags = TRUE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 621 | { |
| 622 | $this->js->_compile($view_var, $script_tags); |
| 623 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 624 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 625 | /** |
| 626 | * Clear Compile |
| 627 | * |
| 628 | * Clears any previous javascript collected for output |
| 629 | * |
| 630 | * @access public |
| 631 | * @return void |
| 632 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 633 | public function clear_compile() |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 634 | { |
| 635 | $this->js->_clear_compile(); |
| 636 | } |
| 637 | |
| 638 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 639 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 640 | /** |
| 641 | * External |
| 642 | * |
| 643 | * Outputs a <script> tag with the source as an external js file |
| 644 | * |
| 645 | * @access public |
| 646 | * @param string The element to attach the event to |
| 647 | * @return string |
| 648 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 649 | public function external($external_file = '', $relative = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 650 | { |
| 651 | if ($external_file !== '') |
| 652 | { |
| 653 | $this->_javascript_location = $external_file; |
| 654 | } |
| 655 | else |
| 656 | { |
| 657 | if ($this->CI->config->item('javascript_location') != '') |
| 658 | { |
| 659 | $this->_javascript_location = $this->CI->config->item('javascript_location'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 660 | } |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 661 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 662 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 663 | if ($relative === TRUE OR strncmp($external_file, 'http://', 7) === 0 OR strncmp($external_file, 'https://', 8) === 0) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 664 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 665 | $str = $this->_open_script($external_file); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 666 | } |
| 667 | elseif (strpos($this->_javascript_location, 'http://') !== FALSE) |
| 668 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 669 | $str = $this->_open_script($this->_javascript_location.$external_file); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 670 | } |
| 671 | else |
| 672 | { |
| 673 | $str = $this->_open_script($this->CI->config->slash_item('base_url').$this->_javascript_location.$external_file); |
| 674 | } |
| 675 | |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 676 | return $str.$this->_close_script(); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 677 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 678 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 679 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 680 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 681 | /** |
| 682 | * Inline |
| 683 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 684 | * Outputs a <script> tag |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 685 | * |
| 686 | * @access public |
| 687 | * @param string The element to attach the event to |
| 688 | * @param boolean If a CDATA section should be added |
| 689 | * @return string |
| 690 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 691 | public function inline($script, $cdata = TRUE) |
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 | return $this->_open_script() |
| 694 | . ($cdata ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n") |
| 695 | . $this->_close_script(); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 696 | } |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 697 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 698 | // -------------------------------------------------------------------- |
| 699 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 700 | /** |
| 701 | * Open Script |
| 702 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 703 | * Outputs an opening <script> |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 704 | * |
| 705 | * @access private |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 706 | * @param string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 707 | * @return string |
| 708 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 709 | private function _open_script($src = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 710 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 711 | return '<script type="text/javascript" charset="'.strtolower($this->CI->config->item('charset')).'"' |
| 712 | . ($src == '' ? '>' : ' src="'.$src.'">'); |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 716 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 717 | /** |
| 718 | * Close Script |
| 719 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 720 | * Outputs an closing </script> |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 721 | * |
| 722 | * @access private |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 723 | * @param string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 724 | * @return string |
| 725 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 726 | private function _close_script($extra = "\n") |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 727 | { |
| 728 | return "</script>$extra"; |
| 729 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 730 | |
| 731 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 732 | // -------------------------------------------------------------------- |
| 733 | // -------------------------------------------------------------------- |
| 734 | // AJAX-Y STUFF - still a testbed |
| 735 | // -------------------------------------------------------------------- |
| 736 | // -------------------------------------------------------------------- |
| 737 | |
| 738 | /** |
| 739 | * Update |
| 740 | * |
| 741 | * Outputs a javascript library slideDown event |
| 742 | * |
| 743 | * @access public |
| 744 | * @param string - element |
| 745 | * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds |
| 746 | * @param string - Javascript callback function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 747 | * @return string |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 748 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 749 | public function update($element = 'this', $speed = '', $callback = '') |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 750 | { |
| 751 | return $this->js->_updater($element, $speed, $callback); |
| 752 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 753 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 754 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 755 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 756 | /** |
| 757 | * Generate JSON |
| 758 | * |
| 759 | * Can be passed a database result or associative array and returns a JSON formatted string |
| 760 | * |
| 761 | * @param mixed result set or array |
| 762 | * @param bool match array types (defaults to objects) |
| 763 | * @return string a json formatted string |
| 764 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 765 | public function generate_json($result = NULL, $match_array_type = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 766 | { |
| 767 | // JSON data can optionally be passed to this function |
| 768 | // either as a database result object or an array, or a user supplied array |
| 769 | if ( ! is_null($result)) |
| 770 | { |
| 771 | if (is_object($result)) |
| 772 | { |
| 773 | $json_result = $result->result_array(); |
| 774 | } |
| 775 | elseif (is_array($result)) |
| 776 | { |
| 777 | $json_result = $result; |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | return $this->_prep_args($result); |
| 782 | } |
| 783 | } |
| 784 | else |
| 785 | { |
| 786 | return 'null'; |
| 787 | } |
| 788 | |
| 789 | $json = array(); |
| 790 | $_is_assoc = TRUE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 791 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 792 | if ( ! is_array($json_result) AND empty($json_result)) |
| 793 | { |
| 794 | show_error("Generate JSON Failed - Illegal key, value pair."); |
| 795 | } |
| 796 | elseif ($match_array_type) |
| 797 | { |
| 798 | $_is_assoc = $this->_is_associative_array($json_result); |
| 799 | } |
| 800 | |
| 801 | foreach ($json_result as $k => $v) |
| 802 | { |
| 803 | if ($_is_assoc) |
| 804 | { |
| 805 | $json[] = $this->_prep_args($k, TRUE).':'.$this->generate_json($v, $match_array_type); |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | $json[] = $this->generate_json($v, $match_array_type); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | $json = implode(',', $json); |
| 814 | |
| 815 | return $_is_assoc ? "{".$json."}" : "[".$json."]"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 816 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 817 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 818 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 819 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 820 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 821 | /** |
| 822 | * Is associative array |
| 823 | * |
| 824 | * Checks for an associative array |
| 825 | * |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 826 | * @access protected |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 827 | * @param type |
| 828 | * @return type |
| 829 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 830 | protected function _is_associative_array($arr) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 831 | { |
| 832 | foreach (array_keys($arr) as $key => $val) |
| 833 | { |
| 834 | if ($key !== $val) |
| 835 | { |
| 836 | return TRUE; |
| 837 | } |
| 838 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 839 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 840 | return FALSE; |
| 841 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 842 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 843 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 844 | |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 845 | /** |
| 846 | * Prep Args |
| 847 | * |
| 848 | * Ensures a standard json value and escapes values |
| 849 | * |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 850 | * @access protected |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 851 | * @param type |
| 852 | * @return type |
| 853 | */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 854 | protected function _prep_args($result, $is_key = FALSE) |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 855 | { |
| 856 | if (is_null($result)) |
| 857 | { |
| 858 | return 'null'; |
| 859 | } |
| 860 | elseif (is_bool($result)) |
| 861 | { |
| 862 | return ($result === TRUE) ? 'true' : 'false'; |
| 863 | } |
| 864 | elseif (is_string($result) OR $is_key) |
| 865 | { |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 866 | return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 867 | } |
| 868 | elseif (is_scalar($result)) |
| 869 | { |
| 870 | return $result; |
| 871 | } |
| 872 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 873 | |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 874 | // -------------------------------------------------------------------- |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 875 | } |
Derek Jones | 9d653ed | 2010-03-05 09:52:53 -0600 | [diff] [blame] | 876 | // END Javascript Class |
Derek Jones | 811f475 | 2010-03-02 18:13:59 -0600 | [diff] [blame] | 877 | |
| 878 | /* End of file Javascript.php */ |
Andrey Andreev | ad47f94 | 2011-12-25 19:13:48 +0200 | [diff] [blame^] | 879 | /* Location: ./system/libraries/Javascript.php */ |