From ba15d955e29b145609f45b78a02e439d51863237 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 28 Mar 2009 23:46:23 -0400 Subject: [PATCH] Updating effect in Mootools Updating effects and effect test in Prototype --- cake/libs/view/helpers/mootools_engine.php | 2 - cake/libs/view/helpers/prototype_engine.php | 33 ++++++++++++- .../view/helpers/prototype_engine.test.php | 46 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/mootools_engine.php b/cake/libs/view/helpers/mootools_engine.php index 3c8ed5629..ad78c5740 100644 --- a/cake/libs/view/helpers/mootools_engine.php +++ b/cake/libs/view/helpers/mootools_engine.php @@ -140,8 +140,6 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $effect = 'setStyle("display", "")'; break; case 'fadeIn': - $effect = 'fade("in")'; - break; case 'fadeOut': case 'slideIn': case 'slideOut': diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php index f15231429..a7b5d5aa8 100644 --- a/cake/libs/view/helpers/prototype_engine.php +++ b/cake/libs/view/helpers/prototype_engine.php @@ -110,7 +110,38 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { * @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. diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php index c0dadba65..92d10a116 100644 --- a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -114,7 +114,53 @@ class PrototypeEngineHelperTestCase extends CakeTestCase { * @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