4 ms·
I tried it out and binding to the pjax:end works. So just wrap any code called by document.ready into a separate function. Then bind it to both document.ready a
by dmix 14y ago
I tried it out and binding to the pjax:end works. So just wrap any code called by document.ready into a separate function. Then bind it to both document.ready and:
$(window).bind('pjax:end', ->
# document ready code
)
- jarin 14y agoHmm that doesn't seem to work with turbolinks. page:change works, but it fires on every change, not just when the body contains the event. I tried making a pageLoad() function on pages that need extra functionality and then putting the following in the head: $(function() { pageLoad(); }); $(window).bind('page:change', function() { pageLoad(); }); However, it calls the originally set pageLoad() on every subsequent update. Maybe if there was some way to clear the function before it replaces the content?
- jrochkind1 14y agoHmm, I wonder if there's any way to have an event on page:change that somehow _sends_ a document.ready trigger. So it will trigger all document.ready hooks, without any changes to the code hooking into document.ready (which of course could come from third-party dependencies you can't easily change to use page:change themselves, and which may not want to be changed to have turbolinks-related code in them). Might be easier if your code exclusively uses jquery's ready rather than native DOM onload or whatever. But yeah, either way, this is a bunch of added logic that can go wrong, I'm not super enthused about it myself.