Skip to content
Permalink
Browse files

Adding Event binding to mootools engine

  • Loading branch information...
markstory committed Mar 15, 2009
1 parent a9da171 commit 51a187f3e51c2545efcd74cabfbab16503d377de
@@ -75,7 +75,18 @@ function get($selector) {
* @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
@@ -76,7 +76,17 @@ function testSelector() {
* @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

0 comments on commit 51a187f

Please sign in to comment.
You can’t perform that action at this time.