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