Skip to content

Commit

Permalink
Adding slider to base engine and jquery engine. Tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 19, 2009
1 parent 4b2504d commit 5bc6bcf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -47,6 +47,10 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
'drop' => array(
'leave' => 'out',
'hover' => 'over'
),
'slider' => array(
'complete' => 'stop',
'direction' => 'orientation'
)
);
/**
Expand Down Expand Up @@ -218,5 +222,19 @@ function drop($options = array()) {
$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);
}
}
?>
22 changes: 22 additions & 0 deletions cake/libs/view/helpers/js.php
Expand Up @@ -650,6 +650,28 @@ function drop($options = array()) {
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,
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -217,5 +217,23 @@ function testDrop() {
$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);
}
}
?>

0 comments on commit 5bc6bcf

Please sign in to comment.