Skip to content
Permalink
Browse files

Adding slider to Mootools. Test cases added.

  • Loading branch information...
markstory committed Apr 19, 2009
1 parent 5bc6bcf commit b7845657a88f5a3d14444905da2fedfaba18db9e
@@ -655,12 +655,12 @@ function sortable() {
*
* ### 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
*
@@ -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 @@ function drop($options = array()) {
$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;
}
}
?>
@@ -250,5 +250,34 @@ function testDrop() {
$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);
}
}
?>

0 comments on commit b784565

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