Add use.whenReady function
This commit is contained in:
parent
797b6448c8
commit
34cac3913f
2 changed files with 15 additions and 4 deletions
7
use.js
7
use.js
|
@ -32,6 +32,13 @@ export const run = (root = document) => {
|
|||
root.querySelectorAll("[use]").forEach(use)
|
||||
}
|
||||
|
||||
export const whenReady = () => {
|
||||
if (document.readyState == "complete")
|
||||
run(document)
|
||||
else
|
||||
document.addEventListener("readystatechange", whenReady, {once: true})
|
||||
}
|
||||
|
||||
export const install = () => {
|
||||
observe(document)
|
||||
run(document)
|
||||
|
|
12
use.md
12
use.md
|
@ -43,11 +43,15 @@ use.observe(root=document)
|
|||
// child elements. Does not perform an initial run over
|
||||
// already existing elements.
|
||||
|
||||
use.use(element)
|
||||
// Runs once on a selected element.
|
||||
// Normally not recommended.
|
||||
|
||||
use.install()
|
||||
// Observes the entire document and performs
|
||||
// an initial scan over existing elements.
|
||||
|
||||
use.whenReady()
|
||||
// Waits for the document to be ready, then
|
||||
// runs once on the whole document.
|
||||
|
||||
use.use(element)
|
||||
// Runs once on a selected element.
|
||||
// Normally not recommended.
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue