1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 09:43:16 +00:00

Fix addAttributeToParseTreeNode handling of ordered attributes

This commit is contained in:
jeremy@jermolene.com 2022-05-03 09:37:49 +01:00
parent 2ea0374b55
commit 0163c04b7d

View File

@ -15,9 +15,18 @@ Parse tree utility functions.
exports.addAttributeToParseTreeNode = function(node,name,value) {
var attribute = {name: name, type: "string", value: value};
node.attributes = node.attributes || {};
node.orderedAttributes = node.orderedAttributes || [];
node.attributes[name] = attribute;
if(node.orderedAttributes) {
var foundIndex = -1;
$tw.utils.each(node.orderedAttributes,function(attr,index) {
if(attr.name === name) {
foundIndex = index;
}
});
if(foundIndex === -1) {
node.orderedAttributes.push(attribute);
} else {
node.orderedAttributes[foundIndex] = attribute;
}
};