mirror of
https://github.com/quartz-community/plugin-template.git
synced 2026-07-22 02:50:24 +00:00
feat: add render event listener pattern to plugin template
This commit is contained in:
parent
ce9a7d186b
commit
462c6acb6a
1 changed files with 8 additions and 1 deletions
|
|
@ -5,7 +5,7 @@
|
|||
// It is bundled as a string and injected via Component.afterDOMLoaded.
|
||||
//
|
||||
// Key patterns demonstrated:
|
||||
// 1. Listening to Quartz navigation events ('nav', 'prenav')
|
||||
// 1. Listening to Quartz navigation events ('nav', 'prenav', 'render')
|
||||
// 2. Fetching content index data
|
||||
// 3. DOM manipulation with cleanup
|
||||
// 4. State persistence (localStorage/sessionStorage)
|
||||
|
|
@ -90,12 +90,19 @@ function init() {
|
|||
|
||||
// Listen to Quartz navigation events
|
||||
// 'nav' fires after page navigation (including initial load)
|
||||
// 'render' fires when DOM content changes in-place (e.g. after decryption, dynamic content)
|
||||
document.addEventListener("nav", (e) => {
|
||||
const slug = e.detail?.url || getCurrentSlug();
|
||||
console.log("[ExampleComponent] Navigation to:", slug);
|
||||
init();
|
||||
});
|
||||
|
||||
// 'render' fires when DOM content changes in-place and components need re-initialization
|
||||
document.addEventListener("render", () => {
|
||||
console.log("[ExampleComponent] Render event - re-initializing");
|
||||
init();
|
||||
});
|
||||
|
||||
// 'prenav' fires before navigation - use for saving state
|
||||
document.addEventListener("prenav", () => {
|
||||
// Example: Save scroll position before navigation
|
||||
|
|
|
|||
Loading…
Reference in a new issue