mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-25 01:20:30 +00:00
Slight optimisation to user defined widgets
This commit is contained in:
parent
fddaa9fdb1
commit
1aba8a1f65
@ -501,25 +501,29 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
// Check whether this node type is defined by a custom widget definition
|
// Check whether this node type is defined by a custom widget definition
|
||||||
var variableDefinitionName = "$" + parseTreeNode.type,
|
var variableDefinitionName = "$" + parseTreeNode.type;
|
||||||
variableInfo = this.getVariableInfo(variableDefinitionName,{allowSelfAssigned: true}),
|
if(this.variables[variableDefinitionName]) {
|
||||||
isOverrideable = function() {
|
var isOverrideable = function() {
|
||||||
// Widget is overrideable if it has a double dollar user defined name, or if it is an existing JS widget and we're not in safe mode
|
// Widget is overrideable if it has a double dollar user defined name, or if it is an existing JS widget and we're not in safe mode
|
||||||
return parseTreeNode.type.charAt(0) === "$" || (!!self.widgetClasses[parseTreeNode.type] && !$tw.safeMode);
|
return parseTreeNode.type.charAt(0) === "$" || (!!self.widgetClasses[parseTreeNode.type] && !$tw.safeMode);
|
||||||
};
|
};
|
||||||
if(!parseTreeNode.isNotRemappable && isOverrideable() && variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) {
|
if(!parseTreeNode.isNotRemappable && isOverrideable()) {
|
||||||
var newParseTreeNode = {
|
var variableInfo = this.getVariableInfo(variableDefinitionName,{allowSelfAssigned: true});
|
||||||
type: "transclude",
|
if(variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) {
|
||||||
children: parseTreeNode.children,
|
var newParseTreeNode = {
|
||||||
isBlock: parseTreeNode.isBlock
|
type: "transclude",
|
||||||
};
|
children: parseTreeNode.children,
|
||||||
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode,"$variable",variableDefinitionName);
|
isBlock: parseTreeNode.isBlock
|
||||||
$tw.utils.each(parseTreeNode.attributes,function(attr,name) {
|
};
|
||||||
// If the attribute starts with a dollar then add an extra dollar so that it doesn't clash with the $xxx attributes of transclude
|
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode,"$variable",variableDefinitionName);
|
||||||
name = name.charAt(0) === "$" ? "$" + name : name;
|
$tw.utils.each(parseTreeNode.attributes,function(attr,name) {
|
||||||
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode,$tw.utils.extend({},attr,{name: name}));
|
// If the attribute starts with a dollar then add an extra dollar so that it doesn't clash with the $xxx attributes of transclude
|
||||||
});
|
name = name.charAt(0) === "$" ? "$" + name : name;
|
||||||
parseTreeNode = newParseTreeNode;
|
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode,$tw.utils.extend({},attr,{name: name}));
|
||||||
|
});
|
||||||
|
parseTreeNode = newParseTreeNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Get the widget class for this node type
|
// Get the widget class for this node type
|
||||||
var WidgetClass = this.widgetClasses[parseTreeNode.type];
|
var WidgetClass = this.widgetClasses[parseTreeNode.type];
|
||||||
|
Loading…
Reference in New Issue
Block a user