From 51394e50e8ff1b38b242df44ad254cff10e1320a Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 2 Nov 2013 10:12:22 +0000 Subject: [PATCH] Get rid of the event handling in the tiddler widget Much neater if each widget does as little as possible. --- core/modules/new_widgets/link.js | 1 + core/modules/new_widgets/tiddler.js | 13 +------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/core/modules/new_widgets/link.js b/core/modules/new_widgets/link.js index f0b10b3a7..1a16b6f54 100755 --- a/core/modules/new_widgets/link.js +++ b/core/modules/new_widgets/link.js @@ -91,6 +91,7 @@ LinkWidget.prototype.handleClickEvent = function (event) { this.dispatchEvent({ type: "tw-navigate", navigateTo: this.to, + navigateFromTitle: this.getVariable("currentTiddler"), navigateFromNode: this, navigateFromClientRect: { top: bounds.top, left: bounds.left, width: bounds.width, right: bounds.right, bottom: bounds.bottom, height: bounds.height } diff --git a/core/modules/new_widgets/tiddler.js b/core/modules/new_widgets/tiddler.js index e21a20505..d76626e3c 100755 --- a/core/modules/new_widgets/tiddler.js +++ b/core/modules/new_widgets/tiddler.js @@ -16,9 +16,6 @@ var Widget = require("$:/core/modules/new_widgets/widget.js").widget; var TiddlerWidget = function(parseTreeNode,options) { this.initialise(parseTreeNode,options); - this.addEventListeners([ - {type: "tw-navigate", handler: "handleNavigateEvent"} - ]); }; /* @@ -41,7 +38,7 @@ Compute the internal state of the widget */ TiddlerWidget.prototype.execute = function() { // Get our parameters - this.tiddlerTitle = this.getAttribute("tiddler",""); + this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); // Set context variables this.setVariable("currentTiddler",this.tiddlerTitle); this.setVariable("missingTiddlerClass",(this.wiki.tiddlerExists(this.tiddlerTitle) || this.wiki.isShadowTiddler(this.tiddlerTitle)) ? "tw-tiddler-exists" : "tw-tiddler-missing"); @@ -64,14 +61,6 @@ TiddlerWidget.prototype.refresh = function(changedTiddlers) { } }; -/* -Handle a tw-navigate event -*/ -TiddlerWidget.prototype.handleNavigateEvent = function(event) { - event.navigateFromTitle = this.tiddlerTitle; - return true; -}; - exports.tiddler = TiddlerWidget; })();