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

Boot: Enhance domMaker to support namespaces and styles

This commit is contained in:
Jermolene 2019-02-01 10:43:14 +00:00
parent 92b8368115
commit 7bc1458749

View File

@ -89,7 +89,9 @@ Helper for making DOM elements
tag: tag name tag: tag name
options: see below options: see below
Options include: Options include:
namespace: defaults to http://www.w3.org/1999/xhtml
attributes: hashmap of attribute values attributes: hashmap of attribute values
style: hashmap of styles
text: text to add as a child node text: text to add as a child node
children: array of further child nodes children: array of further child nodes
innerHTML: optional HTML for element innerHTML: optional HTML for element
@ -99,7 +101,7 @@ eventListeners: array of event listeners (this option won't work until $tw.utils
*/ */
$tw.utils.domMaker = function(tag,options) { $tw.utils.domMaker = function(tag,options) {
var doc = options.document || document; var doc = options.document || document;
var element = doc.createElement(tag); var element = doc.createElementNS(options.namespace || "http://www.w3.org/1999/xhtml",tag);
if(options["class"]) { if(options["class"]) {
element.className = options["class"]; element.className = options["class"];
} }
@ -115,6 +117,9 @@ $tw.utils.domMaker = function(tag,options) {
$tw.utils.each(options.attributes,function(attribute,name) { $tw.utils.each(options.attributes,function(attribute,name) {
element.setAttribute(name,attribute); element.setAttribute(name,attribute);
}); });
$tw.utils.each(options.style,function(value,name) {
element.style[name] = value;
});
if(options.eventListeners) { if(options.eventListeners) {
$tw.utils.addEventListeners(element,options.eventListeners); $tw.utils.addEventListeners(element,options.eventListeners);
} }