MDL-67513 core: Only move modal to body if currently attached
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 16 Nov 2020 07:19:28 +0000 (15:19 +0800)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 16 Nov 2020 08:37:48 +0000 (09:37 +0100)
A previous change as part of this commitset was intended to move the
modal to the document.body, but where the modal had been destroyed it
was instead added back to the body.

lib/amd/build/modal.min.js
lib/amd/build/modal.min.js.map
lib/amd/build/modal_backdrop.min.js
lib/amd/build/modal_backdrop.min.js.map
lib/amd/src/modal.js
lib/amd/src/modal_backdrop.js

index 5aef006..91677e8 100644 (file)
Binary files a/lib/amd/build/modal.min.js and b/lib/amd/build/modal.min.js differ
index 11c184f..e330a08 100644 (file)
Binary files a/lib/amd/build/modal.min.js.map and b/lib/amd/build/modal.min.js.map differ
index ec09403..1778e05 100644 (file)
Binary files a/lib/amd/build/modal_backdrop.min.js and b/lib/amd/build/modal_backdrop.min.js differ
index 27718d9..df2f559 100644 (file)
Binary files a/lib/amd/build/modal_backdrop.min.js.map and b/lib/amd/build/modal_backdrop.min.js.map differ
index 3ca46d8..118d679 100644 (file)
@@ -735,8 +735,10 @@ define([
                 this.getRoot().removeClass('show').addClass('hide');
             }
 
                 this.getRoot().removeClass('show').addClass('hide');
             }
 
-            // Ensure the modal is moved onto the body node.
-            $(document.body).append(this.getRoot());
+            // Ensure the modal is moved onto the body node if it is still attached to the DOM.
+            if ($(document.body).find(this.getRoot()).length) {
+                $(document.body).append(this.getRoot());
+            }
 
             this.root.trigger(ModalEvents.hidden, this);
         }.bind(this));
 
             this.root.trigger(ModalEvents.hidden, this);
         }.bind(this));
index 9cc7448..1cbc1fd 100644 (file)
@@ -142,8 +142,10 @@ define(['jquery', 'core/templates', 'core/notification', 'core/fullscreen'],
             this.getRoot().removeClass('show').addClass('hide');
         }
 
             this.getRoot().removeClass('show').addClass('hide');
         }
 
-        // Ensure the modal is moved back onto the body node.
-        $(document.body).append(this.getRoot());
+        // Ensure the modal is moved onto the body node if it is still attached to the DOM.
+        if ($(document.body).find(this.getRoot()).length) {
+            $(document.body).append(this.getRoot());
+        }
     };
 
     /**
     };
 
     /**