Skip to content

Commit

Permalink
Adding drop() to mootools.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 12, 2009
1 parent 1d5e315 commit 3a3e003
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
44 changes: 44 additions & 0 deletions cake/libs/view/helpers/mootools_engine.php
Expand Up @@ -54,6 +54,11 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onComplete',
),
'drop' => array(
'drop' => 'onDrop',
'hover' => 'onEnter',
'leave' => 'onLeave',
)
);
/**
Expand Down Expand Up @@ -226,6 +231,45 @@ function drag($options = array()) {
$options = $this->_parseOptions($options, $callbacks);
return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});';
}
/**
* Create a Droppable element.
*
* Requires the ```Drag``` and ```Drag.Move``` plugins from MootoolsMore
*
* Droppables in Mootools function differently from other libraries. Droppables
* are implemented as an extension of Drag. So in addtion to making a get() selection for
* the droppable element. You must also provide a selector rule to the draggable element. Furthermore,
* Mootools droppables inherit all options from Drag.
*
* @param array $options Array of options for the droppable.
* @return string Completed droppable script.
* @see JsHelper::drop() for options list.
**/
function drop($options = array()) {
if (empty($options['drag'])) {
trigger_error(
__('MootoolsEngine::drop() requires a "drag" option to properly function', true), E_USER_WARNING
);
return false;
}
$options['droppables'] = $this->selection;

$this->get($options['drag']);
unset($options['drag']);

$options = $this->_mapOptions('drop', $options);
$options = $this->_mapOptions('drag', $options);
$callbacks = array('onBeforeStart', 'onStart', 'onSnap', 'onDrag', 'onComplete', 'onDrop',
'onLeave', 'onEnter', 'droppables');

$optionString = $this->_parseOptions($options, $callbacks);
if (!empty($optionString)) {
$optionString = ', {' . $optionString . '}';
}
$out = 'var jsDrop = new Drag.Move(' . $this->selection . $optionString . ');';
$this->selection = $options['droppables'];
return $out;
}

}
?>
18 changes: 17 additions & 1 deletion cake/tests/cases/libs/view/helpers/mootools_engine.test.php
Expand Up @@ -232,7 +232,23 @@ function testDrag() {
* @return void
**/
function testDrop() {

$this->expectError();
$this->Moo->get('#drop-me');
$this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
));

$result = $this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
'drag' => '#my-drag'
));
$expected = 'var jsDrop = new Drag.Move($("my-drag"), {droppables:$("drop-me"), onDrop:onDrop, onEnter:onHover, onLeave:onLeave});';
$this->assertEqual($result, $expected);
$this->assertEqual($this->Moo->selection, '$("drop-me")');
}
}
?>

0 comments on commit 3a3e003

Please sign in to comment.