MCPcopy
hub / github.com/winjs/winjs / executeElementAnimation

Function executeElementAnimation

src/js/WinJS/Animations/_TransitionAnimation.js:275–349  ·  view source on GitHub ↗
(elem, index, anims, promises, animate)

Source from the content-addressed store, hash-verified

273 };
274
275 function executeElementAnimation(elem, index, anims, promises, animate) {
276 if (animate && anims.length > 0) {
277 var style = elem.style;
278 var id = _ElementUtilities._uniqueID(elem);
279 anims = anims.map(copyWithEvaluation(index, elem));
280 var styleElem;
281 var listener = elem.disabled ? _Global.document : elem;
282 anims.forEach(function (anim) {
283 if (!anim.keyframe) {
284 if (!styleElem) {
285 styleElem = _Global.document.createElement("STYLE");
286 _Global.document.documentElement.appendChild(styleElem);
287 }
288 anim.keyframe = getUniqueKeyframeName();
289 var kf = "@" + browserStyleEquivalents["keyframes"] + " " + anim.keyframe + " { from {" + anim.property + ":" + anim.from + ";} to {" + anim.property + ":" + anim.to + ";}}";
290 styleElem.sheet.insertRule(kf, 0);
291 } else {
292 anim.keyframe = browserStyleEquivalents.animationPrefix + anim.keyframe;
293 }
294 });
295 var styleCache = setTemporaryStyles(elem, id, style, anims, elementAnimationProperties),
296 animationsToCleanUp = [],
297 animationPromises = [];
298 anims.forEach(function (anim) {
299 var finish;
300 animationPromises.push(new Promise(function (c) {
301 finish = function (reason) {
302 if (onAnimationEnd) {
303 listener.removeEventListener(_BaseUtils._browserEventEquivalents["animationEnd"], onAnimationEnd, false);
304 _Global.clearTimeout(timeoutId);
305 onAnimationEnd = null;
306 }
307 completePromise(c, reason === reason_canceled);
308 };
309
310 var onAnimationEnd = function (event) {
311 if (event.target === elem && event.animationName === anim.keyframe) {
312 finish();
313 }
314 };
315
316 registerAction(id, anim.property, finish);
317 // Firefox will stop all animations if we clean up that animation's properties when there're other CSS animations still running
318 // on an element. To work around this, we delay animation style cleanup until all parts of an animation finish.
319 animationsToCleanUp.push({
320 id: id,
321 property: anim.property,
322 style: style,
323 keyframe: anim.keyframe
324 });
325 var timeoutId = _Global.setTimeout(function () {
326 timeoutId = _Global.setTimeout(finish, anim.delay + anim.duration);
327 }, 50);
328 listener.addEventListener(_BaseUtils._browserEventEquivalents["animationEnd"], onAnimationEnd, false);
329 }, function () { finish(reason_canceled); }));
330 });
331 if (styleElem) {
332 _Global.setTimeout(function () {

Callers

nothing calls this directly

Calls 15

copyWithEvaluationFunction · 0.85
getUniqueKeyframeNameFunction · 0.85
setTemporaryStylesFunction · 0.85
completePromiseFunction · 0.85
registerActionFunction · 0.85
finishFunction · 0.85
createElementMethod · 0.80
appendChildMethod · 0.80
clearTimeoutMethod · 0.80
setTimeoutMethod · 0.80
removeChildMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected