Skip to content
Permalink
Browse files

Adding slider to prototype

  • Loading branch information...
markstory committed Apr 21, 2009
1 parent b784565 commit dd01dda0b4809aec642e0b6871f251ed34ee75e3
@@ -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;
}
}
?>
@@ -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);
}
}
?>

0 comments on commit dd01dda

Please sign in to comment.
You can’t perform that action at this time.