/system/libraries/javascript/Jquery.php

https://gitlab.com/lisit1003/TTPHPServer · PHP · 1071 lines · 377 code · 161 blank · 533 comment · 40 complexity · 0c56e303d0981f015f7f97d6f8ac64c9 MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://www.codeigniter.com/user_guide/license.html
  11. * @link http://www.codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. /**
  16. * Jquery Class
  17. *
  18. * @package CodeIgniter
  19. * @subpackage Libraries
  20. * @author ExpressionEngine Dev Team
  21. * @category Loader
  22. * @link http://www.codeigniter.com/user_guide/libraries/javascript.html
  23. */
  24. class CI_Jquery extends CI_Javascript {
  25. var $_javascript_folder = 'js';
  26. var $jquery_code_for_load = array();
  27. var $jquery_code_for_compile = array();
  28. var $jquery_corner_active = FALSE;
  29. var $jquery_table_sorter_active = FALSE;
  30. var $jquery_table_sorter_pager_active = FALSE;
  31. var $jquery_ajax_img = '';
  32. public function __construct($params)
  33. {
  34. $this->CI =& get_instance();
  35. extract($params);
  36. if ($autoload === TRUE)
  37. {
  38. $this->script();
  39. }
  40. log_message('debug', "Jquery Class Initialized");
  41. }
  42. // --------------------------------------------------------------------
  43. // Event Code
  44. // --------------------------------------------------------------------
  45. /**
  46. * Blur
  47. *
  48. * Outputs a jQuery blur event
  49. *
  50. * @access private
  51. * @param string The element to attach the event to
  52. * @param string The code to execute
  53. * @return string
  54. */
  55. function _blur($element = 'this', $js = '')
  56. {
  57. return $this->_add_event($element, $js, 'blur');
  58. }
  59. // --------------------------------------------------------------------
  60. /**
  61. * Change
  62. *
  63. * Outputs a jQuery change event
  64. *
  65. * @access private
  66. * @param string The element to attach the event to
  67. * @param string The code to execute
  68. * @return string
  69. */
  70. function _change($element = 'this', $js = '')
  71. {
  72. return $this->_add_event($element, $js, 'change');
  73. }
  74. // --------------------------------------------------------------------
  75. /**
  76. * Click
  77. *
  78. * Outputs a jQuery click event
  79. *
  80. * @access private
  81. * @param string The element to attach the event to
  82. * @param string The code to execute
  83. * @param boolean whether or not to return false
  84. * @return string
  85. */
  86. function _click($element = 'this', $js = '', $ret_false = TRUE)
  87. {
  88. if ( ! is_array($js))
  89. {
  90. $js = array($js);
  91. }
  92. if ($ret_false)
  93. {
  94. $js[] = "return false;";
  95. }
  96. return $this->_add_event($element, $js, 'click');
  97. }
  98. // --------------------------------------------------------------------
  99. /**
  100. * Double Click
  101. *
  102. * Outputs a jQuery dblclick event
  103. *
  104. * @access private
  105. * @param string The element to attach the event to
  106. * @param string The code to execute
  107. * @return string
  108. */
  109. function _dblclick($element = 'this', $js = '')
  110. {
  111. return $this->_add_event($element, $js, 'dblclick');
  112. }
  113. // --------------------------------------------------------------------
  114. /**
  115. * Error
  116. *
  117. * Outputs a jQuery error event
  118. *
  119. * @access private
  120. * @param string The element to attach the event to
  121. * @param string The code to execute
  122. * @return string
  123. */
  124. function _error($element = 'this', $js = '')
  125. {
  126. return $this->_add_event($element, $js, 'error');
  127. }
  128. // --------------------------------------------------------------------
  129. /**
  130. * Focus
  131. *
  132. * Outputs a jQuery focus event
  133. *
  134. * @access private
  135. * @param string The element to attach the event to
  136. * @param string The code to execute
  137. * @return string
  138. */
  139. function _focus($element = 'this', $js = '')
  140. {
  141. return $this->_add_event($element, $js, 'focus');
  142. }
  143. // --------------------------------------------------------------------
  144. /**
  145. * Hover
  146. *
  147. * Outputs a jQuery hover event
  148. *
  149. * @access private
  150. * @param string - element
  151. * @param string - Javascript code for mouse over
  152. * @param string - Javascript code for mouse out
  153. * @return string
  154. */
  155. function _hover($element = 'this', $over, $out)
  156. {
  157. $event = "\n\t$(" . $this->_prep_element($element) . ").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n";
  158. $this->jquery_code_for_compile[] = $event;
  159. return $event;
  160. }
  161. // --------------------------------------------------------------------
  162. /**
  163. * Keydown
  164. *
  165. * Outputs a jQuery keydown event
  166. *
  167. * @access private
  168. * @param string The element to attach the event to
  169. * @param string The code to execute
  170. * @return string
  171. */
  172. function _keydown($element = 'this', $js = '')
  173. {
  174. return $this->_add_event($element, $js, 'keydown');
  175. }
  176. // --------------------------------------------------------------------
  177. /**
  178. * Keyup
  179. *
  180. * Outputs a jQuery keydown event
  181. *
  182. * @access private
  183. * @param string The element to attach the event to
  184. * @param string The code to execute
  185. * @return string
  186. */
  187. function _keyup($element = 'this', $js = '')
  188. {
  189. return $this->_add_event($element, $js, 'keyup');
  190. }
  191. // --------------------------------------------------------------------
  192. /**
  193. * Load
  194. *
  195. * Outputs a jQuery load event
  196. *
  197. * @access private
  198. * @param string The element to attach the event to
  199. * @param string The code to execute
  200. * @return string
  201. */
  202. function _load($element = 'this', $js = '')
  203. {
  204. return $this->_add_event($element, $js, 'load');
  205. }
  206. // --------------------------------------------------------------------
  207. /**
  208. * Mousedown
  209. *
  210. * Outputs a jQuery mousedown event
  211. *
  212. * @access private
  213. * @param string The element to attach the event to
  214. * @param string The code to execute
  215. * @return string
  216. */
  217. function _mousedown($element = 'this', $js = '')
  218. {
  219. return $this->_add_event($element, $js, 'mousedown');
  220. }
  221. // --------------------------------------------------------------------
  222. /**
  223. * Mouse Out
  224. *
  225. * Outputs a jQuery mouseout event
  226. *
  227. * @access private
  228. * @param string The element to attach the event to
  229. * @param string The code to execute
  230. * @return string
  231. */
  232. function _mouseout($element = 'this', $js = '')
  233. {
  234. return $this->_add_event($element, $js, 'mouseout');
  235. }
  236. // --------------------------------------------------------------------
  237. /**
  238. * Mouse Over
  239. *
  240. * Outputs a jQuery mouseover event
  241. *
  242. * @access private
  243. * @param string The element to attach the event to
  244. * @param string The code to execute
  245. * @return string
  246. */
  247. function _mouseover($element = 'this', $js = '')
  248. {
  249. return $this->_add_event($element, $js, 'mouseover');
  250. }
  251. // --------------------------------------------------------------------
  252. /**
  253. * Mouseup
  254. *
  255. * Outputs a jQuery mouseup event
  256. *
  257. * @access private
  258. * @param string The element to attach the event to
  259. * @param string The code to execute
  260. * @return string
  261. */
  262. function _mouseup($element = 'this', $js = '')
  263. {
  264. return $this->_add_event($element, $js, 'mouseup');
  265. }
  266. // --------------------------------------------------------------------
  267. /**
  268. * Output
  269. *
  270. * Outputs script directly
  271. *
  272. * @access private
  273. * @param string The element to attach the event to
  274. * @param string The code to execute
  275. * @return string
  276. */
  277. function _output($array_js = '')
  278. {
  279. if ( ! is_array($array_js))
  280. {
  281. $array_js = array($array_js);
  282. }
  283. foreach ($array_js as $js)
  284. {
  285. $this->jquery_code_for_compile[] = "\t$js\n";
  286. }
  287. }
  288. // --------------------------------------------------------------------
  289. /**
  290. * Resize
  291. *
  292. * Outputs a jQuery resize event
  293. *
  294. * @access private
  295. * @param string The element to attach the event to
  296. * @param string The code to execute
  297. * @return string
  298. */
  299. function _resize($element = 'this', $js = '')
  300. {
  301. return $this->_add_event($element, $js, 'resize');
  302. }
  303. // --------------------------------------------------------------------
  304. /**
  305. * Scroll
  306. *
  307. * Outputs a jQuery scroll event
  308. *
  309. * @access private
  310. * @param string The element to attach the event to
  311. * @param string The code to execute
  312. * @return string
  313. */
  314. function _scroll($element = 'this', $js = '')
  315. {
  316. return $this->_add_event($element, $js, 'scroll');
  317. }
  318. // --------------------------------------------------------------------
  319. /**
  320. * Unload
  321. *
  322. * Outputs a jQuery unload event
  323. *
  324. * @access private
  325. * @param string The element to attach the event to
  326. * @param string The code to execute
  327. * @return string
  328. */
  329. function _unload($element = 'this', $js = '')
  330. {
  331. return $this->_add_event($element, $js, 'unload');
  332. }
  333. // --------------------------------------------------------------------
  334. // Effects
  335. // --------------------------------------------------------------------
  336. /**
  337. * Add Class
  338. *
  339. * Outputs a jQuery addClass event
  340. *
  341. * @access private
  342. * @param string - element
  343. * @return string
  344. */
  345. function _addClass($element = 'this', $class='')
  346. {
  347. $element = $this->_prep_element($element);
  348. $str = "$({$element}).addClass(\"$class\");";
  349. return $str;
  350. }
  351. // --------------------------------------------------------------------
  352. /**
  353. * Animate
  354. *
  355. * Outputs a jQuery animate event
  356. *
  357. * @access private
  358. * @param string - element
  359. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  360. * @param string - Javascript callback function
  361. * @return string
  362. */
  363. function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
  364. {
  365. $element = $this->_prep_element($element);
  366. $speed = $this->_validate_speed($speed);
  367. $animations = "\t\t\t";
  368. foreach ($params as $param=>$value)
  369. {
  370. $animations .= $param.': \''.$value.'\', ';
  371. }
  372. $animations = substr($animations, 0, -2); // remove the last ", "
  373. if ($speed != '')
  374. {
  375. $speed = ', '.$speed;
  376. }
  377. if ($extra != '')
  378. {
  379. $extra = ', '.$extra;
  380. }
  381. $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");";
  382. return $str;
  383. }
  384. // --------------------------------------------------------------------
  385. /**
  386. * Fade In
  387. *
  388. * Outputs a jQuery hide event
  389. *
  390. * @access private
  391. * @param string - element
  392. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  393. * @param string - Javascript callback function
  394. * @return string
  395. */
  396. function _fadeIn($element = 'this', $speed = '', $callback = '')
  397. {
  398. $element = $this->_prep_element($element);
  399. $speed = $this->_validate_speed($speed);
  400. if ($callback != '')
  401. {
  402. $callback = ", function(){\n{$callback}\n}";
  403. }
  404. $str = "$({$element}).fadeIn({$speed}{$callback});";
  405. return $str;
  406. }
  407. // --------------------------------------------------------------------
  408. /**
  409. * Fade Out
  410. *
  411. * Outputs a jQuery hide event
  412. *
  413. * @access private
  414. * @param string - element
  415. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  416. * @param string - Javascript callback function
  417. * @return string
  418. */
  419. function _fadeOut($element = 'this', $speed = '', $callback = '')
  420. {
  421. $element = $this->_prep_element($element);
  422. $speed = $this->_validate_speed($speed);
  423. if ($callback != '')
  424. {
  425. $callback = ", function(){\n{$callback}\n}";
  426. }
  427. $str = "$({$element}).fadeOut({$speed}{$callback});";
  428. return $str;
  429. }
  430. // --------------------------------------------------------------------
  431. /**
  432. * Hide
  433. *
  434. * Outputs a jQuery hide action
  435. *
  436. * @access private
  437. * @param string - element
  438. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  439. * @param string - Javascript callback function
  440. * @return string
  441. */
  442. function _hide($element = 'this', $speed = '', $callback = '')
  443. {
  444. $element = $this->_prep_element($element);
  445. $speed = $this->_validate_speed($speed);
  446. if ($callback != '')
  447. {
  448. $callback = ", function(){\n{$callback}\n}";
  449. }
  450. $str = "$({$element}).hide({$speed}{$callback});";
  451. return $str;
  452. }
  453. // --------------------------------------------------------------------
  454. /**
  455. * Remove Class
  456. *
  457. * Outputs a jQuery remove class event
  458. *
  459. * @access private
  460. * @param string - element
  461. * @return string
  462. */
  463. function _removeClass($element = 'this', $class='')
  464. {
  465. $element = $this->_prep_element($element);
  466. $str = "$({$element}).removeClass(\"$class\");";
  467. return $str;
  468. }
  469. // --------------------------------------------------------------------
  470. /**
  471. * Slide Up
  472. *
  473. * Outputs a jQuery slideUp event
  474. *
  475. * @access private
  476. * @param string - element
  477. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  478. * @param string - Javascript callback function
  479. * @return string
  480. */
  481. function _slideUp($element = 'this', $speed = '', $callback = '')
  482. {
  483. $element = $this->_prep_element($element);
  484. $speed = $this->_validate_speed($speed);
  485. if ($callback != '')
  486. {
  487. $callback = ", function(){\n{$callback}\n}";
  488. }
  489. $str = "$({$element}).slideUp({$speed}{$callback});";
  490. return $str;
  491. }
  492. // --------------------------------------------------------------------
  493. /**
  494. * Slide Down
  495. *
  496. * Outputs a jQuery slideDown event
  497. *
  498. * @access private
  499. * @param string - element
  500. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  501. * @param string - Javascript callback function
  502. * @return string
  503. */
  504. function _slideDown($element = 'this', $speed = '', $callback = '')
  505. {
  506. $element = $this->_prep_element($element);
  507. $speed = $this->_validate_speed($speed);
  508. if ($callback != '')
  509. {
  510. $callback = ", function(){\n{$callback}\n}";
  511. }
  512. $str = "$({$element}).slideDown({$speed}{$callback});";
  513. return $str;
  514. }
  515. // --------------------------------------------------------------------
  516. /**
  517. * Slide Toggle
  518. *
  519. * Outputs a jQuery slideToggle event
  520. *
  521. * @access public
  522. * @param string - element
  523. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  524. * @param string - Javascript callback function
  525. * @return string
  526. */
  527. function _slideToggle($element = 'this', $speed = '', $callback = '')
  528. {
  529. $element = $this->_prep_element($element);
  530. $speed = $this->_validate_speed($speed);
  531. if ($callback != '')
  532. {
  533. $callback = ", function(){\n{$callback}\n}";
  534. }
  535. $str = "$({$element}).slideToggle({$speed}{$callback});";
  536. return $str;
  537. }
  538. // --------------------------------------------------------------------
  539. /**
  540. * Toggle
  541. *
  542. * Outputs a jQuery toggle event
  543. *
  544. * @access private
  545. * @param string - element
  546. * @return string
  547. */
  548. function _toggle($element = 'this')
  549. {
  550. $element = $this->_prep_element($element);
  551. $str = "$({$element}).toggle();";
  552. return $str;
  553. }
  554. // --------------------------------------------------------------------
  555. /**
  556. * Toggle Class
  557. *
  558. * Outputs a jQuery toggle class event
  559. *
  560. * @access private
  561. * @param string - element
  562. * @return string
  563. */
  564. function _toggleClass($element = 'this', $class='')
  565. {
  566. $element = $this->_prep_element($element);
  567. $str = "$({$element}).toggleClass(\"$class\");";
  568. return $str;
  569. }
  570. // --------------------------------------------------------------------
  571. /**
  572. * Show
  573. *
  574. * Outputs a jQuery show event
  575. *
  576. * @access private
  577. * @param string - element
  578. * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
  579. * @param string - Javascript callback function
  580. * @return string
  581. */
  582. function _show($element = 'this', $speed = '', $callback = '')
  583. {
  584. $element = $this->_prep_element($element);
  585. $speed = $this->_validate_speed($speed);
  586. if ($callback != '')
  587. {
  588. $callback = ", function(){\n{$callback}\n}";
  589. }
  590. $str = "$({$element}).show({$speed}{$callback});";
  591. return $str;
  592. }
  593. // --------------------------------------------------------------------
  594. /**
  595. * Updater
  596. *
  597. * An Ajax call that populates the designated DOM node with
  598. * returned content
  599. *
  600. * @access private
  601. * @param string The element to attach the event to
  602. * @param string the controller to run the call against
  603. * @param string optional parameters
  604. * @return string
  605. */
  606. function _updater($container = 'this', $controller, $options = '')
  607. {
  608. $container = $this->_prep_element($container);
  609. $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller);
  610. // ajaxStart and ajaxStop are better choices here... but this is a stop gap
  611. if ($this->CI->config->item('javascript_ajax_img') == '')
  612. {
  613. $loading_notifier = "Loading...";
  614. }
  615. else
  616. {
  617. $loading_notifier = '<img src=\'' . $this->CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />';
  618. }
  619. $updater = "$($container).empty();\n"; // anything that was in... get it out
  620. $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image
  621. $request_options = '';
  622. if ($options != '')
  623. {
  624. $request_options .= ", {";
  625. $request_options .= (is_array($options)) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'";
  626. $request_options .= "}";
  627. }
  628. $updater .= "\t\t$($container).load('$controller'$request_options);";
  629. return $updater;
  630. }
  631. // --------------------------------------------------------------------
  632. // Pre-written handy stuff
  633. // --------------------------------------------------------------------
  634. /**
  635. * Zebra tables
  636. *
  637. * @access private
  638. * @param string table name
  639. * @param string plugin location
  640. * @return string
  641. */
  642. function _zebraTables($class = '', $odd = 'odd', $hover = '')
  643. {
  644. $class = ($class != '') ? '.'.$class : '';
  645. $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");";
  646. $this->jquery_code_for_compile[] = $zebra;
  647. if ($hover != '')
  648. {
  649. $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');");
  650. }
  651. return $zebra;
  652. }
  653. // --------------------------------------------------------------------
  654. // Plugins
  655. // --------------------------------------------------------------------
  656. /**
  657. * Corner Plugin
  658. *
  659. * http://www.malsup.com/jquery/corner/
  660. *
  661. * @access public
  662. * @param string target
  663. * @return string
  664. */
  665. function corner($element = '', $corner_style = '')
  666. {
  667. // may want to make this configurable down the road
  668. $corner_location = '/plugins/jquery.corner.js';
  669. if ($corner_style != '')
  670. {
  671. $corner_style = '"'.$corner_style.'"';
  672. }
  673. return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");";
  674. }
  675. // --------------------------------------------------------------------
  676. /**
  677. * modal window
  678. *
  679. * Load a thickbox modal window
  680. *
  681. * @access public
  682. * @return void
  683. */
  684. function modal($src, $relative = FALSE)
  685. {
  686. $this->jquery_code_for_load[] = $this->external($src, $relative);
  687. }
  688. // --------------------------------------------------------------------
  689. /**
  690. * Effect
  691. *
  692. * Load an Effect library
  693. *
  694. * @access public
  695. * @return void
  696. */
  697. function effect($src, $relative = FALSE)
  698. {
  699. $this->jquery_code_for_load[] = $this->external($src, $relative);
  700. }
  701. // --------------------------------------------------------------------
  702. /**
  703. * Plugin
  704. *
  705. * Load a plugin library
  706. *
  707. * @access public
  708. * @return void
  709. */
  710. function plugin($src, $relative = FALSE)
  711. {
  712. $this->jquery_code_for_load[] = $this->external($src, $relative);
  713. }
  714. // --------------------------------------------------------------------
  715. /**
  716. * UI
  717. *
  718. * Load a user interface library
  719. *
  720. * @access public
  721. * @return void
  722. */
  723. function ui($src, $relative = FALSE)
  724. {
  725. $this->jquery_code_for_load[] = $this->external($src, $relative);
  726. }
  727. // --------------------------------------------------------------------
  728. /**
  729. * Sortable
  730. *
  731. * Creates a jQuery sortable
  732. *
  733. * @access public
  734. * @return void
  735. */
  736. function sortable($element, $options = array())
  737. {
  738. if (count($options) > 0)
  739. {
  740. $sort_options = array();
  741. foreach ($options as $k=>$v)
  742. {
  743. $sort_options[] = "\n\t\t".$k.': '.$v."";
  744. }
  745. $sort_options = implode(",", $sort_options);
  746. }
  747. else
  748. {
  749. $sort_options = '';
  750. }
  751. return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});";
  752. }
  753. // --------------------------------------------------------------------
  754. /**
  755. * Table Sorter Plugin
  756. *
  757. * @access public
  758. * @param string table name
  759. * @param string plugin location
  760. * @return string
  761. */
  762. function tablesorter($table = '', $options = '')
  763. {
  764. $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n";
  765. }
  766. // --------------------------------------------------------------------
  767. // Class functions
  768. // --------------------------------------------------------------------
  769. /**
  770. * Add Event
  771. *
  772. * Constructs the syntax for an event, and adds to into the array for compilation
  773. *
  774. * @access private
  775. * @param string The element to attach the event to
  776. * @param string The code to execute
  777. * @param string The event to pass
  778. * @return string
  779. */
  780. function _add_event($element, $js, $event)
  781. {
  782. if (is_array($js))
  783. {
  784. $js = implode("\n\t\t", $js);
  785. }
  786. $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n";
  787. $this->jquery_code_for_compile[] = $event;
  788. return $event;
  789. }
  790. // --------------------------------------------------------------------
  791. /**
  792. * Compile
  793. *
  794. * As events are specified, they are stored in an array
  795. * This funciton compiles them all for output on a page
  796. *
  797. * @access private
  798. * @return string
  799. */
  800. function _compile($view_var = 'script_foot', $script_tags = TRUE)
  801. {
  802. // External references
  803. $external_scripts = implode('', $this->jquery_code_for_load);
  804. $this->CI->load->vars(array('library_src' => $external_scripts));
  805. if (count($this->jquery_code_for_compile) == 0 )
  806. {
  807. // no inline references, let's just return
  808. return;
  809. }
  810. // Inline references
  811. $script = '$(document).ready(function() {' . "\n";
  812. $script .= implode('', $this->jquery_code_for_compile);
  813. $script .= '});';
  814. $output = ($script_tags === FALSE) ? $script : $this->inline($script);
  815. $this->CI->load->vars(array($view_var => $output));
  816. }
  817. // --------------------------------------------------------------------
  818. /**
  819. * Clear Compile
  820. *
  821. * Clears the array of script events collected for output
  822. *
  823. * @access public
  824. * @return void
  825. */
  826. function _clear_compile()
  827. {
  828. $this->jquery_code_for_compile = array();
  829. }
  830. // --------------------------------------------------------------------
  831. /**
  832. * Document Ready
  833. *
  834. * A wrapper for writing document.ready()
  835. *
  836. * @access private
  837. * @return string
  838. */
  839. function _document_ready($js)
  840. {
  841. if ( ! is_array($js))
  842. {
  843. $js = array ($js);
  844. }
  845. foreach ($js as $script)
  846. {
  847. $this->jquery_code_for_compile[] = $script;
  848. }
  849. }
  850. // --------------------------------------------------------------------
  851. /**
  852. * Script Tag
  853. *
  854. * Outputs the script tag that loads the jquery.js file into an HTML document
  855. *
  856. * @access public
  857. * @param string
  858. * @return string
  859. */
  860. function script($library_src = '', $relative = FALSE)
  861. {
  862. $library_src = $this->external($library_src, $relative);
  863. $this->jquery_code_for_load[] = $library_src;
  864. return $library_src;
  865. }
  866. // --------------------------------------------------------------------
  867. /**
  868. * Prep Element
  869. *
  870. * Puts HTML element in quotes for use in jQuery code
  871. * unless the supplied element is the Javascript 'this'
  872. * object, in which case no quotes are added
  873. *
  874. * @access public
  875. * @param string
  876. * @return string
  877. */
  878. function _prep_element($element)
  879. {
  880. if ($element != 'this')
  881. {
  882. $element = '"'.$element.'"';
  883. }
  884. return $element;
  885. }
  886. // --------------------------------------------------------------------
  887. /**
  888. * Validate Speed
  889. *
  890. * Ensures the speed parameter is valid for jQuery
  891. *
  892. * @access private
  893. * @param string
  894. * @return string
  895. */
  896. function _validate_speed($speed)
  897. {
  898. if (in_array($speed, array('slow', 'normal', 'fast')))
  899. {
  900. $speed = '"'.$speed.'"';
  901. }
  902. elseif (preg_match("/[^0-9]/", $speed))
  903. {
  904. $speed = '';
  905. }
  906. return $speed;
  907. }
  908. }
  909. /* End of file Jquery.php */
  910. /* Location: ./system/libraries/Jquery.php */