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