Permalink
Browse files

Adding drop() to mootools.

  • Loading branch information...
1 parent 1d5e315 commit 3a3e003982871b394191659e0ea50cc577da9137 @markstory markstory committed Apr 12, 2009
@@ -54,6 +54,11 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onComplete',
+ ),
+ 'drop' => array(
+ 'drop' => 'onDrop',
+ 'hover' => 'onEnter',
+ 'leave' => 'onLeave',
)
);
/**
@@ -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;
+ }
}
?>
@@ -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.