Permalink
Browse files

Updating effect in Mootools

Updating effects and effect test in Prototype
  • Loading branch information...
markstory committed Mar 29, 2009
1 parent 768941b commit ba15d955e29b145609f45b78a02e439d51863237
@@ -140,8 +140,6 @@ function effect($name, $options = array()) {
$effect = 'setStyle("display", "")';
break;
case 'fadeIn':
- $effect = 'fade("in")';
- break;
case 'fadeOut':
case 'slideIn':
case 'slideOut':
@@ -110,7 +110,38 @@ function each($callback) {
* @see JsBaseEngineHelper::effect()
**/
function effect($name, $options = array()) {
-
+ $effect = '';
+ $optionString = null;
+ if (isset($options['speed'])) {
+ if ($options['speed'] == 'fast') {
+ $options['duration'] = 0.5;
+ } elseif ($options['speed'] == 'slow') {
+ $options['duration'] = 2;
+ } else {
+ $options['duration'] = 1;
+ }
+ unset($options['speed']);
+ }
+ if (!empty($options)) {
+ $optionString = ', {' . $this->_parseOptions($options) . '}';
+ }
+ switch ($name) {
+ case 'hide':
+ case 'show':
+ $effect = $this->selection . '.' . $name . '();';
+ break;
+ case 'slideIn':
+ case 'slideOut':
+ $name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
+ $effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');';
+ break;
+ case 'fadeIn':
+ case 'fadeOut':
+ $name = ($name == 'fadeIn') ? 'appear' : 'fade';
+ $effect = $this->selection . '.' . $name .'(' . substr($optionString, 2) . ');';
+ break;
+ }
+ return $effect;
}
/**
* Create an Ajax or Ajax.Updater call.
@@ -114,7 +114,53 @@ function testEach() {
* @return void
**/
function testEffect() {
+ $result = $this->Proto->get('#foo')->effect('show');
+ $expected = '$("foo").show();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('hide');
+ $expected = '$("foo").hide();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeIn');
+ $expected = '$("foo").appear();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeIn', array('speed' => 'fast'));
+ $expected = '$("foo").appear({duration:0.50000000000});';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeIn', array('speed' => 'slow'));
+ $expected = '$("foo").appear({duration:2});';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeOut');
+ $expected = '$("foo").fade();';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeOut', array('speed' => 'fast'));
+ $expected = '$("foo").fade({duration:0.50000000000});';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('fadeOut', array('speed' => 'slow'));
+ $expected = '$("foo").fade({duration:2});';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('slideIn');
+ $expected = 'Effect.slideDown($("foo"));';
+ $this->assertEqual($result, $expected);
+ $result = $this->Proto->effect('slideOut');
+ $expected = 'Effect.slideUp($("foo"));';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('slideOut', array('speed' => 'fast'));
+ $expected = 'Effect.slideUp($("foo"), {duration:0.50000000000});';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->effect('slideOut', array('speed' => 'slow'));
+ $expected = 'Effect.slideUp($("foo"), {duration:2});';
+ $this->assertEqual($result, $expected);
}
/**
* Test Request Generation

0 comments on commit ba15d95

Please sign in to comment.