From 5ae14a16ec8bc47e8ee62276cd14e8c1b6f9e0b4 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 2 May 2019 21:21:22 +0100 Subject: [PATCH] Classic Storyview: Optimise for animation duration of zero (part 2) See fddc5d4ee --- core/modules/storyviews/classic.js | 120 ++++++++++++++--------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/core/modules/storyviews/classic.js b/core/modules/storyviews/classic.js index a2abe03d4..e5f726f5f 100644 --- a/core/modules/storyviews/classic.js +++ b/core/modules/storyviews/classic.js @@ -41,36 +41,36 @@ ClassicStoryView.prototype.navigateTo = function(historyInfo) { ClassicStoryView.prototype.insert = function(widget) { var duration = $tw.utils.getAnimationDuration(); if(duration) { - var targetElement = widget.findFirstDomNode(); - // Abandon if the list entry isn't a DOM element (it might be a text node) - if(!(targetElement instanceof Element)) { - return; - } - // Get the current height of the tiddler - var computedStyle = window.getComputedStyle(targetElement), - currMarginBottom = parseInt(computedStyle.marginBottom,10), - currMarginTop = parseInt(computedStyle.marginTop,10), - currHeight = targetElement.offsetHeight + currMarginTop; - // Reset the margin once the transition is over - setTimeout(function() { + var targetElement = widget.findFirstDomNode(); + // Abandon if the list entry isn't a DOM element (it might be a text node) + if(!(targetElement instanceof Element)) { + return; + } + // Get the current height of the tiddler + var computedStyle = window.getComputedStyle(targetElement), + currMarginBottom = parseInt(computedStyle.marginBottom,10), + currMarginTop = parseInt(computedStyle.marginTop,10), + currHeight = targetElement.offsetHeight + currMarginTop; + // Reset the margin once the transition is over + setTimeout(function() { + $tw.utils.setStyle(targetElement,[ + {transition: "none"}, + {marginBottom: ""} + ]); + },duration); + // Set up the initial position of the element $tw.utils.setStyle(targetElement,[ {transition: "none"}, - {marginBottom: ""} + {marginBottom: (-currHeight) + "px"}, + {opacity: "0.0"} ]); - },duration); - // Set up the initial position of the element - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {marginBottom: (-currHeight) + "px"}, - {opacity: "0.0"} - ]); - $tw.utils.forceLayout(targetElement); - // Transition to the final position - $tw.utils.setStyle(targetElement,[ - {transition: "opacity " + duration + "ms " + easing + ", " + - "margin-bottom " + duration + "ms " + easing}, - {marginBottom: currMarginBottom + "px"}, - {opacity: "1.0"} + $tw.utils.forceLayout(targetElement); + // Transition to the final position + $tw.utils.setStyle(targetElement,[ + {transition: "opacity " + duration + "ms " + easing + ", " + + "margin-bottom " + duration + "ms " + easing}, + {marginBottom: currMarginBottom + "px"}, + {opacity: "1.0"} ]); } }; @@ -78,39 +78,39 @@ ClassicStoryView.prototype.insert = function(widget) { ClassicStoryView.prototype.remove = function(widget) { var duration = $tw.utils.getAnimationDuration(); if(duration) { - var targetElement = widget.findFirstDomNode(), - removeElement = function() { - widget.removeChildDomNodes(); - }; - // Abandon if the list entry isn't a DOM element (it might be a text node) - if(!(targetElement instanceof Element)) { - removeElement(); - return; - } - // Get the current height of the tiddler - var currWidth = targetElement.offsetWidth, - computedStyle = window.getComputedStyle(targetElement), - currMarginBottom = parseInt(computedStyle.marginBottom,10), - currMarginTop = parseInt(computedStyle.marginTop,10), - currHeight = targetElement.offsetHeight + currMarginTop; - // Remove the dom nodes of the widget at the end of the transition - setTimeout(removeElement,duration); - // Animate the closure - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {transform: "translateX(0px)"}, - {marginBottom: currMarginBottom + "px"}, - {opacity: "1.0"} - ]); - $tw.utils.forceLayout(targetElement); - $tw.utils.setStyle(targetElement,[ - {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms " + easing + ", " + - "opacity " + duration + "ms " + easing + ", " + - "margin-bottom " + duration + "ms " + easing}, - {transform: "translateX(-" + currWidth + "px)"}, - {marginBottom: (-currHeight) + "px"}, - {opacity: "0.0"} - ]); + var targetElement = widget.findFirstDomNode(), + removeElement = function() { + widget.removeChildDomNodes(); + }; + // Abandon if the list entry isn't a DOM element (it might be a text node) + if(!(targetElement instanceof Element)) { + removeElement(); + return; + } + // Get the current height of the tiddler + var currWidth = targetElement.offsetWidth, + computedStyle = window.getComputedStyle(targetElement), + currMarginBottom = parseInt(computedStyle.marginBottom,10), + currMarginTop = parseInt(computedStyle.marginTop,10), + currHeight = targetElement.offsetHeight + currMarginTop; + // Remove the dom nodes of the widget at the end of the transition + setTimeout(removeElement,duration); + // Animate the closure + $tw.utils.setStyle(targetElement,[ + {transition: "none"}, + {transform: "translateX(0px)"}, + {marginBottom: currMarginBottom + "px"}, + {opacity: "1.0"} + ]); + $tw.utils.forceLayout(targetElement); + $tw.utils.setStyle(targetElement,[ + {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms " + easing + ", " + + "opacity " + duration + "ms " + easing + ", " + + "margin-bottom " + duration + "ms " + easing}, + {transform: "translateX(-" + currWidth + "px)"}, + {marginBottom: (-currHeight) + "px"}, + {opacity: "0.0"} + ]); } else { widget.removeChildDomNodes(); }