Boot: Enhance domMaker to support namespaces and styles

allow-filter-duplicates
Jermolene 2019-02-01 10:43:14 +00:00
rodzic 92b8368115
commit 7bc1458749
1 zmienionych plików z 6 dodań i 1 usunięć

Wyświetl plik

@ -89,7 +89,9 @@ Helper for making DOM elements
tag: tag name
options: see below
Options include:
namespace: defaults to http://www.w3.org/1999/xhtml
attributes: hashmap of attribute values
style: hashmap of styles
text: text to add as a child node
children: array of further child nodes
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) {
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"]) {
element.className = options["class"];
}
@ -115,6 +117,9 @@ $tw.utils.domMaker = function(tag,options) {
$tw.utils.each(options.attributes,function(attribute,name) {
element.setAttribute(name,attribute);
});
$tw.utils.each(options.style,function(value,name) {
element.style[name] = value;
});
if(options.eventListeners) {
$tw.utils.addEventListeners(element,options.eventListeners);
}