Browse Source

Emulate transition end event

pull/782/head
Johann-S 10 years ago
parent
commit
71b6d35be1
  1. 17
      js/common.js
  2. 2
      js/popovers.js
  3. 6
      js/push.js

17
js/common.js

@ -54,4 +54,21 @@
return transEndEventNames.transition; 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);
};
}()); }());

2
js/popovers.js

@ -10,6 +10,7 @@
'use strict'; 'use strict';
var popover; var popover;
var popoverDuration = 250;
var findPopovers = function (target) { var findPopovers = function (target) {
var i; var i;
@ -36,6 +37,7 @@
element.addEventListener('touchend', function () { element.addEventListener('touchend', function () {
popover.addEventListener(window.RATCHET.getTransitionEnd, onPopoverHidden); popover.addEventListener(window.RATCHET.getTransitionEnd, onPopoverHidden);
window.RATCHET.emulateTransitionEnd(popoverDuration, popover);
popover.classList.remove('visible'); popover.classList.remove('visible');
popover.parentNode.removeChild(backdrop); popover.parentNode.removeChild(backdrop);
}); });

6
js/push.js

@ -13,7 +13,7 @@
'use strict'; 'use strict';
var noop = function () {}; var noop = function () {};
var pushDuration = 400;
// Pushstate caching // Pushstate caching
// ================== // ==================
@ -383,6 +383,7 @@
container.removeEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd); container.removeEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd);
swap.classList.add('in'); swap.classList.add('in');
swap.addEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd); swap.addEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd);
window.RATCHET.emulateTransitionEnd(pushDuration, swap);
}; };
var fadeSwapEnd = function () { var fadeSwapEnd = function () {
swap.removeEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd); swap.removeEventListener(window.RATCHET.getTransitionEnd, fadeSwapEnd);
@ -394,7 +395,7 @@
} }
}; };
container.addEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd); container.addEventListener(window.RATCHET.getTransitionEnd, fadeContainerEnd);
window.RATCHET.emulateTransitionEnd(pushDuration, swap);
} }
if (/slide/.test(transition)) { if (/slide/.test(transition)) {
@ -414,6 +415,7 @@
container.classList.add(containerDirection); container.classList.add(containerDirection);
swap.classList.remove(swapDirection); swap.classList.remove(swapDirection);
swap.addEventListener(window.RATCHET.getTransitionEnd, slideEnd); swap.addEventListener(window.RATCHET.getTransitionEnd, slideEnd);
window.RATCHET.emulateTransitionEnd(pushDuration, swap);
} }
}; };

Loading…
Cancel
Save