Documentation (#6200)

* vim backup files to be ignored

* added tip about using document$ observable
This commit is contained in:
Alexander Voss 2023-10-16 10:25:29 -04:00 committed by GitHub
parent e2fc46a299
commit 6a9b685405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,29 @@ extra_javascript:
- javascripts/extra.js - javascripts/extra.js
``` ```
!!! tip "Make sure the page is fully loaded"
It is likely that you will want to run your JavaScript code only
once the page has been fully loaded by the browser. This means
installing a callback function subscribing to events on the
`document$` observable exported by Material for MkDocs.
Using the `document$` observable is particularly important if you
are using [instant loading] since it will not result in a page
refresh in the browser - but subscribers on the observable will be
notified.
``` javascript
document$.subscribe(function() {
console.log("Page loaded.") // or whatever it is you want to do
})
```
`document$` is an [RxJS Observable] and you can call the `subscribe()`
method any number of times to attach different functionality.
[instant loading]: setup/setting-up-navigation.md/#instant-loading
[RxJS Observable]: https://rxjs.dev/api/index/class/Observable
## Extending the theme ## Extending the theme
If you want to alter the HTML source (e.g. add or remove some parts), you can If you want to alter the HTML source (e.g. add or remove some parts), you can