1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Add widget.destroy() function (#7468)

This commit is contained in:
buggyj 2023-06-13 16:55:44 +02:00 committed by GitHub
parent 120c2f8136
commit 50315310f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -718,23 +718,44 @@ Widget.prototype.findFirstDomNode = function() {
};
/*
Remove any DOM nodes created by this widget or its children
Entry into destroy procedure
*/
Widget.prototype.destroyChildren = function() {
$tw.utils.each(this.children,function(childWidget) {
childWidget.destroy();
});
};
/*
Legacy entry into destroy procedure
*/
Widget.prototype.removeChildDomNodes = function() {
// 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
this.destroy();
};
/*
Default destroy
*/
Widget.prototype.destroy = function() {
// call children to remove their resources
this.destroyChildren();
// remove our resources
this.children = [];
this.removeLocalDomNodes();
};
/*
Remove any DOM nodes created by this widget
*/
Widget.prototype.removeLocalDomNodes = function() {
// If this widget has directly created DOM nodes, delete them and exit.
if(this.domNodes.length > 0) {
$tw.utils.each(this.domNodes,function(domNode) {
domNode.parentNode.removeChild(domNode);
});
this.domNodes = [];
} else {
// Otherwise, ask the child widgets to delete their DOM nodes
$tw.utils.each(this.children,function(childWidget) {
childWidget.removeChildDomNodes();
});
}
};
/*
Invoke the action widgets that are descendents of the current widget.
*/