/*\ title: $:/core/modules/treenodes/element.js type: application/javascript module-type: treenode Element nodes \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; var Node = require("./node.js").Node; var Element = function(type,attributes,children,options) { options = options || {}; if(this instanceof Element) { this.type = type; this.attributes = attributes || {}; this.children = children; this.events = options.events; this.eventHandler = options.eventHandler; } else { return new Element(type,attributes,children,options); } }; Element.prototype = new Node(); Element.prototype.constructor = Element; Element.prototype.clone = function() { var childClones; if(this.children) { childClones = []; for(var t=0; t"); } if(this.children) { for(var t=0; t"); } } return output.join(""); }; Element.prototype.renderInDom = function(parentDomNode,insertBefore) { // Create the element var element = document.createElement(this.type); // Assign the attributes if(this.attributes) { for(var a in this.attributes) { var v = this.attributes[a]; if(v !== undefined) { if($tw.utils.isArray(v)) { // Ahem, could there be arrays other than className? element.className = v.join(" "); } else if (typeof v === "object") { // ...or objects other than style? for(var p in v) { element.style[$tw.utils.unHyphenateCss(p)] = v[p]; } } else { element.setAttribute(a,v); } } } } // Insert it into the DOM tree if(insertBefore) { parentDomNode.insertBefore(element,insertBefore); } else { parentDomNode.appendChild(element); } // Register event handlers if(this.events) { for(var e=0; e