From ee33cbbc2e6fee89c78462f3d48006d0ef231120 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 29 Aug 2013 12:43:24 +0100 Subject: [PATCH] Fix up some problems when the animation duration is zero We want to be able to suppress animations by making the duration zero --- core/modules/utils/dom/modal.js | 9 ++++----- core/modules/utils/dom/notifier.js | 4 ++-- core/modules/utils/dom/scroller.js | 9 +++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js index 20789b1ef..210a8cb48 100644 --- a/core/modules/utils/dom/modal.js +++ b/core/modules/utils/dom/modal.js @@ -42,8 +42,7 @@ Modal.prototype.display = function(title,options) { modalFooter = document.createElement("div"), modalFooterHelp = document.createElement("span"), modalFooterButtons = document.createElement("span"), - tiddler = this.wiki.getTiddler(title), - d = duration + "ms"; + tiddler = this.wiki.getTiddler(title); // Don't do anything if the tiddler doesn't exist if(!tiddler) { return; @@ -130,12 +129,12 @@ Modal.prototype.display = function(title,options) { {transform: "translateY(" + window.innerHeight + "px)"} ]); // Set up an event for the transition end - modalWrapper.addEventListener($tw.utils.convertEventName("transitionEnd"),function(event) { + window.setTimeout(function() { if(wrapper.parentNode) { // Remove the modal message from the DOM document.body.removeChild(wrapper); } - },false); + },duration); // Don't let anyone else handle the tw-close-tiddler message event.stopPropagation(); return false; @@ -152,7 +151,7 @@ Modal.prototype.display = function(title,options) { document.body.appendChild(wrapper); // Set up animation for the styles $tw.utils.setStyle(modalBackdrop,[ - {transition: "opacity " + d + " ease-out"} + {transition: "opacity " + duration + "ms ease-out"} ]); $tw.utils.setStyle(modalWrapper,[ {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out"} diff --git a/core/modules/utils/dom/notifier.js b/core/modules/utils/dom/notifier.js index b9177b533..9f2fb3588 100644 --- a/core/modules/utils/dom/notifier.js +++ b/core/modules/utils/dom/notifier.js @@ -27,7 +27,7 @@ Notifier.prototype.display = function(title,options) { // Create the wrapper divs var notification = document.createElement("div"), tiddler = this.wiki.getTiddler(title), - d = $tw.utils.getAnimationDuration() + "ms"; + duration = $tw.utils.getAnimationDuration(); // Don't do anything if the tiddler doesn't exist if(!tiddler) { return; @@ -47,7 +47,7 @@ Notifier.prototype.display = function(title,options) { {opacity: "0"}, {transformOrigin: "0% 0%"}, {transform: "translateY(" + (-window.innerHeight) + "px)"}, - {transition: "opacity " + d + " ease-out, " + $tw.utils.roundTripPropertyName("transform") + " " + d + " ease-in-out"} + {transition: "opacity " + duration + "ms ease-out, " + $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out"} ]); // Add the notification to the DOM document.body.appendChild(notification); diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 74178f5e2..2b087e3fa 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -54,7 +54,7 @@ PageScroller.prototype.handleEvent = function(event) { Handle a scroll event hitting the page document */ PageScroller.prototype.scrollIntoView = function(element) { - var duration = $tw.utils.getAnimationDuration() + var duration = $tw.utils.getAnimationDuration(); // Get the offset bounds of the element var bounds = { left: element.offsetLeft, @@ -95,7 +95,12 @@ PageScroller.prototype.scrollIntoView = function(element) { var self = this, drawFrame; drawFrame = function () { - var t = ((new Date()) - self.startTime) / duration; + var t; + if(duration <= 0) { + t = 1; + } else { + t = ((new Date()) - self.startTime) / duration; + } if(t >= 1) { self.cancelScroll(); t = 1;