mirror of
https://codeberg.org/setop/elm-scripting
synced 2025-11-08 21:49:57 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7b1b206be | |||
| 6050fb02a3 | |||
| 9566f305b5 | |||
| 7025bc1104 | |||
| a261077f6c |
42
dom.js
42
dom.js
@@ -14,7 +14,7 @@ function Node(parent, tag) {
|
|||||||
this.replaceChild = (newNode, domNode) => {
|
this.replaceChild = (newNode, domNode) => {
|
||||||
this.children[domNode.pos-1] = newNode;
|
this.children[domNode.pos-1] = newNode;
|
||||||
newNode.pos = domNode.pos;
|
newNode.pos = domNode.pos;
|
||||||
};
|
};
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
this.pos = parent.children.push(this);
|
this.pos = parent.children.push(this);
|
||||||
}
|
}
|
||||||
@@ -24,17 +24,17 @@ function Node(parent, tag) {
|
|||||||
this.replaceData = (offset, count, data) => {
|
this.replaceData = (offset, count, data) => {
|
||||||
this.text = data; // elm runtime will always replace the whole text
|
this.text = data; // elm runtime will always replace the whole text
|
||||||
}
|
}
|
||||||
this.dump = (d=0) => {
|
this.dump = (d=0) => {
|
||||||
if (this.text != null) {
|
if (this.text != null) {
|
||||||
print(this.text);
|
print(this.text);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.innerHTML) {
|
if (this.innerHTML) {
|
||||||
print(this.innerHTML);
|
print(this.innerHTML);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
std.printf("<%s", this.tagName)
|
std.printf("<%s", this.tagName)
|
||||||
// Set.difference(other) is not avalable in qjs
|
// Set.difference(other) is not avalable in qjs
|
||||||
for (a of Object.keys(this)) {
|
for (a of Object.keys(this)) {
|
||||||
if (!NodeKeys.has(a)) {
|
if (!NodeKeys.has(a)) {
|
||||||
std.printf(' %s="%s"', a, this[a])
|
std.printf(' %s="%s"', a, this[a])
|
||||||
@@ -43,18 +43,18 @@ function Node(parent, tag) {
|
|||||||
if (this.children.length==0) {
|
if (this.children.length==0) {
|
||||||
print("/>")
|
print("/>")
|
||||||
} else {
|
} else {
|
||||||
print(">")
|
print(">")
|
||||||
for (c of this.children) {
|
for (c of this.children) {
|
||||||
c.dump(d+1)
|
c.dump(d+1)
|
||||||
}
|
}
|
||||||
print("</"+this.tagName+">");
|
print("</"+this.tagName+">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = new Node(null, "document");
|
var document = new Node(null, "document");
|
||||||
const target = new Node(document, "target");
|
var target = new Node(document, "target");
|
||||||
const NodeKeys = new Set(Object.keys(target));
|
const NodeKeys = new Set(Object.keys(target));
|
||||||
|
|
||||||
// getElementById is only used once, to get node Elm must hook into.
|
// getElementById is only used once, to get node Elm must hook into.
|
||||||
@@ -67,6 +67,6 @@ document.createTextNode = (text) => { t = new Node(null, "#text" ); t.text = tex
|
|||||||
|
|
||||||
|
|
||||||
// workaround for elm-explorations/markdown Markdown.toHtml
|
// workaround for elm-explorations/markdown Markdown.toHtml
|
||||||
const global = {};
|
global = {};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user