Skip to content
Permalink
Browse files

Adding effects and effects tests to JqueryEngine

  • Loading branch information...
markstory committed Mar 14, 2009
1 parent 94c4e18 commit 72e1c7313451727e03b11db7a51233b49bd28196
@@ -24,7 +24,9 @@
* @lastmodified
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class jqueryEngineHelper extends AppHelper {
App::import('Helper', 'Js');
class jqueryEngineHelper extends JsBaseEngineHelper {
/**
* Create javascript selector for a CSS rule
*
@@ -74,5 +76,30 @@ function domReady($functionBody) {
function each($callback) {
return $this->selection . '.each(function () {' . $callback . '});';
}
/**
* Trigger an Effect.
*
* @param string $name The name of the effect to trigger.
* @param array $options Array of options for the effect.
* @return string completed string with effect.
* @see JsBaseEngineHelper::effect()
**/
function effect($name, $options = array()) {
$speed = null;
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
$speed = $this->value($options['speed']);
}
$effect = '';
switch ($name) {
case 'hide':
case 'show':
case 'fadeIn':
case 'fadeOut':
case 'toggle':
$effect = ".$name($speed);";
break;
}
return $this->selection . $effect;
}
}
?>
@@ -467,7 +467,7 @@ function writeCache($script) {
/**
* Get all the cached scripts
*
* @param boolean $clear Whether or not to clear the script cache.s
* @param boolean $clear Whether or not to clear the script caches
* @return array Array of scripts added to the request.
**/
function getCache($clear = true) {
@@ -517,6 +517,41 @@ function domReady($functionBody) {
function each($callback) {
trigger_error(sprintf(__('%s does not have each() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Trigger an Effect.
*
* #### Supported Effects
*
* The following effects are supported by all JsEngines
*
* - 'show' - reveal an element.
* - '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.
*
* #### Options
*
* - 'speed' - Speed at which the animation should occur. Accepted values are 'slow', 'fast'. Not all effects use
* the speed option.
*
* @param string $name The name of the effect to trigger.
* @param array $options Array of options for the effect.
* @return string completed string with effect.
**/
function effect($name, $options) {
trigger_error(sprintf(__('%s does not have effect() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Make an XHR request
*
* @return string XHR request.
**/
function request() {
trigger_error(sprintf(__('%s does not have request() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Parse an options assoc array into an Javascript object literal.
* Similar to object() but treats any non-integer value as a string,
@@ -96,6 +96,35 @@ function testEach() {
$expected = "\$('#foo').each(function () {\$(this).hide();});";
$this->assertEqual($result, $expected);
}
/**
* test Effect generation
*
* @return void
**/
function testEffect() {
$result = $this->Jquery->get('#foo')->effect('show');
$expected = "\$('#foo').show();";
$this->assertEqual($result, $expected);
$result = $this->Jquery->effect('hide');
$expected = "\$('#foo').hide();";
$this->assertEqual($result, $expected);
$result = $this->Jquery->effect('hide', array('speed' => 'fast'));
$expected = "\$('#foo').hide(\"fast\");";
$this->assertEqual($result, $expected);
$result = $this->Jquery->effect('fadeIn');
$expected = "\$('#foo').fadeIn();";
$this->assertEqual($result, $expected);
$result = $this->Jquery->effect('fadeOut');
$expected = "\$('#foo').fadeOut();";
$this->assertEqual($result, $expected);
$result = $this->Jquery->effect('toggle');
$expected = "\$('#foo').toggle();";
$this->assertEqual($result, $expected);
}
}
?>

0 comments on commit 72e1c73

Please sign in to comment.
You can’t perform that action at this time.