mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Add widget.destroy() function (#7468)
This commit is contained in:
parent
120c2f8136
commit
50315310f5
@ -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() {
|
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) {
|
if(this.domNodes.length > 0) {
|
||||||
$tw.utils.each(this.domNodes,function(domNode) {
|
$tw.utils.each(this.domNodes,function(domNode) {
|
||||||
domNode.parentNode.removeChild(domNode);
|
domNode.parentNode.removeChild(domNode);
|
||||||
});
|
});
|
||||||
this.domNodes = [];
|
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.
|
Invoke the action widgets that are descendents of the current widget.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user