diff options
author | bptato <nincsnevem662@gmail.com> | 2022-11-27 22:49:55 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-11-27 23:00:33 +0100 |
commit | 8af10b8b74fd29fe4c9debcd5cbecfaddf53a7b5 (patch) | |
tree | c328a14994c5da468f68253d2dff5b90bb7b1333 /src/html | |
parent | 4df668fd2225278d4745a67613efd9859bc8c1a0 (diff) | |
download | chawan-8af10b8b74fd29fe4c9debcd5cbecfaddf53a7b5.tar.gz |
Add support for <button>
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 25 | ||||
-rw-r--r-- | src/html/tags.nim | 7 |
2 files changed, 28 insertions, 4 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 51a4058b..be66dc51 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -168,6 +168,10 @@ type HTMLAreaElement* = ref object of HTMLElement + HTMLButtonElement* = ref object of FormAssociatedElement + ctype*: ButtonType + value*: string + proc tostr(ftype: enum): string = return ($ftype).split('_')[1..^1].join("-").tolower() @@ -649,6 +653,8 @@ func newHTMLElement*(document: Document, tagType: TagType, namespace = Namespace HTMLScriptElement(result).forceAsync = true of TAG_BASE: result = new(HTMLBaseElement) + of TAG_BUTTON: + result = new(HTMLButtonElement) else: result = new(HTMLElement) @@ -892,7 +898,11 @@ proc setForm*(element: FormAssociatedElement, form: HTMLFormElement) = let select = HTMLSelectElement(element) select.form = form form.controls.add(select) - of TAG_BUTTON, TAG_FIELDSET, TAG_OBJECT, TAG_OUTPUT, TAG_TEXTAREA, TAG_IMG: + of TAG_BUTTON: + let button = HTMLButtonElement(element) + button.form = form + form.controls.add(button) + of TAG_FIELDSET, TAG_OBJECT, TAG_OUTPUT, TAG_TEXTAREA, TAG_IMG: discard #TODO else: assert false @@ -926,7 +936,7 @@ proc insertionSteps(insertedNode: Node) = select.resetElement() else: discard if tagType in FormAssociatedElements: - if tagType notin {TAG_SELECT, TAG_INPUT}: + if tagType notin SupportedFormAssociatedElements: return #TODO TODO TODO implement others too let element = FormAssociatedElement(element) if element.parserInserted: @@ -1012,9 +1022,19 @@ proc appendAttribute*(element: Element, k, v: string) = select.size = parseInt(v) elif "multiple" in select.attributes: select.size = 4 + of TAG_BUTTON: + let button = HTMLButtonElement(element) + if k == "type": + case v + of "submit": button.ctype = BUTTON_SUBMIT + of "reset": button.ctype = BUTTON_RESET + of "button": button.ctype = BUTTON_BUTTON + elif k == "value": + button.value = v else: discard element.attributes[k] = v +# Forward definition hack (these are set in selectors.nim) var doqsa*: proc (node: Node, q: string): seq[Element] var doqs*: proc (node: Node, q: string): Element @@ -1052,3 +1072,4 @@ proc addDOMModule*(ctx: JSContext) = ctx.registerType(HTMLTemplateElement, parent = htmlElementCID) ctx.registerType(HTMLUnknownElement, parent = htmlElementCID) ctx.registerType(HTMLScriptElement, parent = htmlElementCID) + ctx.registerType(HTMLButtonElement, parent = htmlElementCID) diff --git a/src/html/tags.nim b/src/html/tags.nim index 5e0a2935..fbec9164 100644 --- a/src/html/tags.nim +++ b/src/html/tags.nim @@ -24,6 +24,9 @@ type INPUT_RESET, INPUT_SEARCH, INPUT_SUBMIT, INPUT_TEL, INPUT_TEXT, INPUT_TIME, INPUT_URL, INPUT_WEEK + ButtonType* = enum + BUTTON_SUBMIT, BUTTON_RESET, BUTTON_BUTTON + TagType* = enum TAG_UNKNOWN, TAG_APPLET, TAG_BIG, TAG_HTML, TAG_BASE, TAG_BASEFONT, TAG_BGSOUND, TAG_HEAD, TAG_LINK, TAG_LISTING, TAG_META, TAG_STYLE, @@ -115,11 +118,11 @@ const FormAssociatedElements* = { #TODO support all the other ones const SupportedFormAssociatedElements* = { - TAG_SELECT, TAG_INPUT + TAG_SELECT, TAG_INPUT, TAG_BUTTON } const ListedElements* = { - TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA + TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA } const SubmittableElements* = { |