diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-02-08 18:41:59 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-02-08 18:41:59 +0100 |
| commit | 6432329809af23dd246cbd0802896273e6c5f1f4 (patch) | |
| tree | 70b7f9bc7a0475252a4151d705a90a28c82624c8 /src | |
| parent | 4a727c2d8998f5ab68612fddff2f3080121dc551 (diff) | |
| download | chawan-6432329809af23dd246cbd0802896273e6c5f1f4.tar.gz | |
dom: add fireEvent for Event objects
Diffstat (limited to 'src')
| -rw-r--r-- | src/html/dom.nim | 5 | ||||
| -rw-r--r-- | src/html/env.nim | 2 | ||||
| -rw-r--r-- | src/html/xmlhttprequest.nim | 2 | ||||
| -rw-r--r-- | src/server/buffer.nim | 6 |
4 files changed, 9 insertions, 6 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index b70c061f..582d7907 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2851,10 +2851,13 @@ func findAutoFocus*(document: Document): Element = return child return nil +proc fireEvent*(window: Window; event: Event; target: EventTarget) = + discard window.jsctx.dispatch(target, event) + proc fireEvent*(window: Window; name: StaticAtom; target: EventTarget) = let event = newEvent(window.toAtom(name), target) event.isTrusted = true - discard window.jsctx.dispatch(target, event) + window.fireEvent(event, target) proc parseColor(element: Element; s: string): ARGBColor = let cval = parseComponentValue(s) diff --git a/src/html/env.nim b/src/html/env.nim index d140bd44..a771a33f 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -327,7 +327,7 @@ proc postMessage(ctx: JSContext; window: Window; value: JSValue): Err[void] cstring"<postMessage>") let event = ctx.newMessageEvent(ctx.toAtom(satMessage), MessageEventInit(data: data)) - discard ctx.dispatch(window, event) + window.fireEvent(event, window) ok() proc setOnLoad(ctx: JSContext; window: Window; val: JSValue) diff --git a/src/html/xmlhttprequest.nim b/src/html/xmlhttprequest.nim index 5f85aee6..af3df80b 100644 --- a/src/html/xmlhttprequest.nim +++ b/src/html/xmlhttprequest.nim @@ -194,7 +194,7 @@ proc fireProgressEvent(window: Window; target: EventTarget; name: StaticAtom; total: length, lengthComputable: length != 0 )) - discard window.jsctx.dispatch(target, event) + window.fireEvent(event, target) proc errorSteps(window: Window; this: XMLHttpRequest; name: StaticAtom) = this.readyState = xhrsDone diff --git a/src/server/buffer.nim b/src/server/buffer.nim index b171392a..51eefe57 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -1031,14 +1031,14 @@ proc dispatchDOMContentLoadedEvent(buffer: Buffer) = let window = buffer.window let event = newEvent(window.toAtom(satDOMContentLoaded), buffer.document) event.isTrusted = true - discard window.jsctx.dispatch(buffer.document, event) + window.fireEvent(event, buffer.document) buffer.maybeReshape() proc dispatchLoadEvent(buffer: Buffer) = let window = buffer.window let event = newEvent(window.toAtom(satLoad), window) event.isTrusted = true - discard window.jsctx.dispatch(window, event) + window.fireEvent(event, window) buffer.maybeReshape() proc finishLoad(buffer: Buffer; data: InputData): EmptyPromise = @@ -1361,7 +1361,7 @@ proc readSuccess*(buffer: Buffer; s: string; hasFd: bool): Request {.proxy.} = let inputEvent = newInputEvent(window.toAtom(satInput), InputEventInit(data: some(s), inputType: "insertText")) inputEvent.isTrusted = true - discard window.jsctx.dispatch(input, inputEvent) + window.fireEvent(inputEvent, input) buffer.window.fireEvent(satChange, input) buffer.maybeReshape() return buffer.implicitSubmit(input) |