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