Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switching quote styles in mootools engine

Adding effect() and each() to mootools
Adding tests
  • Loading branch information...
commit 87d68e5029ddb969c6f800c87d46198c078e2f08 1 parent 51a187f
Mark Story markstory authored
3  cake/libs/view/helpers/jquery_engine.php
View
@@ -118,7 +118,8 @@ function effect($name, $options = array()) {
case 'show':
case 'fadeIn':
case 'fadeOut':
- case 'toggle':
+ case 'slideIn':
+ case 'slideOut':
$effect = ".$name($speed);";
break;
}
1  cake/libs/view/helpers/js.php
View
@@ -538,7 +538,6 @@ function each($callback) {
* - 'hide' - hide an element.
* - 'fadeIn' - Fade in an element.
* - 'fadeOut' - Fade out an element.
- * - 'toggle' - Toggle an element's visibility.
* - 'slideIn' - Slide an element in.
* - 'slideOut' - Slide an element out.
*
47 cake/libs/view/helpers/mootools_engine.php
View
@@ -4,7 +4,7 @@
*
* Provides MooTools specific Javascript for JsHelper.
* Assumes that you have the following MooTools packages
- *
+ *
* - Remote, Remote.HTML, Remote.JSON
* - Fx, Fx.Tween, Fx.Morph
* - Selectors, DomReady,
@@ -55,10 +55,10 @@ function get($selector) {
return $this;
}
if (preg_match('/^#[^\s.]+$/', $selector)) {
- $this->selection = "$('" . substr($selector, 1) . "')";
+ $this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
- $this->selection = "$$('" . $selector ."')";
+ $this->selection = '$$("' . $selector . '")';
return $this;
}
/**
@@ -77,7 +77,7 @@ function get($selector) {
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;";
@@ -85,7 +85,7 @@ function event($type, $callback, $options = array()) {
if ($options['wrap']) {
$callback = sprintf($function, $callback);
}
- $out = $this->selection . ".addEvent('{$type}', $callback);";
+ $out = $this->selection . ".addEvent(\"{$type}\", $callback);";
return $out;
}
/**
@@ -95,7 +95,8 @@ function event($type, $callback, $options = array()) {
* @return string completed domReady method
**/
function domReady($functionBody) {
-
+ $this->selection = 'window';
+ return $this->event('domready', $functionBody, array('stop' => false));
}
/**
* Create an iteration over the current selection result.
@@ -105,7 +106,7 @@ function domReady($functionBody) {
* @return string completed iteration
**/
function each($callback) {
-
+ return $this->selection . '.each(function (item, index) {' . $callback . '});';
}
/**
* Trigger an Effect.
@@ -116,7 +117,37 @@ function each($callback) {
* @see JsBaseEngineHelper::effect()
**/
function effect($name, $options = array()) {
-
+ $speed = null;
+ if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
+ if ($options['speed'] == 'fast') {
+ $speed = '"short"';
+ } elseif ($options['speed'] == 'slow') {
+ $speed = '"long"';
+ }
+ }
+ $effect = '';
+ switch ($name) {
+ case 'hide':
+ $effect = 'setStyle("display", "none")';
+ break;
+ case 'show':
+ $effect = 'setStyle("display", "")';
+ break;
+ case 'fadeIn':
+ $effect = 'fade("in")';
+ break;
+ case 'fadeOut':
+ case 'slideIn':
+ case 'slideOut':
+ list($effectName, $direction) = preg_split('/([A-Z][a-z]+)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $direction = strtolower($direction);
+ if ($speed) {
+ $effect .= "set(\"$effectName\", {duration:$speed}).";
+ }
+ $effect .= "$effectName(\"$direction\")";
+ break;
+ }
+ return $this->selection . '.' . $effect . ';';
}
/**
* Create an $.ajax() call.
8 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
View
@@ -126,8 +126,12 @@ function testEffect() {
$expected = "\$('#foo').fadeOut();";
$this->assertEqual($result, $expected);
- $result = $this->Jquery->effect('toggle');
- $expected = "\$('#foo').toggle();";
+ $result = $this->Jquery->effect('slideIn');
+ $expected = "\$('#foo').slideIn();";
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Jquery->effect('slideOut');
+ $expected = "\$('#foo').slideOut();";
$this->assertEqual($result, $expected);
}
/**
53 cake/tests/cases/libs/view/helpers/mootools_engine.test.php
View
@@ -48,11 +48,11 @@ function endTest() {
function testSelector() {
$result = $this->Moo->get('#content');
$this->assertEqual($result, $this->Moo);
- $this->assertEqual($this->Moo->selection, "$('content')");
+ $this->assertEqual($this->Moo->selection, '$("content")');
$result = $this->Moo->get('a .remove');
$this->assertEqual($result, $this->Moo);
- $this->assertEqual($this->Moo->selection, "$$('a .remove')");
+ $this->assertEqual($this->Moo->selection, '$$("a .remove")');
$result = $this->Moo->get('document');
$this->assertEqual($result, $this->Moo);
@@ -64,11 +64,11 @@ function testSelector() {
$result = $this->Moo->get('ul');
$this->assertEqual($result, $this->Moo);
- $this->assertEqual($this->Moo->selection, "$$('ul')");
+ $this->assertEqual($this->Moo->selection, '$$("ul")');
$result = $this->Moo->get('#some_long-id.class');
$this->assertEqual($result, $this->Moo);
- $this->assertEqual($this->Moo->selection, "$$('#some_long-id.class')");
+ $this->assertEqual($this->Moo->selection, '$$("#some_long-id.class")');
}
/**
* test event binding
@@ -77,15 +77,15 @@ function testSelector() {
**/
function testEvent() {
$result = $this->Moo->get('#myLink')->event('click', 'doClick', array('wrap' => false));
- $expected = "$('myLink').addEvent('click', doClick);";
+ $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\", \"\");});";
+ $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;});";
+ $expected = "\$(\"myLink\").addEvent(\"click\", function (event) {this.setStyle(\"display\", \"none\");\nreturn false;});";
$this->assertEqual($result, $expected);
}
/**
@@ -94,7 +94,9 @@ function testEvent() {
* @return void
**/
function testDomReady() {
-
+ $result = $this->Moo->domReady('foo.name = "bar";');
+ $expected = 'window.addEvent("domready", function (event) {foo.name = "bar";});';
+ $this->assertEqual($result, $expected);
}
/**
* test Each method
@@ -102,7 +104,9 @@ function testDomReady() {
* @return void
**/
function testEach() {
-
+ $result = $this->Moo->get('#foo')->each('item.setStyle("display", "none");');
+ $expected = '$("foo").each(function (item, index) {item.setStyle("display", "none");});';
+ $this->assertEqual($result, $expected);
}
/**
* test Effect generation
@@ -110,6 +114,37 @@ function testEach() {
* @return void
**/
function testEffect() {
+ $result = $this->Moo->get('#foo')->effect('show');
+ $expected = '$("foo").setStyle("display", "");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('hide');
+ $expected = '$("foo").setStyle("display", "none");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('fadeIn');
+ $expected = '$("foo").fade("in");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('fadeOut');
+ $expected = '$("foo").fade("out");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('slideIn');
+ $expected = '$("foo").slide("in");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('slideOut');
+ $expected = '$("foo").slide("out");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('slideOut', array('speed' => 'fast'));
+ $expected = '$("foo").set("slide", {duration:"short"}).slide("out");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Moo->effect('slideOut', array('speed' => 'slow'));
+ $expected = '$("foo").set("slide", {duration:"long"}).slide("out");';
+ $this->assertEqual($result, $expected);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.