Updating effect in Mootools

Updating effects and effect test in Prototype
This commit is contained in:
mark_story 2009-03-28 23:46:23 -04:00
parent 768941baeb
commit ba15d955e2
3 changed files with 78 additions and 3 deletions

View file

@ -140,8 +140,6 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$effect = 'setStyle("display", "")';
break;
case 'fadeIn':
$effect = 'fade("in")';
break;
case 'fadeOut':
case 'slideIn':
case 'slideOut':

View file

@ -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.

View file

@ -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