From fc94d4af9617a96ddee4c859a56bae8bc4ba1d49 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 9 Nov 2024 21:26:50 +0100 Subject: dom: misc fixes & additions * fix cloneNode not cloning id/name atoms * fix HTMLOptionsCollection named item getter * fix HTMLCollection named item getter not refreshing snapshot * support named item getter for form * add basic createEvent --- src/html/dom.nim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/html/dom.nim') diff --git a/src/html/dom.nim b/src/html/dom.nim index d173c40d..2f285899 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1602,6 +1602,7 @@ func item(this: HTMLCollection; u: uint32): Element {.jsfunc.} = return nil func namedItem(this: HTMLCollection; atom: CAtom): Element {.jsfunc.} = + this.refreshCollection() for it in this.snapshot: let it = Element(it) if it.id == atom or it.namespace == Namespace.HTML and it.name == atom: @@ -2732,6 +2733,10 @@ func elements(form: HTMLFormElement): HTMLFormControlsCollection {.jsfget.} = ) return form.cachedElements +proc getter(ctx: JSContext; this: HTMLFormElement; atom: JSAtom): JSValue + {.jsgetprop.} = + return ctx.getter(this.elements, atom) + # func jsForm(this: HTMLInputElement): HTMLFormElement {.jsfget: "form".} = return this.form @@ -2756,6 +2761,14 @@ func isOptionOf(node: Node; select: HTMLSelectElement): bool = parent of HTMLOptGroupElement and parent.parentNode == select return false +proc names(ctx: JSContext; this: HTMLOptionsCollection): JSPropertyEnumList + {.jspropnames.} = + return ctx.names(HTMLCollection(this)) + +proc getter(ctx: JSContext; this: HTMLOptionsCollection; atom: JSAtom): Element + {.jsgetprop.} = + return ctx.getter(HTMLCollection(this), atom) + func jsOptions(this: HTMLSelectElement): HTMLOptionsCollection {.jsfget: "options".} = if this.cachedOptions == nil: @@ -4378,6 +4391,12 @@ proc createProcessingInstruction(document: Document; target, data: string): "InvalidCharacterError") return ok(newProcessingInstruction(document, target, data)) +proc createEvent(ctx: JSContext; document: Document; t: StaticAtom): + DOMResult[Event] {.jsfunc.} = + if t notin {satUEvent, satEvent, satEvents, satSvgevents}: + return errDOMException("Event not supported", "NotSupportedError") + return ok(newEvent(ctx.toAtom(""), nil)) + proc clone(node: Node; document = none(Document), deep = false): Node = let document = document.get(node.document) let copy = if node of Element: @@ -4385,6 +4404,9 @@ proc clone(node: Node; document = none(Document), deep = false): Node = let element = Element(node) let x = document.newHTMLElement(element.localName, element.namespace, element.namespacePrefix) + x.id = element.id + x.name = element.name + x.classList = DOMTokenList(element: x, localName: element.localName) x.attrs = element.attrs #TODO namespaced attrs? # Cloning steps -- cgit 1.4.1-2-gfad0