mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Adding event() and tests to prototype library
This commit is contained in:
parent
da2361de14
commit
8cc5990e09
2 changed files with 23 additions and 1 deletions
|
@ -2,7 +2,8 @@
|
|||
/**
|
||||
* Prototype Engine Helper for JsHelper
|
||||
*
|
||||
* Provides Prototype specific Javascript for JsHelper.
|
||||
* Provides Prototype specific Javascript for JsHelper. Requires at least
|
||||
* Prototype 1.6
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -67,7 +68,18 @@ class PrototypeEngineHelper 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 = "event.stop();\n" . $callback;
|
||||
}
|
||||
if ($options['wrap']) {
|
||||
$callback = sprintf($function, $callback);
|
||||
}
|
||||
$out = $this->selection . ".observe(\"{$type}\", $callback);";
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Create a domReady event. This is a special event in many libraries
|
||||
|
|
|
@ -76,7 +76,17 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testEvent() {
|
||||
$result = $this->Proto->get('#myLink')->event('click', 'doClick', array('wrap' => false));
|
||||
$expected = '$("myLink").observe("click", doClick);';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->get('#myLink')->event('click', 'Element.hide(this);', array('stop' => false));
|
||||
$expected = '$("myLink").observe("click", function (event) {Element.hide(this);});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->get('#myLink')->event('click', 'Element.hide(this);');
|
||||
$expected = "\$(\"myLink\").observe(\"click\", function (event) {event.stop();\nElement.hide(this);});";
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test dom ready event creation
|
||||
|
|
Loading…
Add table
Reference in a new issue