mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-01 23:29:45 +00:00
Adding drop() to mootools.
This commit is contained in:
parent
1d5e3150a2
commit
3a3e003982
2 changed files with 61 additions and 1 deletions
cake
|
@ -54,6 +54,11 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
||||||
'start' => 'onStart',
|
'start' => 'onStart',
|
||||||
'drag' => 'onDrag',
|
'drag' => 'onDrag',
|
||||||
'stop' => 'onComplete',
|
'stop' => 'onComplete',
|
||||||
|
),
|
||||||
|
'drop' => array(
|
||||||
|
'drop' => 'onDrop',
|
||||||
|
'hover' => 'onEnter',
|
||||||
|
'leave' => 'onLeave',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
|
@ -226,6 +231,45 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
||||||
$options = $this->_parseOptions($options, $callbacks);
|
$options = $this->_parseOptions($options, $callbacks);
|
||||||
return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});';
|
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 @@ class MooEngineHelperTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
**/
|
||||||
function testDrop() {
|
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")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue