Updating Mootools engine to work seamlessly with $() and $$() type selections.

This commit is contained in:
mark_story 2009-07-27 08:45:31 -04:00
parent 7246563bae
commit cde9afb486
2 changed files with 6 additions and 7 deletions

View file

@ -73,6 +73,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
* @return object instance of $this. Allows chained methods. * @return object instance of $this. Allows chained methods.
**/ **/
function get($selector) { function get($selector) {
$this->_multipleSelection = false;
if ($selector == 'window' || $selector == 'document') { if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")"; $this->selection = "$(" . $selector .")";
return $this; return $this;
@ -81,6 +82,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$this->selection = '$("' . substr($selector, 1) . '")'; $this->selection = '$("' . substr($selector, 1) . '")';
return $this; return $this;
} }
$this->_multipleSelection = true;
$this->selection = '$$("' . $selector . '")'; $this->selection = '$$("' . $selector . '")';
return $this; return $this;
} }
@ -237,7 +239,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$options = $this->_mapOptions('drag', $options); $options = $this->_mapOptions('drag', $options);
$callbacks = array('onBeforeStart', 'onStart', 'onSnap', 'onDrag', 'onComplete'); $callbacks = array('onBeforeStart', 'onStart', 'onSnap', 'onDrag', 'onComplete');
$options = $this->_parseOptions($options, $callbacks); $options = $this->_parseOptions($options, $callbacks);
return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});'; return $this->selection . '.makeDraggable({' . $options . '});';
} }
/** /**
* Create a Droppable element. * Create a Droppable element.
@ -271,10 +273,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'onLeave', 'onEnter', 'droppables'); 'onLeave', 'onEnter', 'droppables');
$optionString = $this->_parseOptions($options, $callbacks); $optionString = $this->_parseOptions($options, $callbacks);
if (!empty($optionString)) { $out = $this->selection . '.makeDraggable({' . $optionString . '});';
$optionString = ', {' . $optionString . '}';
}
$out = 'var jsDrop = new Drag.Move(' . $this->selection . $optionString . ');';
$this->selection = $options['droppables']; $this->selection = $options['droppables'];
return $out; return $out;
} }

View file

@ -235,7 +235,7 @@ class MooEngineHelperTestCase extends CakeTestCase {
'stop' => 'onStop', 'stop' => 'onStop',
'snapGrid' => array(10,10) 'snapGrid' => array(10,10)
)); ));
$expected = 'var jsDrag = new Drag($("drag-me"), {onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});'; $expected = '$("drag-me").makeDraggable({onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**
@ -258,7 +258,7 @@ class MooEngineHelperTestCase extends CakeTestCase {
'hover' => 'onHover', 'hover' => 'onHover',
'drag' => '#my-drag' 'drag' => '#my-drag'
)); ));
$expected = 'var jsDrop = new Drag.Move($("my-drag"), {droppables:$("drop-me"), onDrop:onDrop, onEnter:onHover, onLeave:onLeave});'; $expected = '$("my-drag").makeDraggable({droppables:$("drop-me"), onDrop:onDrop, onEnter:onHover, onLeave:onLeave});';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->assertEqual($this->Moo->selection, '$("drop-me")'); $this->assertEqual($this->Moo->selection, '$("drop-me")');
} }