Skip to content

Commit

Permalink
Adding Event binding to mootools engine
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 15, 2009
1 parent a9da171 commit 51a187f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cake/libs/view/helpers/mootools_engine.php
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cake/tests/cases/libs/view/helpers/mootools_engine.test.php
Expand Up @@ -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
Expand Down

0 comments on commit 51a187f

Please sign in to comment.