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