diff --git a/core/modules/new_widgets/element.js b/core/modules/new_widgets/element.js index 034490bb9..2a65789cd 100755 --- a/core/modules/new_widgets/element.js +++ b/core/modules/new_widgets/element.js @@ -50,7 +50,7 @@ ElementWidget.prototype.execute = function() { if(this.namespace) { this.setVariable("namespace",this.namespace); } else { - this.namespace = this.getVariable("namespace",null,"http://www.w3.org/1999/xhtml"); + this.namespace = this.getVariable("namespace",{defaultValue: "http://www.w3.org/1999/xhtml"}); } // Make the child widgets this.makeChildWidgets(); diff --git a/core/modules/new_widgets/macrocall.js b/core/modules/new_widgets/macrocall.js index 3d47a9969..a488917e0 100644 --- a/core/modules/new_widgets/macrocall.js +++ b/core/modules/new_widgets/macrocall.js @@ -43,7 +43,7 @@ MacroCallWidget.prototype.execute = function() { params.push({name: name, value: attribute}); }); // Get the macro value - var text = this.getVariable(this.parseTreeNode.name || this.getAttribute("$name"),params); + var text = this.getVariable(this.parseTreeNode.name || this.getAttribute("$name"),{params: params}); // Parse the macro var parser = this.wiki.new_parseText("text/vnd.tiddlywiki",text, {parseAsInline: !this.parseTreeNode.isBlock}), diff --git a/core/modules/new_widgets/transclude.js b/core/modules/new_widgets/transclude.js index 754e34608..572dcc539 100755 --- a/core/modules/new_widgets/transclude.js +++ b/core/modules/new_widgets/transclude.js @@ -66,7 +66,7 @@ Compose a string comprising the title, field and/or index to identify this trans TranscludeWidget.prototype.makeRecursionMarker = function() { var output = []; output.push("{"); - output.push(this.getVariable("tiddlerTitle","")); + output.push(this.getVariable("tiddlerTitle",{defaultValue: ""})); output.push("|"); output.push(this.transcludeTitle || ""); output.push("|"); diff --git a/core/modules/new_widgets/widget.js b/core/modules/new_widgets/widget.js index eb8b90cf9..adeb75140 100755 --- a/core/modules/new_widgets/widget.js +++ b/core/modules/new_widgets/widget.js @@ -72,10 +72,14 @@ Widget.prototype.execute = function() { /* Get the prevailing value of a context variable name: name of variable +options: see below +Options include params: array of {name:, value:} for each parameter +defaultValue: default value if the variable is not defined */ -Widget.prototype.getVariable = function(name,actualParams,defaultValue) { - actualParams = actualParams || []; +Widget.prototype.getVariable = function(name,options) { + options = options || {}; + var actualParams = options.params || []; // Search up the widget tree for the variable name var node = this; while(node && !$tw.utils.hop(node.variables,name)) { @@ -83,7 +87,7 @@ Widget.prototype.getVariable = function(name,actualParams,defaultValue) { } // If we get to the root then look for a macro module if(!node) { - return this.evaluateMacroModule(name,actualParams,defaultValue); + return this.evaluateMacroModule(name,actualParams,options.defaultValue); } // Get the value var value = node.variables[name].value; @@ -126,7 +130,7 @@ Widget.prototype.substituteVariableParameters = function(text,formalParams,actua Widget.prototype.substituteVariableReferences = function(text) { var self = this; return text.replace(/\$\(([^\)\$]+)\)\$/g,function(match,p1,offset,string) { - return self.getVariable(p1,null,""); + return self.getVariable(p1,{defaultValue: ""}); }); }; @@ -215,7 +219,7 @@ Widget.prototype.computeAttributes = function() { if(attribute.type === "indirect") { value = self.wiki.getTextReference(attribute.textReference,"",self.getVariable("tiddlerTitle")); } else if(attribute.type === "macro") { - value = self.getVariable(attribute.value.name,attribute.value.params); + value = self.getVariable(attribute.value.name,{params: attribute.value.params}); } else { // String attribute value = attribute.value; }