From 71b6d35be1af2d98d72cbe3b0013706821c984c6 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Mon, 8 Jun 2015 22:08:30 +0200 Subject: [PATCH] Emulate transition end event --- js/common.js | 17 +++++++++++++++++ js/popovers.js | 2 ++ js/push.js | 6 ++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/js/common.js b/js/common.js index eb462d5..be745f8 100755 --- a/js/common.js +++ b/js/common.js @@ -54,4 +54,21 @@ return transEndEventNames.transition; })(); + + window.RATCHET.emulateTransitionEnd = function (duration, target) { + var called = false; + target.addEventListener(window.RATCHET.getTransitionEnd, function () { + called = true; + }); + var callback = function () { + if (!called) { + var e = new CustomEvent(window.RATCHET.getTransitionEnd, { + bubbles: true, + cancelable: true + }); + target.dispatchEvent(e); + } + }; + setTimeout(callback, duration); + }; }()); diff --git a/js/popovers.js b/js/popovers.js index dc87b2b..0608cb2 100644 --- a/js/popovers.js +++ b/js/popovers.js @@ -10,6 +10,7 @@ 'use strict'; var popover; + var popoverDuration = 250; var findPopovers = function (target) { var i; @@ -36,6 +37,7 @@ element.addEventListener('touchend', function () { popover.addEventListener(window.RATCHET.getTransitionEnd, onPopoverHidden); + window.RATCHET.emulateTransitionEnd(popoverDuration, popover); popover.classList.remove('visible'); popover.parentNode.removeChild(backdrop); }); diff --git a/js/push.js b/js/push.js index 96dd476..be1069b 100644 --- a/js/push.js +++ b/js/push.js @@ -13,7 +13,7 @@ 'use strict'; var noop = function () {}; - + var pushDuration = 400; // Pushstate caching // ================== @@ -383,6 +383,7 @@ container.removeEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd); swap.classList.add('in'); swap.addEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd); + window.RATCHET.emulateTransitionEnd(pushDuration, swap); }; var fadeSwapEnd = function () { swap.removeEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd); @@ -394,7 +395,7 @@ } }; container.addEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd); - + window.RATCHET.emulateTransitionEnd(pushDuration, swap); } if (/slide/.test(transition)) { @@ -414,6 +415,7 @@ container.classList.add(containerDirection); swap.classList.remove(swapDirection); swap.addEventListener(window.RATCHET.getTransitionEnd, slideEnd); + window.RATCHET.emulateTransitionEnd(pushDuration, swap); } };