From 6f1c9d88ccbf0dc5ebc5f931f665adfc03998a2f Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 9 Nov 2013 16:55:14 +0000 Subject: [PATCH] Improve the Widget.prototype.removeChildDomNodes() method so that most subclasses won't need to override it --- core/modules/widgets/browse.js | 10 ---------- core/modules/widgets/button.js | 10 ---------- core/modules/widgets/checkbox.js | 10 ---------- core/modules/widgets/count.js | 10 ---------- core/modules/widgets/dropzone.js | 10 ---------- core/modules/widgets/edit-bitmap.js | 10 ---------- core/modules/widgets/edit-text.js | 10 ---------- core/modules/widgets/element.js | 10 ---------- core/modules/widgets/encrypt.js | 10 ---------- core/modules/widgets/entity.js | 10 ---------- core/modules/widgets/fields.js | 10 ---------- core/modules/widgets/link.js | 10 ---------- core/modules/widgets/password.js | 10 ---------- core/modules/widgets/reveal.js | 10 ---------- core/modules/widgets/text.js | 10 ---------- core/modules/widgets/view.js | 10 ---------- core/modules/widgets/widget.js | 15 ++++++++++++--- plugins/tiddlywiki/d3/barwidget.js | 10 ---------- plugins/tiddlywiki/d3/cloudwidget.js | 10 ---------- 19 files changed, 12 insertions(+), 183 deletions(-) diff --git a/core/modules/widgets/browse.js b/core/modules/widgets/browse.js index b79c96ea2..66a68f2a7 100644 --- a/core/modules/widgets/browse.js +++ b/core/modules/widgets/browse.js @@ -63,16 +63,6 @@ BrowseWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget or its children -*/ -BrowseWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.browse = BrowseWidget; })(); diff --git a/core/modules/widgets/button.js b/core/modules/widgets/button.js index 77b6808f9..1682e275e 100644 --- a/core/modules/widgets/button.js +++ b/core/modules/widgets/button.js @@ -136,16 +136,6 @@ ButtonWidget.prototype.refresh = function(changedTiddlers) { return this.refreshChildren(changedTiddlers); }; -/* -Remove any DOM nodes created by this widget or its children -*/ -ButtonWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.button = ButtonWidget; })(); diff --git a/core/modules/widgets/checkbox.js b/core/modules/widgets/checkbox.js index 969b5961e..6f32afdd7 100644 --- a/core/modules/widgets/checkbox.js +++ b/core/modules/widgets/checkbox.js @@ -103,16 +103,6 @@ CheckboxWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Remove any DOM nodes created by this widget or its children -*/ -CheckboxWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.checkbox = CheckboxWidget; })(); diff --git a/core/modules/widgets/count.js b/core/modules/widgets/count.js index 678875f41..1be0aa5e1 100644 --- a/core/modules/widgets/count.js +++ b/core/modules/widgets/count.js @@ -66,16 +66,6 @@ CountWidget.prototype.refresh = function(changedTiddlers) { }; -/* -Remove any DOM nodes created by this widget -*/ -CountWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.count = CountWidget; })(); diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index fa2521cb3..f86ecc9f7 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -175,16 +175,6 @@ DropZoneWidget.prototype.refresh = function(changedTiddlers) { return this.refreshChildren(changedTiddlers); }; -/* -Remove any DOM nodes created by this widget or its children -*/ -DropZoneWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.dropzone = DropZoneWidget; })(); diff --git a/core/modules/widgets/edit-bitmap.js b/core/modules/widgets/edit-bitmap.js index 8707fe59a..40f0e81aa 100644 --- a/core/modules/widgets/edit-bitmap.js +++ b/core/modules/widgets/edit-bitmap.js @@ -94,16 +94,6 @@ EditBitmapWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget or its children -*/ -EditBitmapWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - EditBitmapWidget.prototype.loadCanvas = function() { var tiddler = this.wiki.getTiddler(this.editTitle), currImage = new Image(); diff --git a/core/modules/widgets/edit-text.js b/core/modules/widgets/edit-text.js index 52975e713..468efd0ac 100644 --- a/core/modules/widgets/edit-text.js +++ b/core/modules/widgets/edit-text.js @@ -247,16 +247,6 @@ EditTextWidget.prototype.saveChanges = function(text) { } }; -/* -Remove any DOM nodes created by this widget or its children -*/ -EditTextWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports["edit-text"] = EditTextWidget; })(); diff --git a/core/modules/widgets/element.js b/core/modules/widgets/element.js index a2c3a1df4..b77bab5ed 100755 --- a/core/modules/widgets/element.js +++ b/core/modules/widgets/element.js @@ -70,16 +70,6 @@ ElementWidget.prototype.refresh = function(changedTiddlers) { return this.refreshChildren(changedTiddlers) || hasChangedAttributes; }; -/* -Remove any DOM nodes created by this widget or its children -*/ -ElementWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.element = ElementWidget; })(); diff --git a/core/modules/widgets/encrypt.js b/core/modules/widgets/encrypt.js index 9759f0d37..3937cd4b8 100644 --- a/core/modules/widgets/encrypt.js +++ b/core/modules/widgets/encrypt.js @@ -70,16 +70,6 @@ EncryptWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Remove any DOM nodes created by this widget -*/ -EncryptWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.encrypt = EncryptWidget; })(); diff --git a/core/modules/widgets/entity.js b/core/modules/widgets/entity.js index 0571eafd2..7e2b9dc66 100755 --- a/core/modules/widgets/entity.js +++ b/core/modules/widgets/entity.js @@ -47,16 +47,6 @@ EntityWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget -*/ -EntityWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.entity = EntityWidget; })(); diff --git a/core/modules/widgets/fields.js b/core/modules/widgets/fields.js index 9ac828dc1..aaa9761b6 100755 --- a/core/modules/widgets/fields.js +++ b/core/modules/widgets/fields.js @@ -98,16 +98,6 @@ FieldsWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Remove any DOM nodes created by this widget -*/ -FieldsWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.fields = FieldsWidget; })(); diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index 5b61d8048..48dc79e10 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -169,16 +169,6 @@ LinkWidget.prototype.refresh = function(changedTiddlers) { return this.refreshChildren(changedTiddlers); }; -/* -Remove any DOM nodes created by this widget or its children -*/ -LinkWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.link = LinkWidget; })(); diff --git a/core/modules/widgets/password.js b/core/modules/widgets/password.js index 3b88d06da..e50f308ed 100644 --- a/core/modules/widgets/password.js +++ b/core/modules/widgets/password.js @@ -77,16 +77,6 @@ PasswordWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Remove any DOM nodes created by this widget or its children -*/ -PasswordWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.password = PasswordWidget; })(); diff --git a/core/modules/widgets/reveal.js b/core/modules/widgets/reveal.js index 84f7f4a5b..45049df52 100755 --- a/core/modules/widgets/reveal.js +++ b/core/modules/widgets/reveal.js @@ -190,16 +190,6 @@ RevealWidget.prototype.updateState = function() { } }; -/* -Remove any DOM nodes created by this widget or its children -*/ -RevealWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.reveal = RevealWidget; })(); diff --git a/core/modules/widgets/text.js b/core/modules/widgets/text.js index 5c40c2f8c..7d92e9822 100755 --- a/core/modules/widgets/text.js +++ b/core/modules/widgets/text.js @@ -48,16 +48,6 @@ TextNodeWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget -*/ -TextNodeWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.text = TextNodeWidget; })(); diff --git a/core/modules/widgets/view.js b/core/modules/widgets/view.js index db6f4a2a7..7398a7da8 100755 --- a/core/modules/widgets/view.js +++ b/core/modules/widgets/view.js @@ -170,16 +170,6 @@ ViewWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Remove any DOM nodes created by this widget -*/ -ViewWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.view = ViewWidget; })(); diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index bc2159716..d65fcf002 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -450,9 +450,18 @@ Widget.prototype.findFirstDomNode = function() { Remove any DOM nodes created by this widget or its children */ Widget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.children,function(childWidget) { - childWidget.removeChildDomNodes(); - }); + // 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) { + 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(); + }); + } }; exports.widget = Widget; diff --git a/plugins/tiddlywiki/d3/barwidget.js b/plugins/tiddlywiki/d3/barwidget.js index e27000919..e6562a086 100644 --- a/plugins/tiddlywiki/d3/barwidget.js +++ b/plugins/tiddlywiki/d3/barwidget.js @@ -199,16 +199,6 @@ BarWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget or its children -*/ -BarWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.d3bar = BarWidget; })(); diff --git a/plugins/tiddlywiki/d3/cloudwidget.js b/plugins/tiddlywiki/d3/cloudwidget.js index d8d4ea4ef..6726a9252 100644 --- a/plugins/tiddlywiki/d3/cloudwidget.js +++ b/plugins/tiddlywiki/d3/cloudwidget.js @@ -128,16 +128,6 @@ CloudWidget.prototype.refresh = function(changedTiddlers) { return false; }; -/* -Remove any DOM nodes created by this widget or its children -*/ -CloudWidget.prototype.removeChildDomNodes = function() { - $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); - }); - this.domNodes = []; -}; - exports.d3cloud = CloudWidget; })();