(domElement: Element)
| 8 | import { parseJs } from './import_js' |
| 9 | |
| 10 | function createScriptElement(domElement: Element): SplootHtmlScriptElement { |
| 11 | const splootNode = new SplootHtmlScriptElement(null) |
| 12 | domElement.childNodes.forEach((childNode: ChildNode) => { |
| 13 | if (childNode.nodeType !== Node.TEXT_NODE) { |
| 14 | console.warn('Found non-text node inside script tag??') |
| 15 | } else { |
| 16 | const jsNode = parseJs((childNode as Text).textContent) as JavascriptFile |
| 17 | jsNode.getBody().children.forEach((node: SplootNode) => { |
| 18 | splootNode.getContent().addChild(node) |
| 19 | }) |
| 20 | } |
| 21 | }) |
| 22 | const attrs = domElement.attributes |
| 23 | for (let i = 0; i < attrs.length; i++) { |
| 24 | const attr = attrs.item(i) |
| 25 | // TODO: Detect if this should be a string, number or javascript node. |
| 26 | const strLiteral = new StringLiteral(null, attr.value) |
| 27 | const newAttrNode = new SplootHtmlAttribute(null, attr.name) |
| 28 | newAttrNode.getValue().addChild(strLiteral) |
| 29 | splootNode.getAttributes().addChild(newAttrNode) |
| 30 | } |
| 31 | return splootNode |
| 32 | } |
| 33 | |
| 34 | function createDomElement(domElement: Element): SplootNode { |
| 35 | switch (domElement.tagName.toLowerCase()) { |
no test coverage detected