1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Add utility method for getting ordered attributes

This commit is contained in:
jeremy@jermolene.com 2022-04-26 14:02:31 +01:00
parent bdd99edfe8
commit 0bffae2108
2 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,20 @@ exports.addAttributeToParseTreeNode = function(node,name,value) {
} }
}; };
exports.getOrderedAttributesFromParseTreeNode = function(node) {
if(node.orderedAttributes) {
return node.orderedAttributes;
} else {
var attributes = [];
$tw.utils.each(node.attributes,function(attribute) {
attributes.push(attribute);
});
return attributes.sort(function(a,b) {
return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0);
});
}
};
exports.getAttributeValueFromParseTreeNode = function(node,name,defaultValue) { exports.getAttributeValueFromParseTreeNode = function(node,name,defaultValue) {
if(node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) { if(node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) {
return node.attributes[name].value; return node.attributes[name].value;

View File

@ -48,7 +48,7 @@ LetWidget.prototype.computeAttributes = function() {
var changedAttributes = {}, var changedAttributes = {},
self = this; self = this;
this.currentValueFor = Object.create(null); this.currentValueFor = Object.create(null);
$tw.utils.each(this.parseTreeNode.orderedAttributes,function(attribute,index) { $tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(this.parseTreeNode),function(attribute) {
var value = self.computeAttribute(attribute), var value = self.computeAttribute(attribute),
name = attribute.name; name = attribute.name;
if(name.charAt(0) !== "$") { if(name.charAt(0) !== "$") {