MDL-69166 core_form: allow modals to prevent closing on accidental click
authorMarina Glancy <marina@moodle.com>
Fri, 17 Jan 2020 13:25:53 +0000 (00:25 +1100)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 04:44:59 +0000 (15:44 +1100)
lib/amd/build/modal.min.js
lib/amd/build/modal.min.js.map
lib/amd/build/modal_events.min.js
lib/amd/build/modal_events.min.js.map
lib/amd/src/modal.js
lib/amd/src/modal_events.js

index 530e371..1374a94 100644 (file)
Binary files a/lib/amd/build/modal.min.js and b/lib/amd/build/modal.min.js differ
index 7935256..3b050c2 100644 (file)
Binary files a/lib/amd/build/modal.min.js.map and b/lib/amd/build/modal.min.js.map differ
index ca97402..ad3019a 100644 (file)
Binary files a/lib/amd/build/modal_events.min.js and b/lib/amd/build/modal_events.min.js differ
index d7749db..eb37ddd 100644 (file)
Binary files a/lib/amd/build/modal_events.min.js.map and b/lib/amd/build/modal_events.min.js.map differ
index 823adcd..37ce574 100644 (file)
@@ -780,7 +780,12 @@ define([
                 // So, we check if we can still find the container element or not. If not, then the DOM tree is changed.
                 // It's best not to hide the modal in that case.
                 if ($(e.target).closest(SELECTORS.CONTAINER).length) {
-                    this.hideIfNotForm();
+                    var outsideClickEvent = $.Event(ModalEvents.outsideClick);
+                    this.getRoot().trigger(outsideClickEvent, this);
+
+                    if (!outsideClickEvent.isDefaultPrevented()) {
+                        this.hideIfNotForm();
+                    }
                 }
             }
         }.bind(this));
index 234d3d7..b57d504 100644 (file)
@@ -29,6 +29,7 @@ define([], function() {
         hidden: 'modal:hidden',
         destroyed: 'modal:destroyed',
         bodyRendered: 'modal:bodyRendered',
+        outsideClick: 'modal:outsideClick',
         // ModalSaveCancel events.
         save: 'modal-save-cancel:save',
         cancel: 'modal-save-cancel:cancel',