From 91dfe87b0fcebc4e69a7784ae411e35d0db94a45 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Sun, 12 Mar 2017 21:21:54 -0400 Subject: [PATCH] Fixes #4479 - Approve/deny callbacks can occur multiple times if clicked quickly --- RELEASE-NOTES.md | 1 + src/definitions/modules/modal.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 63701c236..f7083591a 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -10,6 +10,7 @@ - **Button** - Fixes `@basicActiveBoxShadow` being used incorrectly in basic button variables - **Visibility** - Fixes issue where visibility events would occur improperly when using a `context` that have `overflow-x` or `overflow-y` set to `auto` - **Dropdown** - Fixes an issue where dropdown would not correctly open `upward` at bottom edge of the screen when using a `context` with `overflow-x` or `overflow-y` set to `auto` +- **Modal** - `onDeny` and `onApprove` callbacks can no longer occur multiple times if you rapidly click a approve/deny button in a modal. #4479 ### Version 2.2.10 - February 21, 2017 diff --git a/src/definitions/modules/modal.js b/src/definitions/modules/modal.js index b8c32f5a6..9de8673de 100644 --- a/src/definitions/modules/modal.js +++ b/src/definitions/modules/modal.js @@ -72,6 +72,8 @@ $.fn.modal = function(parameters) { element = this, instance = $module.data(moduleNamespace), + ignoreRepeatedEvents = false, + elementEventNamespace, id, observer, @@ -226,18 +228,24 @@ $.fn.modal = function(parameters) { event: { approve: function() { - if(settings.onApprove.call(element, $(this)) === false) { + if(ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) { module.verbose('Approve callback returned false cancelling hide'); return; } - module.hide(); + ignoreRepeatedEvents = true; + module.hide(function() { + ignoreRepeatedEvents = false; + }); }, deny: function() { - if(settings.onDeny.call(element, $(this)) === false) { + if(ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) { module.verbose('Deny callback returned false cancelling hide'); return; } - module.hide(); + ignoreRepeatedEvents = true; + module.hide(function() { + ignoreRepeatedEvents = false; + }); }, close: function() { module.hide();