aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorhkcomori <hkcomori@gmail.com>2025-03-25 18:18:33 +0900
committerGitHub <noreply@github.com>2025-03-25 10:18:33 +0100
commit9e8c306b3edbda071cdd9cc93bcc45055789ad42 (patch)
treefdab50cbbbf4f4a2d835f90cd894c980d0c189f5
parenta130f96646d403edafe377b4011d94edcbd7221d (diff)
downloadfreshrss-9e8c306b3edbda071cdd9cc93bcc45055789ad42.tar.gz
freshrss-9e8c306b3edbda071cdd9cc93bcc45055789ad42.zip
JavaScript: new event to detect context loaded (#7452)
* Add JavaScript event: freshrss:globalContextLoaded * Update docs * Update docs: fix typo
-rw-r--r--docs/en/developers/03_Backend/05_Extensions.md18
-rw-r--r--p/scripts/main.js3
2 files changed, 21 insertions, 0 deletions
diff --git a/docs/en/developers/03_Backend/05_Extensions.md b/docs/en/developers/03_Backend/05_Extensions.md
index 2a4c4dcf0..cf0fa3386 100644
--- a/docs/en/developers/03_Backend/05_Extensions.md
+++ b/docs/en/developers/03_Backend/05_Extensions.md
@@ -183,6 +183,24 @@ The following events are available:
> ℹ️ Note: the `simplepie_*` hooks are only fired for feeds using SimplePie via pull, i.e. normal RSS/Atom feeds. This excludes WebSub (push), and the various HTML or JSON Web scraping methods.
+### JavaScript events
+
+```javascript
+function use_context() {
+ // Something that refers to the window.context
+}
+
+if (document.readyState && document.readyState !== 'loading' && typeof window.context !== 'undefined' && typeof window.context.extensions !== 'undefined') {
+ use_context();
+} else {
+ document.addEventListener('freshrss:globalContextLoaded', use_context, false);
+}
+```
+
+The following events are available:
+
+* `freshrss:globalContextLoaded`: will be dispatched after load the global `context` variable, useful for referencing variables injected with the `js_vars` hook.
+
### Injecting CDN content
When using the `init` method, it is possible to inject scripts from CDN using the `Minz_View::appendScript` directive.
diff --git a/p/scripts/main.js b/p/scripts/main.js
index 112b38bce..73ac27ddd 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -53,6 +53,9 @@ var context;
context.icons.unread = decodeURIComponent(context.icons.unread);
context.extensions = json.extensions;
}());
+
+const freshrssGlobalContextLoadedEvent = new Event('freshrss:globalContextLoaded');
+document.dispatchEvent(freshrssGlobalContextLoadedEvent);
// </Global context>
function badAjax(reload) {