1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Improve the Widget.prototype.removeChildDomNodes() method so that most subclasses won't need to override it

This commit is contained in:
Jermolene 2013-11-09 16:55:14 +00:00
parent e2d7c7aea5
commit 6f1c9d88cc
19 changed files with 12 additions and 183 deletions

View File

@ -63,16 +63,6 @@ BrowseWidget.prototype.refresh = function(changedTiddlers) {
return false; 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; exports.browse = BrowseWidget;
})(); })();

View File

@ -136,16 +136,6 @@ ButtonWidget.prototype.refresh = function(changedTiddlers) {
return this.refreshChildren(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; exports.button = ButtonWidget;
})(); })();

View File

@ -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; exports.checkbox = CheckboxWidget;
})(); })();

View File

@ -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; exports.count = CountWidget;
})(); })();

View File

@ -175,16 +175,6 @@ DropZoneWidget.prototype.refresh = function(changedTiddlers) {
return this.refreshChildren(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; exports.dropzone = DropZoneWidget;
})(); })();

View File

@ -94,16 +94,6 @@ EditBitmapWidget.prototype.refresh = function(changedTiddlers) {
return false; 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() { EditBitmapWidget.prototype.loadCanvas = function() {
var tiddler = this.wiki.getTiddler(this.editTitle), var tiddler = this.wiki.getTiddler(this.editTitle),
currImage = new Image(); currImage = new Image();

View File

@ -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; exports["edit-text"] = EditTextWidget;
})(); })();

View File

@ -70,16 +70,6 @@ ElementWidget.prototype.refresh = function(changedTiddlers) {
return this.refreshChildren(changedTiddlers) || hasChangedAttributes; 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; exports.element = ElementWidget;
})(); })();

View File

@ -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; exports.encrypt = EncryptWidget;
})(); })();

View File

@ -47,16 +47,6 @@ EntityWidget.prototype.refresh = function(changedTiddlers) {
return false; 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; exports.entity = EntityWidget;
})(); })();

View File

@ -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; exports.fields = FieldsWidget;
})(); })();

View File

@ -169,16 +169,6 @@ LinkWidget.prototype.refresh = function(changedTiddlers) {
return this.refreshChildren(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; exports.link = LinkWidget;
})(); })();

View File

@ -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; exports.password = PasswordWidget;
})(); })();

View File

@ -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; exports.reveal = RevealWidget;
})(); })();

View File

@ -48,16 +48,6 @@ TextNodeWidget.prototype.refresh = function(changedTiddlers) {
return false; 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; exports.text = TextNodeWidget;
})(); })();

View File

@ -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; exports.view = ViewWidget;
})(); })();

View File

@ -450,9 +450,18 @@ Widget.prototype.findFirstDomNode = function() {
Remove any DOM nodes created by this widget or its children Remove any DOM nodes created by this widget or its children
*/ */
Widget.prototype.removeChildDomNodes = function() { Widget.prototype.removeChildDomNodes = function() {
$tw.utils.each(this.children,function(childWidget) { // 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
childWidget.removeChildDomNodes(); 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; exports.widget = Widget;

View File

@ -199,16 +199,6 @@ BarWidget.prototype.refresh = function(changedTiddlers) {
return false; 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; exports.d3bar = BarWidget;
})(); })();

View File

@ -128,16 +128,6 @@ CloudWidget.prototype.refresh = function(changedTiddlers) {
return false; 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; exports.d3cloud = CloudWidget;
})(); })();