1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Some widget.js cleanups

This commit is contained in:
jeremy@jermolene.com 2022-09-27 08:58:10 +01:00
parent 502a1ab70d
commit 668168dfea

View File

@ -41,10 +41,7 @@ Widget.prototype.initialise = function(parseTreeNode,options) {
this.parseTreeNode = parseTreeNode;
this.wiki = options.wiki;
this.parentWidget = options.parentWidget;
this.variables = Object.create(null);
if(this.parentWidget) {
Object.setPrototypeOf(this.variables,this.parentWidget.variables);
}
this.variables = Object.create(this.parentWidget ? this.parentWidget.variables : null);
this.document = options.document;
this.attributes = {};
this.children = [];
@ -128,8 +125,14 @@ Widget.prototype.getVariableInfo = function(name,options) {
options = options || {};
var self = this,
actualParams = options.params || [],
currWidget = options.allowSelfAssigned ? this : this.parentWidget,
processVariable = function(variable) {
variable;
if(options.allowSelfAssigned) {
variable = this.variables[name];
} else {
variable = this.parentWidget && this.parentWidget.variables[name];
}
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
if(variable) {
var originalValue = variable.value,
value = originalValue,
params = [];
@ -148,10 +151,6 @@ Widget.prototype.getVariableInfo = function(name,options) {
srcVariable: variable,
isCacheable: originalValue === value
};
};
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
if(currWidget && name in currWidget.variables) {
return processVariable(currWidget.variables[name]);
}
// If the variable doesn't exist in the parent widget then look for a macro module
var text = this.evaluateMacroModule(name,actualParams);