From 5557f3c420e22fc421bc75389efdea76d9b0c79b Mon Sep 17 00:00:00 2001 From: iamdevlinph Date: Fri, 15 Mar 2019 17:57:37 +0800 Subject: [PATCH 1/5] rm whitespaces --- toastr.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/toastr.js b/toastr.js index f48cb73..2406fd2 100644 --- a/toastr.js +++ b/toastr.js @@ -121,14 +121,14 @@ // internal functions - function clearContainer (options) { + function clearContainer(options) { var toastsToClear = $container.children(); for (var i = toastsToClear.length - 1; i >= 0; i--) { clearToast($(toastsToClear[i]), options); } } - function clearToast ($toastElement, options, clearOptions) { + function clearToast($toastElement, options, clearOptions) { var force = clearOptions && clearOptions.force ? clearOptions.force : false; if ($toastElement && (force || $(':focus', $toastElement).length === 0)) { $toastElement[options.hideMethod]({ @@ -276,7 +276,7 @@ switch (map.iconClass) { case 'toast-success': case 'toast-info': - ariaValue = 'polite'; + ariaValue = 'polite'; break; default: ariaValue = 'assertive'; @@ -321,7 +321,7 @@ $toastElement.hide(); $toastElement[options.showMethod]( - {duration: options.showDuration, easing: options.showEasing, complete: options.onShown} + { duration: options.showDuration, easing: options.showEasing, complete: options.onShown } ); if (options.timeOut > 0) { @@ -438,7 +438,7 @@ clearTimeout(intervalId); progressBar.hideEta = 0; $toastElement.stop(true, true)[options.showMethod]( - {duration: options.showDuration, easing: options.showEasing} + { duration: options.showDuration, easing: options.showEasing } ); } From 40b90af16d6b997ee61f90db67476f889ecf9a95 Mon Sep 17 00:00:00 2001 From: iamdevlinph Date: Fri, 15 Mar 2019 18:02:14 +0800 Subject: [PATCH 2/5] Fix issue where default closeClass is not applied --- toastr.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/toastr.js b/toastr.js index 2406fd2..04a07c2 100644 --- a/toastr.js +++ b/toastr.js @@ -17,6 +17,7 @@ var $container; var listener; var toastId = 0; + var closeClass = 'toast-close-button'; var toastType = { error: 'error', info: 'info', @@ -185,7 +186,7 @@ escapeHtml: false, target: 'body', closeHtml: '', - closeClass: 'toast-close-button', + closeClass: closeClass, newestOnTop: true, preventDuplicates: false, progressBar: false, @@ -372,7 +373,7 @@ function setCloseButton() { if (options.closeButton) { - $closeElement.addClass(options.closeClass).attr('role', 'button'); + $closeElement.addClass(closeClass).attr('role', 'button'); $toastElement.prepend($closeElement); } } From 162888bb1bfe397df3d1c9e67d8000fe4f2adcc9 Mon Sep 17 00:00:00 2001 From: iamdevlinph Date: Fri, 15 Mar 2019 18:03:56 +0800 Subject: [PATCH 3/5] Typos in readme --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6c74bb7..8ec18d4 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ npm install --save toastr ## Breaking Changes -####Animation Changes +#### Animation Changes The following animations options have been deprecated and should be replaced: - Replace `options.fadeIn` with `options.showDuration` @@ -132,7 +132,7 @@ toastr.options.onCloseClick = function() { console.log('close button clicked'); ### Animation Options Toastr will supply default animations, so you do not have to provide any of these settings. However you have the option to override the animations if you like. -####Easings +#### Easings Optionally override the animation easing to show or hide the toasts. Default is swing. swing and linear are built into jQuery. ```js toastr.options.showEasing = 'swing'; @@ -147,7 +147,7 @@ toastr.options.hideEasing = 'easeInBack'; toastr.options.closeEasing = 'easeInBack'; ``` -####Animation Method +#### Animation Method Use the jQuery show/hide method of your choice. These default to fadeIn/fadeOut. The methods fadeIn/fadeOut, slideDown/slideUp, and show/hide are built into jQuery. ```js toastr.options.showMethod = 'slideDown'; @@ -155,13 +155,13 @@ toastr.options.hideMethod = 'slideUp'; toastr.options.closeMethod = 'slideUp'; ``` -###Prevent Duplicates +### Prevent Duplicates Rather than having identical toasts stack, set the preventDuplicates property to true. Duplicates are matched to the previous toast based on their message content. ```js toastr.options.preventDuplicates = true; ``` -###Timeouts +### Timeouts Control how toastr interacts with users by setting timeouts appropriately. Timeouts can be disabled by setting them to 0. ```js toastr.options.timeOut = 30; // How long the toast will display without user interaction @@ -169,7 +169,7 @@ toastr.options.extendedTimeOut = 60; // How long the toast will display after a ``` -###Progress Bar +### Progress Bar Visually indicate how long before a toast expires. ```js toastr.options.progressBar = true; @@ -178,7 +178,7 @@ toastr.options.progressBar = true; ### rtl Flip the toastr to be displayed properly for right-to-left languages. ```js -toastr.options.rtl = true; +toastr.options.rtl = true; ``` ## Building Toastr From a91dd2533396d65fec446f7c5960c29c0a9a4175 Mon Sep 17 00:00:00 2001 From: iamdevlinph Date: Fri, 15 Mar 2019 18:06:04 +0800 Subject: [PATCH 4/5] New option: onCloseClickNoOnHidden --- README.md | 7 +++++++ toastr.js | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ec18d4..e505632 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,13 @@ toastr.options.onclick = function() { console.log('clicked'); } toastr.options.onCloseClick = function() { console.log('close button clicked'); } ``` +#### Prevent onHidden from onCloseClick +``` +toastr.options.onCloseClickNoOnHidden = true; +``` + +When true, prevents the execution of `onHidden`. This is useful when you have a different flow when user manually clicks on the close button and when the toastr fades away automatically. + ### Animation Options Toastr will supply default animations, so you do not have to provide any of these settings. However you have the option to override the animations if you like. diff --git a/toastr.js b/toastr.js index 04a07c2..5c2d5ef 100644 --- a/toastr.js +++ b/toastr.js @@ -18,6 +18,7 @@ var listener; var toastId = 0; var closeClass = 'toast-close-button'; + var userClickedCloseBtn = false; var toastType = { error: 'error', info: 'info', @@ -304,6 +305,7 @@ if (options.onCloseClick) { options.onCloseClick(event); + userClickedCloseBtn = true; } hideToast(true); @@ -417,7 +419,7 @@ complete: function () { removeToast($toastElement); clearTimeout(intervalId); - if (options.onHidden && response.state !== 'hidden') { + if (options.onHidden && response.state !== 'hidden' && !(options.onCloseClickNoOnHidden && userClickedCloseBtn)) { options.onHidden(); } response.state = 'hidden'; From 4f36e9210f0b883cf8221670d5d66098377f917b Mon Sep 17 00:00:00 2001 From: iamdevlinph Date: Tue, 21 May 2019 17:21:25 +0800 Subject: [PATCH 5/5] Reset default on new instance --- .vscode/settings.json | 3 +++ toastr.js | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..895dbb6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.tabSize": 4, +} diff --git a/toastr.js b/toastr.js index 5c2d5ef..93c17c9 100644 --- a/toastr.js +++ b/toastr.js @@ -235,6 +235,8 @@ map: map }; + resetDefaults(); + personalizeToast(); displayToast(); @@ -262,6 +264,10 @@ .replace(/>/g, '>'); } + function resetDefaults() { + userClickedCloseBtn = false; + } + function personalizeToast() { setIcon(); setTitle();