Skip to content

Effects Rewrite #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fea61ce
Effects Rewrite
mikesherov Dec 26, 2012
a2e69cd
Effects rewrite: clip effect
mpetrovich Jun 26, 2013
73c00e5
Effects rewrite: puff effect
mikesherov Feb 12, 2014
1641329
Effects Rewrite: correct animation for "show" on "size".
mikesherov Feb 12, 2014
277b6cc
Effects rewrite: correct whitespace in ui/effect.js
mikesherov Feb 12, 2014
2603495
Effects rewrite: correct element jumping during size animation
mikesherov Feb 12, 2014
03fa2cf
Effects rewrite: add clip visual test to visual test index
mikesherov Feb 12, 2014
01f7f3c
Effects Rewrite: No longer swap "to" and "from" in scale.
mikesherov Feb 12, 2014
9029963
Effects rewrite: correct "restore: false" use case for size/scale.
mikesherov Feb 13, 2014
d564590
Effects: Allow all "effect" calls to default to default Mode.
mikesherov Mar 1, 2014
1cae0d3
Size Effect: revert default origin to middle, center.
mikesherov Mar 3, 2014
fb39056
Puff Effect: set default effect mode to hide
mikesherov Mar 3, 2014
2f25d1f
Effects: Calling an effect that hides back to back replays animation
mikesherov Sep 3, 2014
e02ec9d
Effects: rename effect.removePlaceholder to effect.cleanUpPlaceholder
mikesherov Sep 12, 2014
cc786a8
Effects: Remove stored style data when calling removeStyle
mikesherov Sep 12, 2014
dbb6540
Effects: Introduce $.fn.transfer, deprecate $.effects.effect.transfer
mikesherov Sep 12, 2014
85ce536
Effects: Ensure defined effects are exported as modules
mikesherov Sep 12, 2014
bf67149
Effects: Fix css clip parsing in IE8
mikesherov Sep 12, 2014
cd3ec9f
Effects: Provide back compat for effects defined without a default mode
mikesherov Sep 13, 2014
e8a0d53
Effects: Add explanatory comments for prefilter step
mikesherov Sep 13, 2014
fd051a0
Effects Tests: Fix failing scale test due to subpixel accuracy
mikesherov Sep 13, 2014
15f0cf7
Effects rewrite: ensure placeholder element copies float property
mikesherov Nov 13, 2014
b68b4b2
Effects Rewrite: ensure fold and blind animate the placeholder
mikesherov Nov 14, 2014
32167bd
Effects Rewrite: extract "unshift" method for reuse
mikesherov Nov 14, 2014
b404525
Effects Rewrite: add IE8 CANTFIX note to clip effect test
mikesherov Nov 15, 2014
8017d84
Effects Rewrite: Fix "unshift" method
mikesherov Nov 15, 2014
77783f0
Effects Rewrite: Inline prefilter method
mikesherov Nov 17, 2014
86c375f
Effects Rewrite: Fix style violations in effects_core.js
mikesherov Nov 17, 2014
4c2ffd9
Effects Rewrite: Tests for createPlaceholder
mikesherov Nov 17, 2014
2d7eb90
Effects Rewrite: Consolidate placeholder and style cleanup
mikesherov Nov 17, 2014
64b8ab8
Effects Rewrite: Style cleanup in most files
mikesherov Nov 17, 2014
08544b4
Effects Rewrite: Fix toggle behavior of fade effect
mikesherov Nov 18, 2014
f03b938
Effects Rewrite: Fix style nits
mikesherov Nov 18, 2014
d1b4132
Effects Rewrite: ensure all effects are :animated detectable
mikesherov Nov 18, 2014
40e9a82
Effects Rewrite: Style Changes From Code Review
mikesherov Nov 25, 2014
1cd8fb8
Effects Rewrite: consolidate scaledDimensions
mikesherov Nov 26, 2014
4855481
Effects Rewrite: Style fixes
mikesherov Nov 26, 2014
e9b02fe
Effects Rewrite: Rename el and o to element and options
mikesherov Nov 26, 2014
2f39707
Effects Rewrite: Fix style nits in size effect
mikesherov Nov 28, 2014
2a37345
Effects Rewrite: Fix demo sizes to account for new font sizes
mikesherov Nov 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demos/effect/addClass.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; padding: 1em; font-size: 1.2em; border: 1px solid #000; background: #eee; color: #333; }
.newClass { text-indent: 40px; letter-spacing: .4em; width: 410px; height: 100px; padding: 30px; margin: 10px; font-size: 1.6em; }
#effect { width: 240px; padding: 1em; border: 1px solid #000; background: #eee; color: #333; }
.newClass { text-indent: 40px; letter-spacing: .4em; width: 410px; height: 120px; padding: 30px; margin: 10px; font-size: 1.1em; }
</style>
<script>
$(function() {
Expand Down
2 changes: 1 addition & 1 deletion demos/effect/animate.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; background: #fff; }
#effect { width: 240px; height: 170px; padding: 0.4em; position: relative; background: #fff; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script>
Expand Down
4 changes: 2 additions & 2 deletions demos/effect/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
#effect { width: 240px; height: 170px; padding: 0.4em; position: relative; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
.ui-effects-transfer { border: 2px dotted gray; }
</style>
Expand All @@ -40,7 +40,7 @@
var options = {};
// some effects have required parameters
if ( selectedEffect === "scale" ) {
options = { percent: 0 };
options = { percent: 50 };
} else if ( selectedEffect === "transfer" ) {
options = { to: "#button", className: "ui-effects-transfer" };
} else if ( selectedEffect === "size" ) {
Expand Down
6 changes: 4 additions & 2 deletions demos/effect/hide.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script src="../../ui/effect-clip.js"></script>
<script src="../../ui/effect-drop.js"></script>
<script src="../../ui/effect-explode.js"></script>
<script src="../../ui/effect-fade.js"></script>
<script src="../../ui/effect-fold.js"></script>
<script src="../../ui/effect-highlight.js"></script>
<script src="../../ui/effect-puff.js"></script>
Expand All @@ -23,7 +24,7 @@
<style>
.toggler { width: 500px; height: 200px; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
#effect { width: 240px; height: 170px; padding: 0.4em; position: relative; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script>
Expand All @@ -37,7 +38,7 @@
var options = {};
// some effects have required parameters
if ( selectedEffect === "scale" ) {
options = { percent: 0 };
options = { percent: 50 };
} else if ( selectedEffect === "size" ) {
options = { to: { width: 200, height: 60 } };
}
Expand Down Expand Up @@ -77,6 +78,7 @@ <h3 class="ui-widget-header ui-corner-all">Hide</h3>
<option value="clip">Clip</option>
<option value="drop">Drop</option>
<option value="explode">Explode</option>
<option value="fade">Fade</option>
<option value="fold">Fold</option>
<option value="highlight">Highlight</option>
<option value="puff">Puff</option>
Expand Down
6 changes: 4 additions & 2 deletions demos/effect/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script src="../../ui/effect-clip.js"></script>
<script src="../../ui/effect-drop.js"></script>
<script src="../../ui/effect-explode.js"></script>
<script src="../../ui/effect-fade.js"></script>
<script src="../../ui/effect-fold.js"></script>
<script src="../../ui/effect-highlight.js"></script>
<script src="../../ui/effect-puff.js"></script>
Expand All @@ -23,7 +24,7 @@
<style>
.toggler { width: 500px; height: 200px; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
#effect { width: 240px; height: 170px; padding: 0.4em; position: relative; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script>
Expand All @@ -37,7 +38,7 @@
var options = {};
// some effects have required parameters
if ( selectedEffect === "scale" ) {
options = { percent: 100 };
options = { percent: 50 };
} else if ( selectedEffect === "size" ) {
options = { to: { width: 280, height: 185 } };
}
Expand Down Expand Up @@ -79,6 +80,7 @@ <h3 class="ui-widget-header ui-corner-all">Show</h3>
<option value="clip">Clip</option>
<option value="drop">Drop</option>
<option value="explode">Explode</option>
<option value="fade">Fade</option>
<option value="fold">Fold</option>
<option value="highlight">Highlight</option>
<option value="puff">Puff</option>
Expand Down
4 changes: 2 additions & 2 deletions demos/effect/switchClass.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { position: relative; }
.newClass { width: 240px; padding: 1em; letter-spacing: 0; font-size: 1.2em; margin: 0; }
.anotherNewClass { text-indent: 40px; letter-spacing: .4em; width: 410px; height: 100px; padding: 30px; margin: 10px; font-size: 1.6em; }
.newClass { width: 240px; padding: 1em; letter-spacing: 0; margin: 0; }
.anotherNewClass { text-indent: 40px; letter-spacing: .2em; width: 410px; height: 100px; padding: 30px; margin: 10px; font-size: 1.1em; }
</style>
<script>
$(function() {
Expand Down
6 changes: 4 additions & 2 deletions demos/effect/toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script src="../../ui/effect-clip.js"></script>
<script src="../../ui/effect-drop.js"></script>
<script src="../../ui/effect-explode.js"></script>
<script src="../../ui/effect-fade.js"></script>
<script src="../../ui/effect-fold.js"></script>
<script src="../../ui/effect-highlight.js"></script>
<script src="../../ui/effect-puff.js"></script>
Expand All @@ -32,7 +33,7 @@
#effect {
position: relative;
width: 240px;
height: 135px;
height: 170px;
padding: 0.4em;
}
#effect h3 {
Expand All @@ -52,7 +53,7 @@
var options = {};
// some effects have required parameters
if ( selectedEffect === "scale" ) {
options = { percent: 0 };
options = { percent: 50 };
} else if ( selectedEffect === "size" ) {
options = { to: { width: 200, height: 60 } };
}
Expand Down Expand Up @@ -85,6 +86,7 @@ <h3 class="ui-widget-header ui-corner-all">Toggle</h3>
<option value="clip">Clip</option>
<option value="drop">Drop</option>
<option value="explode">Explode</option>
<option value="fade">Fade</option>
<option value="fold">Fold</option>
<option value="highlight">Highlight</option>
<option value="puff">Puff</option>
Expand Down
51 changes: 35 additions & 16 deletions tests/unit/effects/effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,47 @@
width: 100px;
}

.relative {
position: relative;
top: 0px;
left: 0px;
}
.absolute {
position: absolute;
top: 0px;
left: 0px;
}
.fixed {
position: fixed;
top: 0px;
left: 0px;
}
.static {
position: static;
}

</style>
</head>
<body>

<div id="qunit"></div>
<div id="qunit-fixture">
<div id="elem" class="test">
</div>
<div class="hidden test">
<div>.</div>
</div>
<div class="animateClass test">
<h2>Child Element Test</h2>
</div>
<div class="relWidth relHeight testAddBorder">
<h2>Slide with relative width</h2>
</div>
<div class="testScale">
</div>
<div class="ticket7106">
</div>

<div id="elem" class="test"></div>
<div class="hidden test">
<div>.</div>
</div>
<div class="animateClass test">
<h2>Child Element Test</h2>
</div>
<div class="relWidth relHeight testAddBorder">
<h2>Slide with relative width</h2>
</div>
<div class="testScale"></div>
<div class="ticket7106"></div>
<div class="relative"></div>
<div class="absolute"></div>
<div class="fixed"></div>
<div class="static"></div>
</div>
</body>
</html>
100 changes: 75 additions & 25 deletions tests/unit/effects/effects_core.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function($) {

function present( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message );
QUnit.push( jQuery.inArray( value, array ) !== -1, value, array, message );
}

function notPresent( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
QUnit.push( jQuery.inArray( value, array ) === -1, value, array, message );
}

// minDuration is used for "short" animate tests where we are only concerned about the final
Expand Down Expand Up @@ -75,20 +75,6 @@ test( "removeClass", function() {
equal( "", element[ 0 ].className );
});


/* TODO: Disabled - Can't figure out why this is failing in IE 6/7
test( "createWrapper and removeWrapper retain focused elements (#7595)", function() {
expect( 2 );
var test = $( "div.hidden" ).show(),
input = $( "<input type='text'>" ).appendTo( test ).focus();

$.effects.createWrapper( test );
equal( document.activeElement, input[ 0 ], "Active element is still input after createWrapper" );
$.effects.removeWrapper( test );
equal( document.activeElement, input[ 0 ], "Active element is still input after removeWrapper" );
});
*/

module( "effects.core: animateClass" );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Determine if we can enable this now that we don't support IE 6/7.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's testing a deprecated function anyway, but I'll see if I can enable it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked into enabling it, and it seemed like it passes, but I'm still removing the test because I'd have to remove it anyway in the future.

asyncTest( "animateClass works with borderStyle", function() {
Expand Down Expand Up @@ -213,6 +199,44 @@ asyncTest( "animateClass: css and class changes during animation are not lost (#
.height( 100 );
});

test( "createPlaceholder: only created for static or relative elements", function() {
expect( 4 );

ok( $.effects.createPlaceholder( $( ".relative" ) ).length, "placeholder created for relative element" );
ok( $.effects.createPlaceholder( $( ".static" ) ).length, "placeholder created for static element" );
ok( !$.effects.createPlaceholder( $( ".absolute" ) ), "placeholder not created for absolute element" );
ok( !$.effects.createPlaceholder( $( ".fixed" ) ), "placeholder not created for fixed element" );
});

test( "createPlaceholder: preserves layout affecting properties", function() {
expect( 7 );

var position = 5,
element = $( ".relative" ).css({
top: position,
left: position
}),
before = {
offset: element.offset(),
outerWidth: element.outerWidth( true ),
outerHeight: element.outerHeight( true ),
"float": element.css( "float" ),
position: element.position()
},
placeholder = $.effects.createPlaceholder( element );

// Placeholders are only placed to preserve the effect on layout. Considering
// top and left do not change layout, they are not preserved, which makes some
// of the math simpler in the implementation.
deepEqual( before.offset.top - position, placeholder.offset().top, "offset top preserved" );
deepEqual( before.offset.left - position, placeholder.offset().left, "offset left preserved" );
deepEqual( before.position.top - position, placeholder.position().top, "position top preserved" );
deepEqual( before.position.left - position, placeholder.position().left, "position left preserved" );

deepEqual( before[ "float" ], placeholder.css( "float" ), "float preserved" );
deepEqual( before.outerWidth, placeholder.outerWidth( true ), "width preserved" );
deepEqual( before.outerHeight, placeholder.outerHeight( true ), "height preserved" );
});

$.each( $.effects.effect, function( effect ) {
module( "effects." + effect );
Expand All @@ -223,7 +247,7 @@ $.each( $.effects.effect, function( effect ) {
return;
}
asyncTest( "show/hide", function() {
expect( 8 );
expect( 12 );
var hidden = $( "div.hidden" ),
count = 0,
test = 0;
Expand All @@ -242,14 +266,40 @@ $.each( $.effects.effect, function( effect ) {
};
}

hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() {
equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
})).queue( queueTest() ).hide( effect, minDuration, queueTest(function() {
equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
})).queue( queueTest(function() {
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
start();
}));
function duringTest( fn ) {
return function( next ) {
setTimeout( fn );
next();
};
}

hidden
.queue( queueTest() )
.queue( duringTest(function() {
ok( hidden.is( ":animated" ),
"Hidden is seen as animated during .show(\"" + effect + "\", time)" );
}) )
.show( effect, minDuration, queueTest(function() {
equal( hidden.css( "display" ), "block",
"Hidden is shown after .show(\"" + effect + "\", time)" );
ok( !$( ".ui-effects-placeholder" ).length,
"No placeholder remains after .show(\"" + effect + "\", time)" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're checking for this not existing after, shouldn't we test for it existing during?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't exist for all animations. The effects code itself always cleans up the placeholder, but the individual effects definitions determine whether or not they need to create one.

}) )
.queue( queueTest() )
.queue( duringTest(function() {
ok( hidden.is( ":animated" ),
"Hidden is seen as animated during .hide(\"" + effect + "\", time)" );
}) )
.hide( effect, minDuration, queueTest(function() {
equal( hidden.css( "display" ), "none",
"Back to hidden after .hide(\"" + effect + "\", time)" );
ok( !$( ".ui-effects-placeholder" ).length,
"No placeholder remains after .hide(\"" + effect + "\", time)" );
}) )
.queue( queueTest(function() {
deepEqual( hidden.queue(), [ "inprogress" ], "Only the inprogress sentinel remains" );
start();
}) );
});

asyncTest( "relative width & height - properties are preserved", function() {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/effects/effects_scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function run( position, v, h, vo, ho ) {
asyncTest( desc, function() {
expect( 2 );
function complete() {
equal( parseInt( test.css( h ), 10 ), target[ h ], "Horizontal Position Correct " + desc );
equal( parseInt( test.css( v ), 10 ), target[ v ], "Vertical Position Correct " + desc );
closeEnough( parseInt( test.css( h ), 10 ), target[ h ], 1, "Horizontal Position Correct " + desc );
closeEnough( parseInt( test.css( v ), 10 ), target[ v ], 1, "Vertical Position Correct " + desc );
start();
}
var test = $( ".testScale" ),
Expand Down
2 changes: 2 additions & 0 deletions tests/visual/effects/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
<script src="../../../ui/effect-fade.js"></script>
<script src="../../../ui/effect-fold.js"></script>
<script src="../../../ui/effect-highlight.js"></script>
<script src="../../../ui/effect-puff.js"></script>
<script src="../../../ui/effect-pulsate.js"></script>
<script src="../../../ui/effect-scale.js"></script>
<script src="../../../ui/effect-size.js"></script>
<script src="../../../ui/effect-shake.js"></script>
<script src="../../../ui/effect-slide.js"></script>
<script src="../../../ui/effect-transfer.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion tests/visual/effects/clip.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<p>EXPECTED: Clicking "Toggle" or "Effect Toggle" a second time reverses the animation, first showing all elements at their original dimensions, and restoring them to their original state.</p>
<p>EXPECTED: Clicking "Effect Default" should always perform a "hide" animation.</p>
<p>EXPECTED: Clicking any of the buttons in quick succession should queue the relevant animations.</p>
<p>EXPECTED CANTFIX: In IE8, the clip animation jumps due to a bug that causes .css('clip') to return undefined unless the clip property is an inline style.</p>

<div class="container">
<button class="toggle">Toggle</button>
Expand All @@ -80,7 +81,7 @@
<p>Jerky corned beef short loin fatback jowl tail. Rump spare ribs shoulder pork belly. Sausage cow ground round bacon. Bresaola kielbasa pastrami brisket ham hock. Andouille kielbasa ham, pork beef tenderloin ground round beef ribs flank turkey pancetta tri-tip.</p>
<div class="column">
<p>Shankle filet mignon ribeye chicken, bacon jowl drumstick frankfurter swine short loin capicola leberkas tenderloin pig. Shankle bacon shank pork loin, shoulder ham drumstick biltong. Shankle ham pastrami ball tip turkey leberkas pork loin ground round. Chicken strip steak venison shoulder biltong ham. Bacon pork loin tenderloin kielbasa, prosciutto sausage leberkas jowl ribeye turducken. Flank short loin venison tenderloin spare ribs boudin, tongue pork chop shank sirloin. Ground round ham pork belly, corned beef jowl strip steak short ribs prosciutto pig bresaola spare ribs.</p>
<img class="target" style="margin: 10px 20px 30px 40px;" src="../../images/jquery_521x191.png" alt="jQuery Logo">
<img class="target margin" src="../../images/jquery_521x191.png" alt="jQuery Logo">
<p>Pork loin biltong ball tip tail jerky beef ribs prosciutto short loin turducken. Turkey chicken jowl pork loin shank tri-tip swine brisket. Doner prosciutto leberkas venison ground round, short loin capicola hamburger pork bacon. Spare ribs beef pork tenderloin rump shoulder pork belly turducken cow beef ribs pastrami tail flank. Spare ribs tri-tip shank, pork beef ribs ribeye chicken bacon boudin shoulder venison. Sirloin beef ribs boudin, andouille doner tail ball tip biltong prosciutto chicken beef turkey tongue hamburger tri-tip.</p>
</div>
<p>Doner salami jowl beef ribs. Pork chop beef short loin pork, kielbasa tail andouille salami sausage meatball short ribs t-bone tri-tip ham. Meatball short ribs prosciutto flank chicken fatback frankfurter brisket turducken. Corned beef hamburger swine short ribs pancetta. Jerky bresaola pork chuck spare ribs pastrami shoulder flank chicken leberkas beef.</p>
Expand Down
Loading