Adding slider to base engine and jquery engine. Tests added.

This commit is contained in:
mark_story 2009-04-18 22:00:58 -04:00
parent 4b2504d334
commit 5bc6bcfce1
3 changed files with 58 additions and 0 deletions

View file

@ -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);
}
}
?>

View file

@ -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,

View file

@ -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);
}
}
?>