diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php index 5e415d9db93..eb6799928b5 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 @@ function drag($options = array()) { * #### 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 @@ function drop($options = array()) { } 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 ab5ed674659..0ed044e0321 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 @@ function testDrop() { $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