1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-15 06:14:53 +00:00

Improved event handling for widgets

This commit is contained in:
Jeremy Ruston 2012-12-14 17:57:53 +00:00
parent 5c1caa672b
commit 966684cb13
2 changed files with 8 additions and 12 deletions

View File

@ -94,8 +94,12 @@ WidgetRenderer.prototype.renderInDom = function() {
this.domNode.setAttribute("data-widget-type",this.parseTreeNode.tag);
this.domNode.setAttribute("data-widget-attr",JSON.stringify(this.attributes));
// Render the widget if we've got one
if(this.widget && this.widget.renderInDom) {
if(this.widget) {
this.widget.renderInDom(this.domNode);
// Attach any event handlers
if(this.widget.getEventListeners) {
$tw.utils.addEventListeners(this.domNode,this.widget.getEventListeners());
}
}
// Return the dom node
return this.domNode;

View File

@ -31,22 +31,14 @@ exports.generateChildNodes = function() {
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children);
};
exports.renderInDom = function(parentElement) {
this.parentElement = parentElement;
// Render any child nodes
$tw.utils.each(this.children,function(node) {
if(node.renderInDom) {
parentElement.appendChild(node.renderInDom());
}
});
// Attach our event handlers
$tw.utils.addEventListeners(this.renderer.domNode,[
exports.getEventListeners = function() {
return [
{name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"},
{name: "tw-EditTiddler", handlerObject: this, handlerMethod: "handleEditTiddlerEvent"},
{name: "tw-SaveTiddler", handlerObject: this, handlerMethod: "handleSaveTiddlerEvent"},
{name: "tw-close", handlerObject: this, handlerMethod: "handleCloseTiddlerEvent"},
{name: "tw-NewTiddler", handlerObject: this, handlerMethod: "handleNewTiddlerEvent"}
]);
];
};
exports.refreshInDom = function(changedAttributes,changedTiddlers) {