mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 14:23:53 +00:00
Some widget.js cleanups
This commit is contained in:
parent
502a1ab70d
commit
668168dfea
@ -41,10 +41,7 @@ Widget.prototype.initialise = function(parseTreeNode,options) {
|
|||||||
this.parseTreeNode = parseTreeNode;
|
this.parseTreeNode = parseTreeNode;
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
this.parentWidget = options.parentWidget;
|
this.parentWidget = options.parentWidget;
|
||||||
this.variables = Object.create(null);
|
this.variables = Object.create(this.parentWidget ? this.parentWidget.variables : null);
|
||||||
if(this.parentWidget) {
|
|
||||||
Object.setPrototypeOf(this.variables,this.parentWidget.variables);
|
|
||||||
}
|
|
||||||
this.document = options.document;
|
this.document = options.document;
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.children = [];
|
this.children = [];
|
||||||
@ -128,30 +125,32 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var self = this,
|
var self = this,
|
||||||
actualParams = options.params || [],
|
actualParams = options.params || [],
|
||||||
currWidget = options.allowSelfAssigned ? this : this.parentWidget,
|
variable;
|
||||||
processVariable = function(variable) {
|
if(options.allowSelfAssigned) {
|
||||||
var originalValue = variable.value,
|
variable = this.variables[name];
|
||||||
value = originalValue,
|
} else {
|
||||||
params = [];
|
variable = this.parentWidget && this.parentWidget.variables[name];
|
||||||
// Only substitute parameter and variable references if this variable was defined with the \define pragma
|
}
|
||||||
if(variable.isMacroDefinition) {
|
|
||||||
params = self.resolveVariableParameters(variable.params,actualParams);
|
|
||||||
// Substitute any parameters specified in the definition
|
|
||||||
$tw.utils.each(params,function(param) {
|
|
||||||
value = $tw.utils.replaceString(value,new RegExp("\\$" + $tw.utils.escapeRegExp(param.name) + "\\$","mg"),param.value);
|
|
||||||
});
|
|
||||||
value = self.substituteVariableReferences(value,options);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
text: value,
|
|
||||||
params: params,
|
|
||||||
srcVariable: variable,
|
|
||||||
isCacheable: originalValue === value
|
|
||||||
};
|
|
||||||
};
|
|
||||||
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
|
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
|
||||||
if(currWidget && name in currWidget.variables) {
|
if(variable) {
|
||||||
return processVariable(currWidget.variables[name]);
|
var originalValue = variable.value,
|
||||||
|
value = originalValue,
|
||||||
|
params = [];
|
||||||
|
// Only substitute parameter and variable references if this variable was defined with the \define pragma
|
||||||
|
if(variable.isMacroDefinition) {
|
||||||
|
params = self.resolveVariableParameters(variable.params,actualParams);
|
||||||
|
// Substitute any parameters specified in the definition
|
||||||
|
$tw.utils.each(params,function(param) {
|
||||||
|
value = $tw.utils.replaceString(value,new RegExp("\\$" + $tw.utils.escapeRegExp(param.name) + "\\$","mg"),param.value);
|
||||||
|
});
|
||||||
|
value = self.substituteVariableReferences(value,options);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
text: value,
|
||||||
|
params: params,
|
||||||
|
srcVariable: variable,
|
||||||
|
isCacheable: originalValue === value
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// If the variable doesn't exist in the parent widget then look for a macro module
|
// If the variable doesn't exist in the parent widget then look for a macro module
|
||||||
var text = this.evaluateMacroModule(name,actualParams);
|
var text = this.evaluateMacroModule(name,actualParams);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user