From 966684cb13e8e1a6f3478050ff7503d21c57bb41 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 14 Dec 2012 17:57:53 +0000 Subject: [PATCH] Improved event handling for widgets --- core/modules/rendertree/renderers/widget.js | 6 +++++- core/modules/widgets/navigator.js | 14 +++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/modules/rendertree/renderers/widget.js b/core/modules/rendertree/renderers/widget.js index b1e541dd9..54f87a97c 100644 --- a/core/modules/rendertree/renderers/widget.js +++ b/core/modules/rendertree/renderers/widget.js @@ -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; diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 3d60dcae0..cb86c14ab 100644 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -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) {