Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .localName and .data #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/undom.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ function createEnvironment() {
}

class Node {
constructor(nodeType, nodeName) {
constructor(nodeType, localName) {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.localName = localName;
this.childNodes = [];
}
get nodeName() {
return this.localName.toUpperCase();
}
get nextSibling() {
let p = this.parentNode;
if (p) return p.childNodes[findWhere(p.childNodes, this, true, true) + 1];
Expand Down Expand Up @@ -76,20 +79,26 @@ function createEnvironment() {
class Text extends Node {
constructor(text) {
super(3, '#text'); // TEXT_NODE
this.nodeValue = text;
this.data = text;
}
set textContent(text) {
this.nodeValue = text;
get nodeValue() {
return this.data;
}
set nodeValue(text) {
this.data = text;
}
get textContent() {
return this.nodeValue;
return this.data;
}
set textContent(text) {
this.data = text;
}
}


class Element extends Node {
constructor(nodeType, nodeName) {
super(nodeType || 1, nodeName); // ELEMENT_NODE
constructor(nodeType, localName) {
super(nodeType || 1, localName); // ELEMENT_NODE
this.attributes = [];
this.__handlers = {};
this.style = {};
Expand Down Expand Up @@ -158,7 +167,7 @@ function createEnvironment() {
}

createElement(type) {
return new Element(null, String(type).toUpperCase());
return new Element(null, type);
}

createElementNS(ns, type) {
Expand All @@ -167,7 +176,6 @@ function createEnvironment() {
return element;
}


createTextNode(text) {
return new Text(text);
}
Expand All @@ -192,12 +200,13 @@ function createEnvironment() {
}


/** Create a minimally viable DOM Document
* @returns {Document} document
*/
/**
* Create a minimally viable DOM Document
* @returns {Document} document
*/
function createDocument() {
let document = new Document();
assign(document, document.defaultView = { document, Document, Node, Text, Element, SVGElement: Element, Event });
document.defaultView = { document, Document, Node, Text, Element, SVGElement: Element, Event };
document.appendChild(
document.documentElement = document.createElement('html')
);
Expand Down