about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-25 15:00:33 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-25 15:00:33 +0200
commit9d4f8dc7a7f0a49d2f78cd81c9812852f906c518 (patch)
tree5d333b94f384e4e1d2e3dbaba1dcab8ac2dc7431
parent34cb7ac286ed5e37c6ff3774387b6a3eee6ab046 (diff)
downloadchawan-9d4f8dc7a7f0a49d2f78cd81c9812852f906c518.tar.gz
buffer: call load event on load
-rw-r--r--src/server/buffer.nim14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index f5ece03b..e722e31d 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -1023,6 +1023,17 @@ proc resolveTask[T](buffer: Buffer, cmd: BufferCommand, res: T) =
   buffer.pstream.swrite(res)
   buffer.pstream.flush()
 
+proc dispatchLoadEvent(buffer: Buffer) =
+  let window = buffer.window
+  if window == nil:
+    return
+  for el in window.eventListeners:
+    if el.ctype == "load":
+      let event = newEvent(window.jsctx, "load", window, window)
+      let e = el.callback(event)
+      if e.isErr:
+        buffer.window.jsctx.writeException(buffer.estream)
+
 proc onload(buffer: Buffer) =
   var res: LoadResult = (false, buffer.lines.len, -1)
   case buffer.state
@@ -1052,6 +1063,7 @@ proc onload(buffer: Buffer) =
       res.atend = true
       buffer.finishLoad().then(proc() =
         buffer.state = LOADED
+        buffer.dispatchLoadEvent()
         buffer.resolveTask(LOAD, res))
       return
     buffer.resolveTask(LOAD, res)
@@ -1477,7 +1489,7 @@ proc dispatchEvent(buffer: Buffer, ctype: string, elem: Element): tuple[
   for a in elem.branch:
     var stop = false
     for el in a.eventListeners:
-      if el.ctype == "click":
+      if el.ctype == ctype:
         let event = newEvent(buffer.window.jsctx, ctype, elem, a)
         let e = el.callback(event)
         called = true