Needs popstate option to resolve history issue #170

Closed
opened 2018-07-20 14:15:29 -05:00 by sleddd · 5 comments
sleddd commented 2018-07-20 14:15:29 -05:00 (Migrated from github.com)

If you use whenDOMReady and try hitting the back button, it won't fire using success | complete. To get whenDOMReady to fire when navigating with history (back | forward), you need to attach an event listener to popstate. (i.e. document.addEventListener('pjax:popstate', function(){ //do stuff });

If you alter the pjax library within the function that handles popstate at about line 53 with:
trigger(document,"pjax:popstate", state.options)

Then you will be able to add in your custom code:
document.addEventListener('pjax:popstate', whenDOMReady)

It will solve the DOM ready, etc... not firing on history issue.

I would suggest adding the pjax:popstate option...

If you use whenDOMReady and try hitting the back button, it won't fire using success | complete. To get whenDOMReady to fire when navigating with history (back | forward), you need to attach an event listener to popstate. (i.e. document.addEventListener('pjax:popstate', function(){ //do stuff }); If you alter the pjax library within the function that handles popstate at about line 53 with: trigger(document,"pjax:popstate", state.options) Then you will be able to add in your custom code: document.addEventListener('pjax:popstate', whenDOMReady) It will solve the DOM ready, etc... not firing on history issue. I would suggest adding the pjax:popstate option...
BehindTheMath commented 2018-07-20 14:32:54 -05:00 (Migrated from github.com)

What's wrong with the success or complete events?

What's wrong with the success or complete events?
BehindTheMath commented 2018-07-20 15:21:46 -05:00 (Migrated from github.com)

The popstate handler calls loadUrl() to load the page, just like when you click a new link. Further down the callstack, the pjax:success and pjax:complete events should be triggered.

The `popstate` handler calls `loadUrl()` to load the page, just like when you click a new link. Further down the callstack, the `pjax:success` and `pjax:complete` events should be triggered.
BehindTheMath commented 2018-07-20 15:32:42 -05:00 (Migrated from github.com)

I don't understand the issue. Popstate should trigger the success and complete events. Did you try it and it wasn't triggered?

I don't understand the issue. Popstate should trigger the success and complete events. Did you try it and it wasn't triggered?
BehindTheMath commented 2018-07-20 15:48:40 -05:00 (Migrated from github.com)

Please post your code that reproduces the issue, so I can try to debug it.

Please post your code that reproduces the issue, so I can try to debug it.
sleddd commented 2018-07-20 15:54:12 -05:00 (Migrated from github.com)

All I can tell you, is that it does not always trigger with success/complete and reliably works with popstate. Thank you for your help, but I have resolved my issue.

All I can tell you, is that it does not always trigger with success/complete and reliably works with popstate. Thank you for your help, but I have resolved my issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#170