qmd-lab / closeread

https://closeread.dev
MIT License
130 stars 5 forks source link

Access default scroller state in OJS #14

Closed jimjam-slam closed 1 year ago

jimjam-slam commented 1 year ago

This is stretch goal, but I'm doing some early thinking about it!

Our default scroller is loaded via vanilla JS ( we can't do it in OJS without a lot of work—a user could themselves, but as I learned in Sverto, injecting OJS content is currently messy as hell. I thought it would be great if that default scroller we initialise could update an OJS variable (or a few!). That way, an extension user could drive an OJS chart or animation based on scroll with basically zero setup.

I've posted on the Quarto discussions about this:

https://github.com/quarto-dev/quarto-cli/discussions/6415

The OJS runtime describes the process of declaring variables inside a module, and I can see the Quarto OJS notebook module in the global window. So there might be a way to hook into that once the doc loads and potentially have our scroller update a variable. I'll see how I go with it!

jimjam-slam commented 1 year ago

Got this to a state where I think it works well! I'll hold off on adding it to the code here until we have the other code going, but the basic gist is that as part of our scroller setup, we register an OJS variable. Then the callbacks update that variable to the new scroller index by calling .define() again.

jimjam-slam commented 1 year ago

Added this in https://github.com/quarto-lab/close-read/pull/15/commits/2acec2054d33c0416c9423dcc029e7c2faf0e70e (in #15)! It works very nicely 😊 I'll put a separate demo together for it at some point!