Adding Event binding to mootools engine

This commit is contained in:
mark_story 2009-03-15 18:48:34 -04:00
parent a9da171e8c
commit 51a187f3e5
2 changed files with 22 additions and 1 deletions

View file

@ -75,7 +75,18 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
* @return string completed event handler
**/
function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options);
$function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) {
$callback .= "\nreturn false;";
}
if ($options['wrap']) {
$callback = sprintf($function, $callback);
}
$out = $this->selection . ".addEvent('{$type}', $callback);";
return $out;
}
/**
* Create a domReady event. This is a special event in many libraries

View file

@ -76,7 +76,17 @@ class MooEngineHelperTestCase extends CakeTestCase {
* @return void
**/
function testEvent() {
$result = $this->Moo->get('#myLink')->event('click', 'doClick', array('wrap' => false));
$expected = "$('myLink').addEvent('click', doClick);";
$this->assertEqual($result, $expected);
$result = $this->Moo->get('#myLink')->event('click', 'this.setStyle("display", "");', array('stop' => false));
$expected = "$('myLink').addEvent('click', function (event) {this.setStyle(\"display\", \"\");});";
$this->assertEqual($result, $expected);
$result = $this->Moo->get('#myLink')->event('click', 'this.setStyle("display", "none");');
$expected = "\$('myLink').addEvent('click', function (event) {this.setStyle(\"display\", \"none\");\nreturn false;});";
$this->assertEqual($result, $expected);
}
/**
* test dom ready event creation