Skip to content

Commit

Permalink
Adding drag() to mootools.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 12, 2009
1 parent 02bb4e7 commit 1d5e315
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 23 additions & 1 deletion cake/libs/view/helpers/mootools_engine.php
Expand Up @@ -48,6 +48,12 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'sort' => 'onSort',
'complete' => 'onComplete',
'start' => 'onStart',
),
'drag' => array(
'snapGrid' => 'snap',
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onComplete',
)
);
/**
Expand Down Expand Up @@ -193,7 +199,7 @@ function request($url, $options = array()) {
/**
* 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.
Expand All @@ -205,5 +211,21 @@ function sortable($options = array()) {
$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 . '});';
}

}
?>
10 changes: 9 additions & 1 deletion cake/tests/cases/libs/view/helpers/mootools_engine.test.php
Expand Up @@ -216,7 +216,15 @@ function testSortable() {
* @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
Expand Down

0 comments on commit 1d5e315

Please sign in to comment.