Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

do not do animateUsingClass on hidden elements #7713

Merged
merged 1 commit into from
May 2, 2014
Merged
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions src/utils/AnimationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,32 @@ define(function (require, exports, module) {
* @return {$.Promise} A promise that is resolved when the animation completes. Never rejected.
*/
function animateUsingClass(target, animClass) {
var result = new $.Deferred();
var result = new $.Deferred(),
$target = $(target);

function finish(e) {
if (e.target === target) {
$(target)
$target
.removeClass(animClass)
.off("webkitTransitionEnd", finish);
result.resolve();
}
}

// Note that we can't just use $.one() here because we only want to remove
// the handler when we get the transition end event for the correct target (not
// a child).
$(target)
.addClass(animClass)
.on("webkitTransitionEnd", finish);
if ($target.is(":hidden")) {
// Don't do anything if the element is hidden because webkitTransitionEnd wouldn't fire
result.resolve();
} else {
// Note that we can't just use $.one() here because we only want to remove
// the handler when we get the transition end event for the correct target (not
// a child).
$target
.addClass(animClass)
.on("webkitTransitionEnd", finish);
}

return result.promise();
}

exports.animateUsingClass = animateUsingClass;
});
});