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