diff options
Diffstat (limited to 'system/libraries/javascript')
-rw-r--r-- | system/libraries/javascript/Jquery.php | 231 | ||||
-rw-r--r-- | system/libraries/javascript/index.html | 10 |
2 files changed, 154 insertions, 87 deletions
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php index f30d7c639..2bf47957f 100644 --- a/system/libraries/javascript/Jquery.php +++ b/system/libraries/javascript/Jquery.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php /** * CodeIgniter * @@ -24,8 +24,7 @@ * @since Version 1.0 * @filesource */ - -// ------------------------------------------------------------------------ +defined('BASEPATH') OR exit('No direct script access allowed'); /** * Jquery Class @@ -36,17 +35,65 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/javascript.html */ - class CI_Jquery extends CI_Javascript { + /** + * JavaScript directory location + * + * @var string + */ protected $_javascript_folder = 'js'; + + /** + * JQuery code for load + * + * @var array + */ public $jquery_code_for_load = array(); + + /** + * JQuery code for compile + * + * @var array + */ public $jquery_code_for_compile = array(); + + /** + * JQuery corner active flag + * + * @var bool + */ public $jquery_corner_active = FALSE; + + /** + * JQuery table sorter active flag + * + * @var bool + */ public $jquery_table_sorter_active = FALSE; + + /** + * JQuery table sorder pager active + * + * @var bool + */ public $jquery_table_sorter_pager_active = FALSE; + + /** + * JQuery AJAX image + * + * @var string + */ public $jquery_ajax_img = ''; + // -------------------------------------------------------------------- + + /** + * Constructor + * + * @param array $params + * @return void + */ public function __construct($params) { $this->CI =& get_instance(); @@ -57,7 +104,7 @@ class CI_Jquery extends CI_Javascript { $this->script(); } - log_message('debug', "Jquery Class Initialized"); + log_message('debug', 'Jquery Class Initialized'); } // -------------------------------------------------------------------- @@ -103,19 +150,16 @@ class CI_Jquery extends CI_Javascript { * * @param string The element to attach the event to * @param string The code to execute - * @param boolean whether or not to return false + * @param bool whether or not to return false * @return string */ protected function _click($element = 'this', $js = '', $ret_false = TRUE) { - if ( ! is_array($js)) - { - $js = array($js); - } + is_array($js) OR $js = array($js); if ($ret_false) { - $js[] = "return false;"; + $js[] = 'return false;'; } return $this->_add_event($element, $js, 'click'); @@ -183,7 +227,7 @@ class CI_Jquery extends CI_Javascript { */ protected function _hover($element = 'this', $over, $out) { - $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"; + $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"; $this->jquery_code_for_compile[] = $event; @@ -309,11 +353,10 @@ class CI_Jquery extends CI_Javascript { * * Outputs script directly * - * @param string The element to attach the event to - * @param string The code to execute - * @return string + * @param array $array_js = array() + * @return void */ - protected function _output($array_js = '') + protected function _output($array_js = array()) { if ( ! is_array($array_js)) { @@ -322,7 +365,7 @@ class CI_Jquery extends CI_Javascript { foreach ($array_js as $js) { - $this->jquery_code_for_compile[] = "\t$js\n"; + $this->jquery_code_for_compile[] = "\t".$js."\n"; } } @@ -383,13 +426,14 @@ class CI_Jquery extends CI_Javascript { * * Outputs a jQuery addClass event * - * @param string - element + * @param string $element + * @param string $class * @return string */ - protected function _addClass($element = 'this', $class='') + protected function _addClass($element = 'this', $class = '') { $element = $this->_prep_element($element); - return "$({$element}).addClass(\"$class\");"; + return '$('.$element.').addClass("'.$class.'");'; } // -------------------------------------------------------------------- @@ -399,9 +443,10 @@ class CI_Jquery extends CI_Javascript { * * Outputs a jQuery animate event * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function + * @param string $element + * @param array $params + * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds + * @param string $extra * @return string */ protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '') @@ -411,24 +456,24 @@ class CI_Jquery extends CI_Javascript { $animations = "\t\t\t"; - foreach ($params as $param=>$value) + foreach ($params as $param => $value) { - $animations .= $param.': \''.$value.'\', '; + $animations .= $param.": '".$value."', "; } $animations = substr($animations, 0, -2); // remove the last ", " - if ($speed != '') + if ($speed !== '') { $speed = ', '.$speed; } - if ($extra != '') + if ($extra !== '') { $extra = ', '.$extra; } - return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; + return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');'; } // -------------------------------------------------------------------- @@ -448,7 +493,7 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } @@ -473,12 +518,12 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } - return "$({$element}).fadeOut({$speed}{$callback});"; + return '$('.$element.').fadeOut('.$speed.$callback.');'; } // -------------------------------------------------------------------- @@ -498,7 +543,7 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } @@ -513,13 +558,14 @@ class CI_Jquery extends CI_Javascript { * * Outputs a jQuery remove class event * - * @param string - element + * @param string $element + * @param string $class * @return string */ - protected function _removeClass($element = 'this', $class='') + protected function _removeClass($element = 'this', $class = '') { $element = $this->_prep_element($element); - return "$({$element}).removeClass(\"$class\");"; + return '$('.$element.').removeClass("'.$class.'");'; } // -------------------------------------------------------------------- @@ -539,12 +585,12 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } - return "$({$element}).slideUp({$speed}{$callback});"; + return '$('.$element.').slideUp('.$speed.$callback.');'; } // -------------------------------------------------------------------- @@ -564,12 +610,12 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } - return "$({$element}).slideDown({$speed}{$callback});"; + return '$('.$element.').slideDown('.$speed.$callback.');'; } // -------------------------------------------------------------------- @@ -589,12 +635,12 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } - return "$({$element}).slideToggle({$speed}{$callback});"; + return '$('.$element.').slideToggle('.$speed.$callback.');'; } // -------------------------------------------------------------------- @@ -610,7 +656,7 @@ class CI_Jquery extends CI_Javascript { protected function _toggle($element = 'this') { $element = $this->_prep_element($element); - return "$({$element}).toggle();"; + return '$('.$element.').toggle();'; } // -------------------------------------------------------------------- @@ -620,13 +666,14 @@ class CI_Jquery extends CI_Javascript { * * Outputs a jQuery toggle class event * - * @param string - element + * @param string $element + * @param string $class * @return string */ - protected function _toggleClass($element = 'this', $class='') + protected function _toggleClass($element = 'this', $class = '') { $element = $this->_prep_element($element); - return "$({$element}).toggleClass(\"$class\");"; + return '$('.$element.').toggleClass("'.$class.'");'; } // -------------------------------------------------------------------- @@ -646,12 +693,12 @@ class CI_Jquery extends CI_Javascript { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - if ($callback != '') + if ($callback !== '') { $callback = ", function(){\n{$callback}\n}"; } - return "$({$element}).show({$speed}{$callback});"; + return '$('.$element.').show('.$speed.$callback.');'; } // -------------------------------------------------------------------- @@ -674,30 +721,29 @@ class CI_Jquery extends CI_Javascript { $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); // ajaxStart and ajaxStop are better choices here... but this is a stop gap - if ($this->CI->config->item('javascript_ajax_img') == '') + if ($this->CI->config->item('javascript_ajax_img') === '') { - $loading_notifier = "Loading..."; + $loading_notifier = 'Loading...'; } else { - $loading_notifier = '<img src=\''.$this->CI->config->slash_item('base_url').$this->CI->config->item('javascript_ajax_img').'\' alt=\'Loading\' />'; + $loading_notifier = '<img src="'.$this->CI->config->slash_item('base_url').$this->CI->config->item('javascript_ajax_img').'" alt="Loading" />'; } - $updater = "$($container).empty();\n" // anything that was in... get it out - . "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image + $updater = '$('.$container.").empty();\n" // anything that was in... get it out + ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image $request_options = ''; - if ($options != '') + if ($options !== '') { $request_options .= ', {' - . (is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(":", "':'", $options)."'") - . '}'; + .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'") + .'}'; } return $updater."\t\t$($container).load('$controller'$request_options);"; } - // -------------------------------------------------------------------- // Pre-written handy stuff // -------------------------------------------------------------------- @@ -705,18 +751,19 @@ class CI_Jquery extends CI_Javascript { /** * Zebra tables * - * @param string table name - * @param string plugin location + * @param string $class + * @param string $odd + * @param string $hover * @return string */ protected function _zebraTables($class = '', $odd = 'odd', $hover = '') { - $class = ($class != '') ? '.'.$class : ''; - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + $class = ($class !== '') ? '.'.$class : ''; + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; $this->jquery_code_for_compile[] = $zebra; - if ($hover != '') + if ($hover !== '') { $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); } @@ -731,9 +778,9 @@ class CI_Jquery extends CI_Javascript { /** * Corner Plugin * - * http://www.malsup.com/jquery/corner/ - * - * @param string target + * @link http://www.malsup.com/jquery/corner/ + * @param string $element + * @param string $corner_style * @return string */ public function corner($element = '', $corner_style = '') @@ -741,21 +788,23 @@ class CI_Jquery extends CI_Javascript { // may want to make this configurable down the road $corner_location = '/plugins/jquery.corner.js'; - if ($corner_style != '') + if ($corner_style !== '') { $corner_style = '"'.$corner_style.'"'; } - return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; + return '$('.$this->_prep_element($element).').corner('.$corner_style.');'; } // -------------------------------------------------------------------- /** - * modal window + * Modal window * * Load a thickbox modal window * + * @param string $src + * @param bool $relative * @return void */ public function modal($src, $relative = FALSE) @@ -770,6 +819,8 @@ class CI_Jquery extends CI_Javascript { * * Load an Effect library * + * @param string $src + * @param bool $relative * @return void */ public function effect($src, $relative = FALSE) @@ -784,6 +835,8 @@ class CI_Jquery extends CI_Javascript { * * Load a plugin library * + * @param string $src + * @param bool $relative * @return void */ public function plugin($src, $relative = FALSE) @@ -798,12 +851,15 @@ class CI_Jquery extends CI_Javascript { * * Load a user interface library * + * @param string $src + * @param bool $relative * @return void */ public function ui($src, $relative = FALSE) { $this->jquery_code_for_load[] = $this->external($src, $relative); } + // -------------------------------------------------------------------- /** @@ -811,26 +867,27 @@ class CI_Jquery extends CI_Javascript { * * Creates a jQuery sortable * - * @return void + * @param string $element + * @param array $options + * @return string */ public function sortable($element, $options = array()) { - if (count($options) > 0) { $sort_options = array(); foreach ($options as $k=>$v) { - $sort_options[] = "\n\t\t".$k.': '.$v.""; + $sort_options[] = "\n\t\t".$k.': '.$v; } - $sort_options = implode(",", $sort_options); + $sort_options = implode(',', $sort_options); } else { $sort_options = ''; } - return "$(" . $this->_prep_element($element) . ").sortable({".$sort_options."\n\t});"; + return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});"; } // -------------------------------------------------------------------- @@ -844,7 +901,7 @@ class CI_Jquery extends CI_Javascript { */ public function tablesorter($table = '', $options = '') { - $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; + $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n"; } // -------------------------------------------------------------------- @@ -869,7 +926,7 @@ class CI_Jquery extends CI_Javascript { } - $event = "\n\t$(" . $this->_prep_element($element) . ").{$event}(function(){\n\t\t{$js}\n\t});\n"; + $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n"; $this->jquery_code_for_compile[] = $event; return $event; } @@ -882,7 +939,9 @@ class CI_Jquery extends CI_Javascript { * As events are specified, they are stored in an array * This funciton compiles them all for output on a page * - * @return string + * @param string $view_var + * @param bool $script_tags + * @return void */ protected function _compile($view_var = 'script_foot', $script_tags = TRUE) { @@ -898,13 +957,12 @@ class CI_Jquery extends CI_Javascript { // Inline references $script = '$(document).ready(function() {'."\n" - . implode('', $this->jquery_code_for_compile) - . '});'; + .implode('', $this->jquery_code_for_compile) + .'});'; $output = ($script_tags === FALSE) ? $script : $this->inline($script); $this->CI->load->vars(array($view_var => $output)); - } // -------------------------------------------------------------------- @@ -928,14 +986,12 @@ class CI_Jquery extends CI_Javascript { * * A wrapper for writing document.ready() * - * @return string + * @param array $js + * @return void */ protected function _document_ready($js) { - if ( ! is_array($js)) - { - $js = array($js); - } + is_array($js) OR $js = array($js); foreach ($js as $script) { @@ -950,7 +1006,8 @@ class CI_Jquery extends CI_Javascript { * * Outputs the script tag that loads the jquery.js file into an HTML document * - * @param string + * @param string $library_src + * @param bool $relative * @return string */ public function script($library_src = '', $relative = FALSE) @@ -974,7 +1031,7 @@ class CI_Jquery extends CI_Javascript { */ protected function _prep_element($element) { - if ($element != 'this') + if ($element !== 'this') { $element = '"'.$element.'"'; } @@ -998,7 +1055,7 @@ class CI_Jquery extends CI_Javascript { { return '"'.$speed.'"'; } - elseif (preg_match("/[^0-9]/", $speed)) + elseif (preg_match('/[^0-9]/', $speed)) { return ''; } @@ -1009,4 +1066,4 @@ class CI_Jquery extends CI_Javascript { } /* End of file Jquery.php */ -/* Location: ./system/libraries/Jquery.php */ +/* Location: ./system/libraries/Jquery.php */
\ No newline at end of file diff --git a/system/libraries/javascript/index.html b/system/libraries/javascript/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/libraries/javascript/index.html @@ -0,0 +1,10 @@ +<html> +<head> + <title>403 Forbidden</title> +</head> +<body> + +<p>Directory access is forbidden.</p> + +</body> +</html>
\ No newline at end of file |