From b3bbf9f0a9daaef2e089ee880301489486516299 Mon Sep 17 00:00:00 2001 From: buggyj Date: Tue, 24 Jan 2023 22:43:43 +0100 Subject: [PATCH 1/3] adds depth first destroy --- core/modules/widgets/widget.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 60f55e8bb..85462979b 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -596,6 +596,24 @@ Widget.prototype.findFirstDomNode = function() { return null; }; + + +/* +Depth first destroy +*/ +Widget.prototype.desendDestroy = function() { + this.waitDestroy = true; //for blocking repeat calls to this method from removeChildDomNodes + $tw.utils.each(this.children,function(childWidget) { + childWidget.desendDestroy(); + }); + + if (this.destroy) { + this.destroy(); + } + this.waitDestroy = false; +}; + +Widget.prototype.waitDestroy = false; /* Remove any DOM nodes created by this widget or its children */ @@ -612,6 +630,7 @@ Widget.prototype.removeChildDomNodes = function() { childWidget.removeChildDomNodes(); }); } + if (!this.waitDestroy) this.desendDestroy(); }; /* From b751beee19060eeddb51b348022f9a82b6ba79cf Mon Sep 17 00:00:00 2001 From: buggyj Date: Wed, 25 Jan 2023 15:27:39 +0100 Subject: [PATCH 2/3] fixed multiple invokes of desendDestroy --- core/modules/widgets/widget.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 85462979b..f6d4fe329 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -617,7 +617,7 @@ Widget.prototype.waitDestroy = false; /* Remove any DOM nodes created by this widget or its children */ -Widget.prototype.removeChildDomNodes = function() { +Widget.prototype.removeChildDomNodes = function(noDestroy) { // If this widget has directly created DOM nodes, delete them and exit. This assumes that any child widgets are contained within the created DOM nodes, which would normally be the case if(this.domNodes.length > 0) { $tw.utils.each(this.domNodes,function(domNode) { @@ -627,10 +627,10 @@ Widget.prototype.removeChildDomNodes = function() { } else { // Otherwise, ask the child widgets to delete their DOM nodes $tw.utils.each(this.children,function(childWidget) { - childWidget.removeChildDomNodes(); + childWidget.removeChildDomNodes(true); }); } - if (!this.waitDestroy) this.desendDestroy(); + if (!noDestroy && !this.waitDestroy) this.desendDestroy(); }; /* From 749eb13dda65efa1cea04c469e6e3247862da3fc Mon Sep 17 00:00:00 2001 From: buggyj Date: Thu, 26 Jan 2023 10:21:51 +0100 Subject: [PATCH 3/3] rewritten to avoid double negative --- core/modules/widgets/widget.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index f6d4fe329..32d4e2013 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -615,10 +615,11 @@ Widget.prototype.desendDestroy = function() { Widget.prototype.waitDestroy = false; /* -Remove any DOM nodes created by this widget or its children +Remove any DOM nodes created by this widget or its children, and start destroy procedure */ -Widget.prototype.removeChildDomNodes = function(noDestroy) { - // If this widget has directly created DOM nodes, delete them and exit. This assumes that any child widgets are contained within the created DOM nodes, which would normally be the case +Widget.prototype.removeChildDomNodes = function(destroy) { + var destroy = (destroy !== undefined ? destroy : true); + // If this widget has directly created DOM nodes, delete them. This assumes that any child widgets are contained within the created DOM nodes, which would normally be the case if(this.domNodes.length > 0) { $tw.utils.each(this.domNodes,function(domNode) { domNode.parentNode.removeChild(domNode); @@ -627,10 +628,10 @@ Widget.prototype.removeChildDomNodes = function(noDestroy) { } else { // Otherwise, ask the child widgets to delete their DOM nodes $tw.utils.each(this.children,function(childWidget) { - childWidget.removeChildDomNodes(true); + childWidget.removeChildDomNodes(false); }); - } - if (!noDestroy && !this.waitDestroy) this.desendDestroy(); + } + if (destroy && !this.waitDestroy) this.desendDestroy(); }; /*