mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding Event binding to mootools engine
This commit is contained in:
parent
a9da171e8c
commit
51a187f3e5
2 changed files with 22 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue