From 8505d2a7ec27a62df599b960ba320fef41c329eb Mon Sep 17 00:00:00 2001 From: Hayden Moulds Date: Mon, 2 Mar 2020 04:51:08 +1000 Subject: [PATCH] Separate stopOnFocus from close (#37) Even when close is not true, still stop dissappearing on focus Co-authored-by: Varun A P --- src/toastify.js | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/toastify.js b/src/toastify.js index ae53f53..398aca8 100644 --- a/src/toastify.js +++ b/src/toastify.js @@ -127,31 +127,6 @@ }.bind(this) ); - // Clear timeout while toast is focused - if (this.options.stopOnFocus && this.options.duration > 0) { - var self = this; - // stop countdown - divElement.addEventListener( - "mouseover", - function(event) { - window.clearTimeout(divElement.timeOutValue); - } - ) - // add back the timeout - divElement.addEventListener( - "mouseleave", - function() { - divElement.timeOutValue = window.setTimeout( - function() { - // Remove the toast from DOM - self.removeElement(divElement); - }, - self.options.duration - ) - } - ) - } - //Calculating screen width var width = window.innerWidth > 0 ? window.innerWidth : screen.width; @@ -166,6 +141,31 @@ } } + // Clear timeout while toast is focused + if (this.options.stopOnFocus && this.options.duration > 0) { + const self = this; + // stop countdown + divElement.addEventListener( + "mouseover", + function(event) { + window.clearTimeout(divElement.timeOutValue); + } + ) + // add back the timeout + divElement.addEventListener( + "mouseleave", + function() { + divElement.timeOutValue = window.setTimeout( + function() { + // Remove the toast from DOM + self.removeElement(divElement); + }, + self.options.duration + ) + } + ) + } + // Adding an on-click destination path if (typeof this.options.destination !== "undefined") { divElement.addEventListener(