Adding drag() to mootools.

This commit is contained in:
mark_story 2009-04-11 23:09:58 -04:00
parent 02bb4e71f3
commit 1d5e3150a2
2 changed files with 32 additions and 2 deletions

View file

@ -48,6 +48,12 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'sort' => 'onSort',
'complete' => 'onComplete',
'start' => 'onStart',
),
'drag' => array(
'snapGrid' => 'snap',
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onComplete',
)
);
/**
@ -193,7 +199,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
/**
* Create a sortable element.
*
* Requires both the ```Sortables``` plugin from MootoolsMore
* Requires the ```Sortables``` plugin from MootoolsMore
*
* @param array $options Array of options for the sortable.
* @return string Completed sortable script.
@ -205,5 +211,21 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$options = $this->_parseOptions($options, $callbacks);
return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
}
/**
* Create a Draggable element.
*
* Requires the ```Drag``` plugin from MootoolsMore
*
* @param array $options Array of options for the draggable.
* @return string Completed draggable script.
* @see JsHelper::drag() for options list.
**/
function drag($options = array()) {
$options = $this->_mapOptions('drag', $options);
$callbacks = array('onBeforeStart', 'onStart', 'onSnap', 'onDrag', 'onComplete');
$options = $this->_parseOptions($options, $callbacks);
return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});';
}
}
?>

View file

@ -216,7 +216,15 @@ class MooEngineHelperTestCase extends CakeTestCase {
* @return void
**/
function testDrag() {
$this->Moo->get('#drag-me');
$result = $this->Moo->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10,10)
));
$expected = 'var jsDrag = new Drag($("drag-me"), {onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';
$this->assertEqual($result, $expected);
}
/**
* test drop() method