aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/effects/effects.html55
-rw-r--r--tests/unit/effects/effects_core.js28
-rw-r--r--tests/unit/index.html5
-rw-r--r--tests/visual/effects.all.js14
-rw-r--r--ui/jquery.effects.bounce.js144
-rw-r--r--ui/jquery.effects.fade.js17
-rw-r--r--ui/jquery.effects.pulsate.js50
-rw-r--r--ui/jquery.effects.scale.js10
-rw-r--r--ui/jquery.effects.shake.js57
9 files changed, 260 insertions, 120 deletions
diff --git a/tests/unit/effects/effects.html b/tests/unit/effects/effects.html
new file mode 100644
index 000000000..2cffda7ec
--- /dev/null
+++ b/tests/unit/effects/effects.html
@@ -0,0 +1,55 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Core Test Suite</title>
+
+ <script src="../../../jquery-1.5.1.js"></script>
+ <script>
+ $.uiBackCompat = false;
+ </script>
+ <script src="../../../ui/jquery.effects.core.js"></script>
+ <script src="../../../ui/jquery.effects.blind.js"></script>
+ <script src="../../../ui/jquery.effects.bounce.js"></script>
+ <script src="../../../ui/jquery.effects.clip.js"></script>
+ <script src="../../../ui/jquery.effects.drop.js"></script>
+ <script src="../../../ui/jquery.effects.explode.js"></script>
+ <script src="../../../ui/jquery.effects.fade.js"></script>
+ <script src="../../../ui/jquery.effects.fold.js"></script>
+ <script src="../../../ui/jquery.effects.highlight.js"></script>
+ <script src="../../../ui/jquery.effects.pulsate.js"></script>
+ <script src="../../../ui/jquery.effects.scale.js"></script>
+ <script src="../../../ui/jquery.effects.shake.js"></script>
+ <script src="../../../ui/jquery.effects.slide.js"></script>
+ <script src="../../../ui/jquery.effects.transfer.js"></script>
+
+ <link rel="stylesheet" href="../../../external/qunit.css">
+ <script src="../../../external/qunit.js"></script>
+ <script src="../../jquery.simulate.js"></script>
+ <script src="../testsuite.js"></script>
+ <script src="effects_core.js"></script>
+
+ <script src="../swarminject.js"></script>
+
+ <style type="text/css">
+ .hidden {
+ display: none;
+ }
+ </style>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Effects Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests">
+</ol>
+
+<div id="qunit-fixture">
+ <div class="hidden test"></div>
+ <div class="shown test"></div>
+</div>
+
+</body>
+</html>
diff --git a/tests/unit/effects/effects_core.js b/tests/unit/effects/effects_core.js
new file mode 100644
index 000000000..3da0b6f47
--- /dev/null
+++ b/tests/unit/effects/effects_core.js
@@ -0,0 +1,28 @@
+(function($) {
+
+var animateTime = 15;
+
+module( "effects.core" );
+
+$.each( $.effects.effect, function( effect ) {
+ if ( effect === "transfer" ) {
+ return;
+ }
+ QUnit.reset();
+ module( "effect."+effect );
+ test( "show/hide", function() {
+ var hidden = $( "div.hidden" );
+ expect( 3 );
+ stop();
+ hidden.show( effect, animateTime, function() {
+ equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
+ }).hide( effect, animateTime, function() {
+ equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
+ }).queue( function(next) {
+ deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains")
+ start();
+ });
+ });
+});
+
+})(jQuery);
diff --git a/tests/unit/index.html b/tests/unit/index.html
index a677023dc..5282d3f27 100644
--- a/tests/unit/index.html
+++ b/tests/unit/index.html
@@ -59,6 +59,11 @@
<li><a href="position/position.html">Position</a></li>
</ul>
+<h2>Effects</h2>
+<ul>
+ <li><a href="effects/effects.html">Effects</a></li>
+</ul>
+
</body>
</html>
diff --git a/tests/visual/effects.all.js b/tests/visual/effects.all.js
index 3ac8968b3..9cf7487c9 100644
--- a/tests/visual/effects.all.js
+++ b/tests/visual/effects.all.js
@@ -14,12 +14,14 @@ $(function() {
$(el).bind("click", function() {
- $(this).addClass("current").hide(n, o, duration, function() {
- var self = this;
- window.setTimeout(function() {
- $(self).show(n, o, duration, function() { $(this).removeClass("current"); });
- }, wait);
- });
+ $(this).addClass("current")
+ // delaying the initial animation makes sure that the queue stays in tact
+ .delay( 10 )
+ .hide( n, o, duration )
+ .delay( wait )
+ .show( n, o, duration, function() {
+ $( this ).removeClass("current");
+ });
});
};
diff --git a/ui/jquery.effects.bounce.js b/ui/jquery.effects.bounce.js
index 8da0feb76..1ffd5ed5a 100644
--- a/ui/jquery.effects.bounce.js
+++ b/ui/jquery.effects.bounce.js
@@ -12,89 +12,107 @@
*/
(function( $, undefined ) {
-var rshowhide = /show|hide/;
-
$.effects.effect.bounce = function(o) {
- return this.queue(function() {
-
- // Create element
+ return this.queue( function( next ) {
var el = $( this ),
- props = [ 'position', 'top', 'bottom', 'left', 'right' ],
+ props = [ "position", "top", "bottom", "left", "right" ],
+
// defaults:
- mode = $.effects.setMode( el, o.mode || 'effect' ),
- direction = o.direction || 'up',
+ mode = $.effects.setMode( el, o.mode || "effect" ),
+ hide = mode === "hide",
+ show = mode === "show",
+ direction = o.direction || "up",
distance = o.distance || 20,
- times = o.times || 5,
- speed = (o.duration || 250),
+ times = o.times || 5,
+
+ // number of internal animations
+ anims = times * 2 + ( show || hide ? 1 : 0 ),
+ speed = o.duration / anims,
+ easing = o.easing,
+
// utility:
- ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
- motion = ( direction == 'up' || direction == 'left' ), // true is positive
- i, animation, animation1, animation2;
-
+ ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
+ motion = ( direction === "up" || direction === "left" ),
+ i,
+ upAnim,
+ downAnim,
+
+ // we will need to re-assemble the queue to stack our animations in place
+ queue = el.queue(),
+ queuelen = queue.length;
+
// Avoid touching opacity to prevent clearType and PNG issues in IE
- if ( rshowhide.test( mode ) ) {
- props.push( 'opacity' );
+ if ( show || hide ) {
+ props.push( "opacity" );
}
$.effects.save( el, props );
el.show();
$.effects.createWrapper( el ); // Create Wrapper
+ // default distance for the BIGGEST bounce is the outer Distance / 3
if ( !distance ) {
- distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3;
+ distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]({ margin:true }) / 3;
}
- if ( mode == 'show' ) el.css( 'opacity', 0 ).css( ref, motion ? -distance : distance ); // Shift
- if ( mode == 'hide' ) distance = distance / (times * 2);
- if ( mode != 'hide' ) times--;
-
- // Animate
- if ( mode == 'show' ) {
- animation = {
- opacity: 1
- };
- animation[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation, speed / 2, o.easing);
- distance = distance / 2;
- times--;
- };
-
- // Bounces
- for (i = 0; i < times; i++) {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing );
- distance = ( mode == 'hide' ) ? distance * 2 : distance / 2;
+
+ if ( show ) {
+ downAnim = { opacity: 1 };
+ downAnim[ ref ] = 0;
+
+ // if we are showing, force opacity 0 and set the initial position
+ // then do the "first" animation
+ el.css( "opacity", 0 )
+ .css( ref, motion ? -distance*2 : distance*2 )
+ .animate( downAnim, speed, easing );
+ }
+
+ // start at the smallest distance if we are hiding
+ if ( hide ) {
+ distance = distance / ( ( times - 1 ) * 2 );
}
- // Last Bounce
- if ( mode == 'hide' ) {
- animation = {
- opacity: 0
- };
- animation[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- el.animate( animation, speed / 2, o.easing, function(){
+ downAnim = {};
+ downAnim[ ref ] = 0;
+ // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
+ for ( i = 0; i < times; i++ ) {
+ upAnim = {};
+ upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
+
+ // add the finish callback to the last animation if we aren't hiding
+ el.animate( upAnim, speed, easing )
+ .animate( downAnim, speed, easing,
+ ( ( i === times - 1 ) && !hide ) ? finish : undefined );
+
+ distance = hide ? distance * 2 : distance / 2;
+ }
+
+ // Last Bounce when Hiding
+ if ( hide ) {
+ upAnim = { opacity: 0 };
+ upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
+
+ el.animate( upAnim, speed, easing, function(){
el.hide();
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
+ finish();
});
- } else {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el
- .animate( animation1, speed / 2, o.easing )
- .animate( animation2, speed / 2, o.easing, function() {
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
- });
}
- el.dequeue();
+
+ function finish() {
+ $.effects.restore( el, props );
+ $.effects.removeWrapper( el );
+ if ( o.complete ) {
+ o.complete.apply( el[ 0 ] );
+ }
+ }
+
+ // inject all the animations we just queued to be first in line (after "inprogress")
+ if ( queuelen > 1) {
+ queue.splice.apply( queue,
+ [ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
+ }
+ next();
+
});
};
diff --git a/ui/jquery.effects.fade.js b/ui/jquery.effects.fade.js
index 5fa0319c0..ff1cba5f8 100644
--- a/ui/jquery.effects.fade.js
+++ b/ui/jquery.effects.fade.js
@@ -13,19 +13,26 @@
(function( $, undefined ) {
$.effects.effect.fade = function( o ) {
- return this.queue( function() {
+ return this.queue( function( next ) {
var el = $( this ),
- mode = $.effects.setMode( el, o.mode || 'hide' );
+ mode = $.effects.setMode( el, o.mode || 'toggle' ),
+ hide = mode === "hide";
+ el.show();
el.animate({
- opacity: mode
+ opacity: hide ? 0 : 1
}, {
queue: false,
duration: o.duration,
easing: o.easing,
complete: function() {
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
- el.dequeue();
+ if ( hide ) {
+ el.hide();
+ }
+ if ( o.complete ) {
+ o.complete.call( this );
+ }
+ next();
}
});
});
diff --git a/ui/jquery.effects.pulsate.js b/ui/jquery.effects.pulsate.js
index b168b6ef5..30c346abd 100644
--- a/ui/jquery.effects.pulsate.js
+++ b/ui/jquery.effects.pulsate.js
@@ -13,39 +13,49 @@
(function( $, undefined ) {
$.effects.effect.pulsate = function( o ) {
- return this.queue( function() {
+ return this.queue( function( next ) {
var elem = $( this ),
- mode = $.effects.setMode( elem, o.mode || 'show' ),
- times = ( ( o.times || 5 ) * 2 ) - 1,
- duration = o.duration / 2,
- isVisible = elem.is( ':visible' ),
+ mode = $.effects.setMode( elem, o.mode || "show" ),
+ show = mode === "show",
+ hide = mode === "hide",
+
+ // showing or hiding leaves of the "last" animation
+ anims = ( ( o.times || 5 ) * 2 ) - ( show || hide ? 1 : 0 ),
+ duration = o.duration / anims,
animateTo = 0,
+ queue = elem.queue(),
+ queuelen = queue.length,
i;
- if ( !isVisible ) {
- elem.css('opacity', 0).show();
+ if ( show || !elem.is(':visible')) {
+ elem.css( "opacity", 0 ).show();
animateTo = 1;
}
- if ( ( mode == 'hide' && isVisible ) || ( mode == 'show' && !isVisible ) ) {
- times--;
- }
-
- for ( i = 0; i < times; i++ ) {
- elem.animate({
- opacity: animateTo
+ for ( i = 0; i < anims - 1; i++ ) {
+ elem.animate({
+ opacity: animateTo
}, duration, o.easing );
- animateTo = ( animateTo + 1 ) % 2;
+ animateTo = 1 - animateTo;
}
- elem.animate({
- opacity: animateTo
+ elem.animate({
+ opacity: animateTo
}, duration, o.easing, function() {
- if (animateTo == 0) {
+ if ( hide ) {
elem.hide();
}
- (o.complete && o.complete.apply(this, arguments));
- }).dequeue();
+ if ( o.complete ) {
+ o.complete.apply( this );
+ }
+ });
+
+ // We just queued up "anims" animations, we need to put them next in the queue
+ if ( queuelen > 1) {
+ queue.splice.apply( queue,
+ [ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
+ }
+ next();
});
};
diff --git a/ui/jquery.effects.scale.js b/ui/jquery.effects.scale.js
index 8f25ca9a8..843aa2241 100644
--- a/ui/jquery.effects.scale.js
+++ b/ui/jquery.effects.scale.js
@@ -25,6 +25,7 @@ $.effects.effect.puff = function( o ) {
$.extend(o, {
effect: 'scale',
+ queue: false,
fade: true,
mode: mode,
percent: mode == 'hide' ? percent : 100,
@@ -36,13 +37,13 @@ $.effects.effect.puff = function( o ) {
}
});
- elem.effect( o ).dequeue();
+ elem.effect( o );
});
};
$.effects.effect.scale = function( o ) {
- return this.queue( function() {
+ return this[ o.queue === false ? "each" : "queue" ]( function() {
// Create element
var el = $( this ),
@@ -62,6 +63,7 @@ $.effects.effect.scale = function( o ) {
// We are going to pass this effect to the size effect:
options.effect = "size";
+ options.queue = false;
// Set default origin and restore for show/hide
if ( mode != 'effect' ) {
@@ -87,14 +89,14 @@ $.effects.effect.scale = function( o ) {
};
// Animate
- el.effect(options).dequeue();
+ el.effect(options);
});
};
$.effects.effect.size = function( o ) {
- return this.queue( function() {
+ return this[ o.queue === false ? "each" : "queue" ]( function() {
// Create element
var el = $( this ),
props = [ 'position', 'top', 'bottom', 'left', 'right', 'width', 'height', 'overflow', 'opacity' ],
diff --git a/ui/jquery.effects.shake.js b/ui/jquery.effects.shake.js
index a1ba1577c..cd26dc5af 100644
--- a/ui/jquery.effects.shake.js
+++ b/ui/jquery.effects.shake.js
@@ -17,46 +17,59 @@ $.effects.effect.shake = function( o ) {
return this.queue( function() {
var el = $( this ),
- props = [ 'position', 'top', 'bottom', 'left', 'right' ],
- mode = $.effects.setMode( el, o.mode || 'effect' ),
- direction = o.direction || 'left',
+ props = [ "position", "top", "bottom", "left", "right" ],
+ mode = $.effects.setMode( el, o.mode || "effect" ),
+ direction = o.direction || "left",
distance = o.distance || 20,
times = o.times || 3,
- speed = o.duration || 140,
- ref = (direction == 'up' || direction == 'down') ? 'top' : 'left',
- motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg',
+ anims = times * 2 + 1,
+ speed = o.duration,
+ ref = (direction == "up" || direction == "down") ? "top" : "left",
+ motion = (direction == "up" || direction == "left") ? "pos" : "neg",
animation = {},
animation1 = {},
animation2 = {},
- i;
+ i,
- // Adjust
- $.effects.save( el, props );
- el.show();
- $.effects.createWrapper( el ); // Create Wrapper
+ // we will need to re-assemble the queue to stack our animations in place
+ queue = el.queue(),
+ queuelen = queue.length;
+
+
+ $.effects.save( el, props );
+ el.show();
+ $.effects.createWrapper( el );
// Animation
- animation[ ref ] = ( motion == 'pos' ? '-=' : '+=' ) + distance;
- animation1[ ref ] = ( motion == 'pos' ? '+=' : '-=' ) + distance * 2;
- animation2[ ref ] = ( motion == 'pos' ? '-=' : '+=' ) + distance * 2;
+ animation[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance;
+ animation1[ ref ] = ( motion == "pos" ? "+=" : "-=" ) + distance * 2;
+ animation2[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance * 2;
// Animate
el.animate( animation, speed, o.easing );
// Shakes
- for ( i = 1; i < times; i++ ) {
+ for ( i = 1; i < times; i++ ) {
el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing );
};
el
.animate( animation1, speed, o.easing )
- .animate( animation, speed / 2, o.easing, function() {
-
+ .animate( animation, speed / 2, o.easing, function() {
+ if ( mode === "hide" ) {
+ el.hide();
+ }
// Last shake
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
- })
- .dequeue();
+ $.effects.restore( el, props );
+ $.effects.removeWrapper( el );
+ $.isFunction( o.complete ) && o.complete.apply( this, arguments );
+ });
+
+ // inject all the animations we just queued to be first in line (after "inprogress")
+ if ( queuelen > 1) {
+ queue.splice.apply( queue,
+ [ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
+ }
+ el.dequeue();
});
};