diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-24 04:47:07 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-24 04:47:49 +0100 |
commit | f8dbdbc8777cda6d45e8e05f9807319db4542572 (patch) | |
tree | 6ec03ba78634e6cecd551e0127883de9e819c7c6 /src/html | |
parent | b1e2a9ce0c996de83b161a21d4e6ebb188a74699 (diff) | |
download | chawan-f8dbdbc8777cda6d45e8e05f9807319db4542572.tar.gz |
dom: add onload content attribute to body
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 27 | ||||
-rw-r--r-- | src/html/enums.nim | 1 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index e4325b18..597d34b9 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2813,6 +2813,21 @@ proc reflectAttrs(element: Element, name: CAtom, value: string) = element.style_cached = newCSSStyleDeclaration(element, value) return case element.tagType + of TAG_BODY: + if name == atOnload and element.scriptingEnabled: + let document = element.document + let ctx = document.window.jsctx + let urls = document.baseURL.serialize(excludepassword = true) + let fun = ctx.newFunction(["event"], value) + assert ctx != nil + if JS_IsException(fun): + let s = ctx.getExceptionStr() + document.window.console.log("Exception in body content attribute of", + urls, s) + else: + let jsWindow = ctx.toJS(document.window) + ctx.definePropertyC(jsWindow, "onload", fun) + JS_FreeValue(ctx, jsWindow) of TAG_INPUT: let input = HTMLInputElement(element) input.reflect_str atValue, value @@ -3533,14 +3548,16 @@ proc execute*(element: HTMLScriptElement) = if window != nil and window.jsctx != nil: let script = element.scriptResult.script let urls = script.baseURL.serialize(excludepassword = true) + let ctx = window.jsctx if JS_IsException(script.record): - let s = document.window.jsctx.getExceptionStr() - document.window.console.log("Exception in document", urls, s) + let s = ctx.getExceptionStr() + window.console.log("Exception in document", urls, s) else: - let ret = window.jsctx.evalFunction(script.record) + let ret = ctx.evalFunction(script.record) if JS_IsException(ret): - let s = document.window.jsctx.getExceptionStr() - document.window.console.log("Exception in document", urls, s) + let s = ctx.getExceptionStr() + window.console.log("Exception in document", urls, s) + JS_FreeValue(ctx, ret) document.currentScript = oldCurrentScript else: discard #TODO if needsInc: diff --git a/src/html/enums.nim b/src/html/enums.nim index 4b4faa63..e422e790 100644 --- a/src/html/enums.nim +++ b/src/html/enums.nim @@ -68,6 +68,7 @@ type atMultiple = "multiple" atName = "name" atNomodule = "nomodule" + atOnload = "onload" atReferrerpolicy = "referrerpolicy" atRel = "rel" atRequired = "required" |