From 5bc6bcfce17ddcb8000056b67db7f91ca6f77004 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 18 Apr 2009 22:00:58 -0400 Subject: [PATCH 1/5] Adding slider to base engine and jquery engine. Tests added. --- cake/libs/view/helpers/jquery_engine.php | 18 +++++++++++++++ cake/libs/view/helpers/js.php | 22 +++++++++++++++++++ .../libs/view/helpers/jquery_engine.test.php | 18 +++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index 6271736a6..c3e0ee9da 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -47,6 +47,10 @@ class JqueryEngineHelper extends JsBaseEngineHelper { 'drop' => array( 'leave' => 'out', 'hover' => 'over' + ), + 'slider' => array( + 'complete' => 'stop', + 'direction' => 'orientation' ) ); /** @@ -218,5 +222,19 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $template = '%s.droppable({%s});'; return $this->_methodTemplate('drop', $template, $options, $callbacks); } +/** + * Create a Slider element + * + * Requires both Ui.Core and Ui.Slider to be loaded. + * + * @param array $options Array of options for the droppable element. + * @return string Completed Slider script. + * @see JsHelper::slider() for options list. + **/ + function slider($options = array()) { + $callbacks = array('start', 'change', 'slide', 'stop'); + $template = '%s.slider({%s});'; + return $this->_methodTemplate('slider', $template, $options, $callbacks); + } } ?> \ No newline at end of file diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 61453e39d..e8bbe7faf 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -650,6 +650,28 @@ class JsBaseEngineHelper extends AppHelper { function sortable() { trigger_error(sprintf(__('%s does not have sortable() implemented', true), get_class($this)), E_USER_WARNING); } +/** + * Create a slider control element. + * + * ### Options + * + * - handle - The handle used in sliding + * - direction - The direction of the slider either 'vertical' or 'horizontal' + * - min - The min value for the slider. + * - max - The max value for the slider. + * - step - The number of steps or ticks the slider will have. + * - value - The initial offset of the slider + * + * ### Events + * + * - change - Fired when the slider's value is updated + * - complete - Fired when the user stops sliding the handle + * + * @return string Completed slider script + **/ + function slider() { + trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING); + } /** * Parse an options assoc array into an Javascript object literal. * Similar to object() but treats any non-integer value as a string, diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 6e50ad356..e12a6a4ef 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -217,5 +217,23 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $expected = '$("#element").droppable({accept:".items", drop:onDrop, out:onExit, over:onHover});'; $this->assertEqual($result, $expected); } +/** + * test slider generation + * + * @return void + **/ + function testSlider() { + $this->Jquery->get('#element'); + $result = $this->Jquery->slider(array( + 'complete' => 'onComplete', + 'change' => 'onChange', + 'min' => 0, + 'max' => 10, + 'value' => 2, + 'direction' => 'vertical' + )); + $expected = '$("#element").slider({change:onChange, max:10, min:0, orientation:"vertical", stop:onComplete, value:2});'; + $this->assertEqual($result, $expected); + } } ?> \ No newline at end of file From b7845657a88f5a3d14444905da2fedfaba18db9e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 18 Apr 2009 22:44:47 -0400 Subject: [PATCH 2/5] Adding slider to Mootools. Test cases added. --- cake/libs/view/helpers/js.php | 4 +-- cake/libs/view/helpers/mootools_engine.php | 33 +++++++++++++++++++ .../view/helpers/mootools_engine.test.php | 29 ++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index e8bbe7faf..602985bae 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -655,12 +655,12 @@ class JsBaseEngineHelper extends AppHelper { * * ### Options * - * - handle - The handle used in sliding + * - handle - The id of the element used in sliding. * - direction - The direction of the slider either 'vertical' or 'horizontal' * - min - The min value for the slider. * - max - The max value for the slider. * - step - The number of steps or ticks the slider will have. - * - value - The initial offset of the slider + * - value - The initial offset of the slider. * * ### Events * diff --git a/cake/libs/view/helpers/mootools_engine.php b/cake/libs/view/helpers/mootools_engine.php index d271c7508..7b7059c81 100644 --- a/cake/libs/view/helpers/mootools_engine.php +++ b/cake/libs/view/helpers/mootools_engine.php @@ -59,6 +59,12 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { 'drop' => 'onDrop', 'hover' => 'onEnter', 'leave' => 'onLeave', + ), + 'slider' => array( + 'complete' => 'onComplete', + 'change' => 'onChange', + 'direction' => 'mode', + 'step' => 'steps' ) ); /** @@ -270,6 +276,33 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $this->selection = $options['droppables']; return $out; } +/** + * Create a slider control + * + * Requires `Slider` from MootoolsMore + * + * @param array $options Array of options for the slider. + * @return string Completed slider script. + * @see JsHelper::slider() for options list. + **/ + function slider($options = array()) { + $slider = $this->selection; + $this->get($options['handle']); + unset($options['handle']); + $callbacks = array('onStart', 'onTick', 'onChange', 'onComplete'); + $options = $this->_mapOptions('slider', $options); + if (isset($options['min']) && isset($options['max'])) { + $options['range'] = array($options['min'], $options['max']); + unset($options['min'], $options['max']); + } + $optionString = $this->_parseOptions($options, $callbacks); + if (!empty($optionString)) { + $optionString = ', {' . $optionString . '}'; + } + $out = 'var jsSlider = new Slider(' . $slider . ', ' . $this->selection . $optionString . ');'; + $this->selection = $slider; + return $out; + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php index 8c24d8736..44b27af7a 100644 --- a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php @@ -250,5 +250,34 @@ class MooEngineHelperTestCase extends CakeTestCase { $this->assertEqual($result, $expected); $this->assertEqual($this->Moo->selection, '$("drop-me")'); } +/** + * test slider generation + * + * @return void + **/ + function testSlider() { + $this->Moo->get('#slider'); + $result = $this->Moo->slider(array( + 'handle' => '#my-handle', + 'complete' => 'onComplete', + 'change' => 'onChange', + 'direction' => 'horizontal', + )); + $expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete});'; + $this->assertEqual($result, $expected); + $this->assertEqual($this->Moo->selection, '$("slider")'); + + $this->Moo->get('#slider'); + $result = $this->Moo->slider(array( + 'handle' => '#my-handle', + 'complete' => 'onComplete', + 'change' => 'onChange', + 'direction' => 'horizontal', + 'min' => 10, + 'max' => 40 + )); + $expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete, range:[10,40]});'; + $this->assertEqual($result, $expected); + } } ?> \ No newline at end of file From dd01dda0b4809aec642e0b6871f251ed34ee75e3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Apr 2009 09:18:45 -0700 Subject: [PATCH 3/5] Adding slider to prototype --- cake/libs/view/helpers/prototype_engine.php | 36 ++++++++++++++++++- .../view/helpers/prototype_engine.test.php | 18 ++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php index 5e415d9db..eb6799928 100644 --- a/cake/libs/view/helpers/prototype_engine.php +++ b/cake/libs/view/helpers/prototype_engine.php @@ -59,6 +59,12 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { 'hover' => 'onHover', 'drop' => 'onDrop', 'hoverClass' => 'hoverclass', + ), + 'slider' => array( + 'direction' => 'axis', + 'change' => 'onSlide', + 'complete' => 'onChange', + 'value' => 'sliderValue', ) ); /** @@ -239,7 +245,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { * #### Note: Requires scriptaculous to be loaded. * * @param array $options Array of options for the droppable. - * @return string Completed draggable script. + * @return string Completed droppable script. * @see JsHelper::droppable() for options list. **/ function drop($options = array()) { @@ -251,5 +257,33 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return 'Droppables.add(' . $this->selection . $options . ');'; } +/** + * Creates a slider control widget. + * + * ### Note: Requires scriptaculous to be loaded. + * + * @param array $options Array of options for the slider. + * @return string Completed slider script. + * @see JsHelper::slider() for options list. + **/ + function slider($options = array()) { + $slider = $this->selection; + $this->get($options['handle']); + unset($options['handle']); + + $callbacks = array('onSlide', 'onChange'); + $options = $this->_mapOptions('slider', $options); + if (isset($options['min']) && isset($options['max'])) { + $options['range'] = array($options['min'], $options['max']); + unset($options['min'], $options['max']); + } + $optionString = $this->_parseOptions($options, $callbacks); + if (!empty($optionString)) { + $optionString = ', {' . $optionString . '}'; + } + $out = 'var jsSlider = new Control.Slider(' . $this->selection . ', ' . $slider . $optionString . ');'; + $this->selection = $slider; + return $out; + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php index ab5ed6746..0ed044e03 100644 --- a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -256,5 +256,23 @@ class PrototypeEngineHelperTestCase extends CakeTestCase { $expected = 'Droppables.add($("element"), {accept:".drag-me", onDrop:onDrop, onHover:onHover});'; $this->assertEqual($result, $expected); } +/** + * ensure that slider() method behaves properly + * + * @return void + **/ + function testSlider() { + $this->Proto->get('#element'); + $result = $this->Proto->slider(array( + 'handle' => '#handle', + 'direction' => 'horizontal', + 'change' => 'onChange', + 'complete' => 'onComplete', + 'value' => 4, + )); + $expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {axis:"horizontal", onChange:onComplete, onSlide:onChange, sliderValue:4});'; + $this->assertEqual($result, $expected); + + } } ?> \ No newline at end of file From 91edcacec2d3d582cb5536adf8a76491aa428ce0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Apr 2009 09:31:52 -0700 Subject: [PATCH 4/5] Adding newlines between methods. --- cake/libs/view/helpers/jquery_engine.php | 11 +++++++++++ cake/libs/view/helpers/mootools_engine.php | 10 ++++++++++ cake/libs/view/helpers/prototype_engine.php | 12 +++++++++++- .../libs/view/helpers/prototype_engine.test.php | 1 - 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index c3e0ee9da..071947463 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -53,6 +53,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { 'direction' => 'orientation' ) ); + /** * Helper function to wrap repetitive simple method templating. * @@ -69,6 +70,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $options = $this->_parseOptions($options, $callbacks); return sprintf($template, $this->selection, $options); } + /** * Create javascript selector for a CSS rule * @@ -83,6 +85,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } return $this; } + /** * Add an event to the script cache. Operates on the currently selected elements. * @@ -109,6 +112,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback); } + /** * Create a domReady event. This is a special event in many libraries * @@ -118,6 +122,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { function domReady($functionBody) { return $this->get('document')->event('ready', $functionBody, array('stop' => false)); } + /** * Create an iteration over the current selection result. * @@ -128,6 +133,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { function each($callback) { return $this->selection . '.each(function () {' . $callback . '});'; } + /** * Trigger an Effect. * @@ -155,6 +161,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } return $this->selection . $effect; } + /** * Create an $.ajax() call. * @@ -179,6 +186,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $options = $this->_parseOptions($options, $callbacks); return '$.ajax({' . $options .'});'; } + /** * Create a sortable element. * @@ -194,6 +202,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $template = '%s.sortable({%s});'; return $this->_methodTemplate('sortable', $template, $options, $callbacks); } + /** * Create a Draggable element * @@ -208,6 +217,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $template = '%s.draggable({%s});'; return $this->_methodTemplate('drag', $template, $options, $callbacks); } + /** * Create a Droppable element * @@ -222,6 +232,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $template = '%s.droppable({%s});'; return $this->_methodTemplate('drop', $template, $options, $callbacks); } + /** * Create a Slider element * diff --git a/cake/libs/view/helpers/mootools_engine.php b/cake/libs/view/helpers/mootools_engine.php index 7b7059c81..51784f8f0 100644 --- a/cake/libs/view/helpers/mootools_engine.php +++ b/cake/libs/view/helpers/mootools_engine.php @@ -67,6 +67,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { 'step' => 'steps' ) ); + /** * Create javascript selector for a CSS rule * @@ -85,6 +86,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $this->selection = '$$("' . $selector . '")'; return $this; } + /** * Add an event to the script cache. Operates on the currently selected elements. * @@ -112,6 +114,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $out = $this->selection . ".addEvent(\"{$type}\", $callback);"; return $out; } + /** * Create a domReady event. This is a special event in many libraries * @@ -122,6 +125,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $this->selection = 'window'; return $this->event('domready', $functionBody, array('stop' => false)); } + /** * Create an iteration over the current selection result. * @@ -132,6 +136,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { function each($callback) { return $this->selection . '.each(function (item, index) {' . $callback . '});'; } + /** * Trigger an Effect. * @@ -171,6 +176,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { } return $this->selection . '.' . $effect . ';'; } + /** * Create an new Request. * @@ -207,6 +213,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $options = $this->_parseOptions($options, $callbacks); return "var jsRequest = new Request$type({{$options}}).send($data);"; } + /** * Create a sortable element. * @@ -222,6 +229,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $options = $this->_parseOptions($options, $callbacks); return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});'; } + /** * Create a Draggable element. * @@ -237,6 +245,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $options = $this->_parseOptions($options, $callbacks); return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});'; } + /** * Create a Droppable element. * @@ -276,6 +285,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $this->selection = $options['droppables']; return $out; } + /** * Create a slider control * diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php index eb6799928..49c335c85 100644 --- a/cake/libs/view/helpers/prototype_engine.php +++ b/cake/libs/view/helpers/prototype_engine.php @@ -67,6 +67,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { 'value' => 'sliderValue', ) ); + /** * Create javascript selector for a CSS rule * @@ -85,6 +86,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { $this->selection = '$$("' . $selector . '")'; return $this; } + /** * Add an event to the script cache. Operates on the currently selected elements. * @@ -112,6 +114,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { $out = $this->selection . ".observe(\"{$type}\", $callback);"; return $out; } + /** * Create a domReady event. This is a special event in many libraries * @@ -122,6 +125,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { $this->selection = 'document'; return $this->event('dom:loaded', $functionBody, array('stop' => false)); } + /** * Create an iteration over the current selection result. * @@ -132,6 +136,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { function each($callback) { return $this->selection . '.each(function (item, index) {' . $callback . '});'; } + /** * Trigger an Effect. * @@ -176,6 +181,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return $effect; } + /** * Create an Ajax or Ajax.Updater call. * @@ -203,6 +209,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return "var jsRequest = new Ajax$type($url$options);"; } + /** * Create a sortable element. * @@ -221,6 +228,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return 'var jsSortable = Sortable.create(' . $this->selection . $options . ');'; } + /** * Create a Draggable element. * @@ -239,6 +247,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return 'var jsDrag = new Draggable(' . $this->selection . $options . ');'; } + /** * Create a Droppable element. * @@ -257,6 +266,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } return 'Droppables.add(' . $this->selection . $options . ');'; } + /** * Creates a slider control widget. * @@ -283,7 +293,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { } $out = 'var jsSlider = new Control.Slider(' . $this->selection . ', ' . $slider . $optionString . ');'; $this->selection = $slider; - return $out; + return $out; } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php index 0ed044e03..b8c838d65 100644 --- a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -272,7 +272,6 @@ class PrototypeEngineHelperTestCase extends CakeTestCase { )); $expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {axis:"horizontal", onChange:onComplete, onSlide:onChange, sliderValue:4});'; $this->assertEqual($result, $expected); - } } ?> \ No newline at end of file From 005cc1b338f3f2e6fe4016c4701bd8a552214791 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 23 Apr 2009 22:58:42 -0700 Subject: [PATCH 5/5] Removing old JsHelperObject --- cake/libs/view/helpers/js.php | 179 ---------------------------------- 1 file changed, 179 deletions(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 602985bae..fbd2849ea 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -734,183 +734,4 @@ class JsBaseEngineHelper extends AppHelper { return $out; } } - - -class JsHelperObject { - var $__parent = null; - - var $id = null; - - var $pattern = null; - - var $real = null; - - function __construct(&$parent) { - if (is_object($parent)) { - $this->setParent($parent); - } - } - - function toString() { - return $this->__toString(); - } - - function __toString() { - return $this->literal; - } - - function ref($ref = null) { - if ($ref == null) { - foreach (array('id', 'pattern', 'real') as $ref) { - if ($this->{$ref} !== null) { - return $this->{$ref}; - } - } - } else { - return ($this->{$ref} !== null); - } - return null; - } - - function literal($append = null) { - if (!empty($this->id)) { - $data = '$("' . $this->id . '")'; - } - if (!empty($this->pattern)) { - $data = '$$("' . $this->pattern . '")'; - } - if (!empty($this->real)) { - $data = $this->real; - } - if (!empty($append)) { - $data .= '.' . $append; - } - return $data; - } - - function __call($name, $args) { - $data = ''; - - if (isset($this->__parent->effectMap[strtolower($name)])) { - array_unshift($args, $this->__parent->effectMap[strtolower($name)]); - $name = 'effect'; - } - - switch ($name) { - case 'effect': - case 'visualEffect': - - if (strpos($args[0], '_') || $args[0]{0} != strtoupper($args[0]{0})) { - $args[0] = Inflector::camelize($args[0]); - } - - if (strtolower($args[0]) == 'highlight') { - $data .= 'new '; - } - if ($this->pattern == null) { - $data .= 'Effect.' . $args[0] . '(' . $this->literal(); - } else { - $data .= 'Effect.' . $args[0] . '(item'; - } - - if (isset($args[1]) && is_array($args[1])) { - $data .= ', {' . $this->__options($args[1]) . '}'; - } - $data .= ');'; - - if ($this->pattern !== null) { - $data = $this->each($data); - } - break; - case 'remove': - case 'toggle': - case 'show': - case 'hide': - if (empty($args)) { - $obj = 'Element'; - $params = ''; - } else { - $obj = 'Effect'; - $params = ', "' . $args[0] . '"'; - } - - if ($this->pattern != null) { - $data = $this->each($obj . ".{$name}(item);"); - } else { - $data = $obj . ".{$name}(" . $this->literal() . ');'; - } - break; - case 'visible': - $data = $this->literal() . '.visible();'; - break; - case 'update': - $data = $this->literal() . ".update({$args[0]});"; - break; - case 'load': - $data = 'new Ajax.Updater("' . $this->id . '", "' . $args[0] . '"'; - if (isset($args[1]) && is_array($args[1])) { - $data .= ', {' . $this->__options($args[1]) . '}'; - } - $data .= ');'; - break; - case 'each': - case 'all': - case 'any': - case 'detect': - case 'findAll': - if ($this->pattern != null) { - $data = $this->__iterate($name, $args[0]); - } - break; - case 'addClass': - case 'removeClass': - case 'hasClass': - case 'toggleClass': - $data = $this->literal() . ".{$name}Name(\"{$args[0]}\");"; - break; - case 'clone': - case 'inspect': - case 'keys': - case 'values': - $data = "Object.{$name}(" . $this->literal() . ");"; - break; - case 'extend': - $data = "Object.extend(" . $this->literal() . ", {$args[0]});"; - break; - case '...': - // Handle other methods here - // including interfaces to load other files on-the-fly - // that add support for additional methods/replacing existing methods - break; - default: - $data = $this->literal() . '.' . $name . '();'; - break; - } - - if ($this->__parent->output) { - echo $data; - } else { - return $data; - } - } - - function __iterate($method, $data) { - return '$$("' . $this->pattern . '").' . $method . '(function(item) {' . $data . '});'; - } - - function setParent(&$parent) { - $this->__parent =& $parent; - } - - function __options($opts) { - $options = array(); - foreach ($opts as $key => $val) { - if (!is_int($val)) { - $val = '"' . $val . '"'; - } - $options[] = $key . ':' . $val; - } - return join(', ', $options); - } -} ?> \ No newline at end of file