1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-05 16:28:05 +00:00

Introduce genesis widget (#6961)

* Initial Commit

* Fix version number

* Fix docs date
This commit is contained in:
Jeremy Ruston
2022-09-24 14:07:42 +01:00
committed by GitHub
parent dd66fcc759
commit 4e9267ea58
7 changed files with 288 additions and 2 deletions

View File

@@ -12,12 +12,26 @@ Parse tree utility functions.
/*global $tw: false */
"use strict";
/*
Add attribute to parse tree node
Can be invoked as (node,name,value) or (node,attr)
*/
exports.addAttributeToParseTreeNode = function(node,name,value) {
var attribute = {name: name, type: "string", value: value};
var attribute = typeof name === "object" ? name : {name: name, type: "string", value: value};
name = attribute.name;
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;
}
};