From fc3a81a622f0339a033b2367dbd57a84e1006feb Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 29 Apr 2021 10:01:54 -0700 Subject: [PATCH] Prevent closing modals when mouse drags outside --- data/interfaces/default/js/script.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/interfaces/default/js/script.js b/data/interfaces/default/js/script.js index e2cb82b4..30acfb1b 100644 --- a/data/interfaces/default/js/script.js +++ b/data/interfaces/default/js/script.js @@ -911,3 +911,20 @@ function toggleRevealTokens() { $('body').on('click', '.reveal-token', function() { _toggleRevealToken($(this), true); }); + +// https://stackoverflow.com/a/57414592 +// prevent modal close when click starts in modal and ends on backdrop +$(document).on('mousedown', '.modal', function(e){ + window.clickStartedInModal = $(e.target).is('.modal-dialog *'); +}); +$(document).on('mouseup', '.modal', function(e){ + if(!$(e.target).is('.modal-dialog *') && window.clickStartedInModal) { + window.preventModalClose = true; + } +}); +$('.modal').on('hide.bs.modal', function (e) { + if(window.preventModalClose){ + window.preventModalClose = false; + return false; + } +});