From 22e2cfe999e66ddff406d7c4196ed5b01aac7cec Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Wed, 27 Jul 2022 12:51:57 +0200 Subject: [PATCH 1/2] OnHover function --- demos/js/jquery.toast.js | 13 +++++++++---- src/jquery.toast.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/demos/js/jquery.toast.js b/demos/js/jquery.toast.js index 77cdf45..9a682e8 100644 --- a/demos/js/jquery.toast.js +++ b/demos/js/jquery.toast.js @@ -279,9 +279,7 @@ if ( typeof Object.create !== 'function' ) { if (this.canAutoHide()) { var that = this; - - window.setTimeout(function(){ - + var hideFunction = function (){ if ( that.options.showHideTransition.toLowerCase() === 'fade' ) { that._toastEl.trigger('beforeHide'); that._toastEl.fadeOut(function () { @@ -298,8 +296,15 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.trigger('afterHidden'); }); } + } + + var timer = window.setTimeout(hideFunction, this.options.hideAfter); - }, this.options.hideAfter); + that._toastEl.hover(() => { + clearTimeout(timer); + }, () => { + window.setTimeout(hideFunction, this.options.hideAfter); + }) }; }, diff --git a/src/jquery.toast.js b/src/jquery.toast.js index 1563986..ef4f94e 100644 --- a/src/jquery.toast.js +++ b/src/jquery.toast.js @@ -285,9 +285,7 @@ if ( typeof Object.create !== 'function' ) { if (this.canAutoHide()) { var that = this; - - window.setTimeout(function(){ - + var hideFunction = function (){ if ( that.options.showHideTransition.toLowerCase() === 'fade' ) { that._toastEl.trigger('beforeHide'); that._toastEl.fadeOut(function () { @@ -304,8 +302,15 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.trigger('afterHidden'); }); } + } + + var timer = window.setTimeout(hideFunction, this.options.hideAfter); - }, this.options.hideAfter); + that._toastEl.hover(() => { + clearTimeout(timer); + }, () => { + window.setTimeout(hideFunction, this.options.hideAfter); + }) }; }, From 12e843a985e470ff9cc5194b318fc20a0ea6b5de Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 2 Aug 2022 22:57:39 +0200 Subject: [PATCH 2/2] Update --- .vscode/launch.json | 15 +++++++++++++++ demos/js/jquery.toast.js | 2 +- src/jquery.toast.js | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a9dfa0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/demos/js/jquery.toast.js b/demos/js/jquery.toast.js index 9a682e8..8f29af2 100644 --- a/demos/js/jquery.toast.js +++ b/demos/js/jquery.toast.js @@ -303,7 +303,7 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.hover(() => { clearTimeout(timer); }, () => { - window.setTimeout(hideFunction, this.options.hideAfter); + timer = window.setTimeout(hideFunction, this.options.hideAfter); }) }; }, diff --git a/src/jquery.toast.js b/src/jquery.toast.js index ef4f94e..5ae90bc 100644 --- a/src/jquery.toast.js +++ b/src/jquery.toast.js @@ -309,7 +309,7 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.hover(() => { clearTimeout(timer); }, () => { - window.setTimeout(hideFunction, this.options.hideAfter); + timer = window.setTimeout(hideFunction, this.options.hideAfter); }) }; },