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) {
if(node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) {
return node.attributes[name].value;

View File

@ -48,7 +48,7 @@ LetWidget.prototype.computeAttributes = function() {
var changedAttributes = {},
self = this;
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),
name = attribute.name;
if(name.charAt(0) !== "$") {