Adding drop() to mootools.

This commit is contained in:
mark_story 2009-04-11 23:37:24 -04:00
parent 1d5e3150a2
commit 3a3e003982
2 changed files with 61 additions and 1 deletions

View file

@ -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 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$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;
}
}
?>

View file

@ -232,7 +232,23 @@ class MooEngineHelperTestCase extends CakeTestCase {
* @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")');
}
}
?>