From bf6f5e0254ce4bc8d6122b071400125cd4d56217 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 21 Feb 2012 21:57:30 +0000 Subject: [PATCH] Refactored macro interface Now 'this' points to the Renderer.MacroNode --- js/Renderer.js | 8 ++++---- js/macros/echo.js | 4 ++-- js/macros/image.js | 18 ++++++++-------- js/macros/link.js | 16 +++++++-------- js/macros/list.js | 16 +++++++-------- js/macros/slider.js | 34 +++++++++++++++--------------- js/macros/story.js | 49 ++++++++++++++++++++++---------------------- js/macros/tiddler.js | 21 ++++++++++--------- js/macros/version.js | 2 +- js/macros/video.js | 10 ++++----- js/macros/view.js | 21 ++++++++++--------- 11 files changed, 101 insertions(+), 98 deletions(-) diff --git a/js/Renderer.js b/js/Renderer.js index 6b0fd5de4..4850b50a7 100644 --- a/js/Renderer.js +++ b/js/Renderer.js @@ -30,7 +30,7 @@ Node.prototype.render = Node.prototype.renderInDom = Node.prototype.refresh = Node.prototype.refreshInDom = function() { - // All these methods are noops by default + // All these methods are no-ops by default }; /* @@ -107,7 +107,7 @@ MacroNode.prototype.execute = function(parents,tiddler) { // Save a reference to the array of parents this.parents = parents || []; // Render the macro to get its content - this.content = this.macro.execute(this,tiddler,this.store); + this.content = this.macro.execute.call(this); }; MacroNode.prototype.render = function(type) { @@ -132,7 +132,7 @@ MacroNode.prototype.renderInDom = function(domNode,insertBefore) { // Add event handlers to the node var self = this, dispatchMacroEvent = function(event) { - self.macro.events[event.type](event,self); + self.macro.events[event.type].call(self,event); }; for(var e in this.macro.events) { macroContainer.addEventListener(e,dispatchMacroEvent,false); @@ -167,7 +167,7 @@ MacroNode.prototype.refreshInDom = function(changes) { // Ask the macro to rerender itself if it can var tiddler = this.store.getTiddler(this.tiddlerTitle); if(this.macro.refresh) { - this.macro.refresh(changes,this,tiddler,this.store); + this.macro.refresh.call(this,changes); } else { // Manually reexecute and rerender this macro while(this.domNode.hasChildNodes()) { diff --git a/js/macros/echo.js b/js/macros/echo.js index e2ebe33eb..80c7ecb4e 100644 --- a/js/macros/echo.js +++ b/js/macros/echo.js @@ -15,8 +15,8 @@ exports.macro = { params: { text: {byPos: 0, type: "text"} }, - execute: function(macroNode,tiddler,store) { - return [Renderer.TextNode(macroNode.params.text)]; + execute: function() { + return [Renderer.TextNode(this.params.text)]; } }; diff --git a/js/macros/image.js b/js/macros/image.js index 0611e52e1..4cba52ee4 100644 --- a/js/macros/image.js +++ b/js/macros/image.js @@ -17,26 +17,26 @@ exports.macro = { text: {byName: true, type: "text"}, alignment: {byName: true, type: "text"} }, - execute: function(macroNode,tiddler,store) { - if(store.tiddlerExists(macroNode.params.src)) { - var imageTree = store.parseTiddler(macroNode.params.src).tree, + execute: function() { + if(this.store.tiddlerExists(this.params.src)) { + var imageTree = this.store.parseTiddler(this.params.src).tree, cloneImage = []; for(var t=0; t t) { // First delete the DOM nodes for(n=t; n targetTiddlers.length) { - for(t=targetTiddlers.length; t targetTiddlers.length) { + for(t=targetTiddlers.length; t> macro **}}")]; } parents = parents.slice(0); parents.push(tiddler.title); } else { - content = store.parseText("text/x-tiddlywiki",v).tree; + content = this.store.parseText("text/x-tiddlywiki",v).tree; } for(t=0; t