I'm interested into a method like self.play
from apostrophe-widgets that permit us apply Jquery selectors without having any doubt that the selector only should be applied to the widget, thanks to $widget
parameter.
What I want to obtain is the same behaviour but with apostrophe-pages, I've research into the documentation and I didn't find anything. Is there any way to replicate the same behaviour?
I let a reference to the method I'm talking about to clarify the question. https://docs.apostrophecms.org/apostrophe/modules/apostrophe-widgets#more
Thanks for your help!
Currently there is no equivalent player
for pages. Typically we push those front-end modules all the time and let them decide when they're relevant or not. Because there is no equivalent, there is no concept of a safe jQuery $widget
object or data
about the page being passed down.
That pattern around pushing page-specific modules is illustrated in the Open Museum demo in the apostrophe-assets
module.
https://github.com/apostrophecms/apostrophe-open-museum/tree/master/lib/modules/apostrophe-assets
A widget's player
method is really nice because it knows to re-run itself when Apostrophe does various editing/saving operations. You can get similar re-running behavior anywhere by listening for the front-end apos
event ready
. A bit of documentation on that here https://docs.apostrophecms.org/apostrophe/tutorials/howtos/migration#browser-side-javascript-is-pretty-close-to-the-same