parent
2102e3b02f
commit
b7f1757952
1 changed files with 31 additions and 0 deletions
|
|
@ -9,6 +9,37 @@
|
||||||
|
|
||||||
## Declaration of the Document Object Model for the `JavaScript backend
|
## Declaration of the Document Object Model for the `JavaScript backend
|
||||||
## <backends.html#backends-the-javascript-target>`_.
|
## <backends.html#backends-the-javascript-target>`_.
|
||||||
|
##
|
||||||
|
##
|
||||||
|
## Document Ready
|
||||||
|
## --------------
|
||||||
|
##
|
||||||
|
## * Basic example of a document ready:
|
||||||
|
runnableExamples"-b:js -r:off":
|
||||||
|
proc example(e: Event) = echo "Document is ready"
|
||||||
|
document.addEventListener("DOMContentLoaded", example) # You can also use "load" event.
|
||||||
|
## * This example runs 5 seconds after the document ready:
|
||||||
|
runnableExamples"-b:js -r:off":
|
||||||
|
proc example() = echo "5 seconds after document ready"
|
||||||
|
proc domReady(e: Event) = discard setTimeout(example, 5_000) # Document is ready.
|
||||||
|
document.addEventListener("DOMContentLoaded", domReady)
|
||||||
|
## Document onUnload
|
||||||
|
## -----------------
|
||||||
|
##
|
||||||
|
## * Simple example of how to implement code that runs when the page unloads:
|
||||||
|
runnableExamples"-b:js -r:off":
|
||||||
|
proc example(e: Event) = echo "Document is unloaded"
|
||||||
|
document.addEventListener("unload", example) # You can also use "beforeunload".
|
||||||
|
## Document Autorefresh
|
||||||
|
## --------------------
|
||||||
|
##
|
||||||
|
## * Minimal example of a document autorefresh:
|
||||||
|
runnableExamples"-b:js -r:off":
|
||||||
|
proc example() = window.location.reload()
|
||||||
|
discard setTimeout(example, 5_000)
|
||||||
|
## - For more examples, see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
||||||
|
|
||||||
|
|
||||||
import std/private/since
|
import std/private/since
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
{.error: "This module only works on the JavaScript platform".}
|
{.error: "This module only works on the JavaScript platform".}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue