Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pjax without making a server request #381

Open
marczking opened this issue Apr 30, 2014 · 5 comments
Open

Use pjax without making a server request #381

marczking opened this issue Apr 30, 2014 · 5 comments
Labels

Comments

@marczking
Copy link

Sometimes I want to only change some small things with JS only for which I don't need to make a request to the server. I would still like to change the history.pushState though.

When using history.pushState manually I get my wished behaviour, only problem is when navigating with back/forward-buttons pjax:popstate does not fire on the manually set pushstates.

So is there a way I can do this with pjax?

@trompx
Copy link

trompx commented Jun 25, 2014

+1 I am trying to do the same (I just need to fade an overlay to go back to the main main page and change url without breaking back/forward). Reloading the same main content just to change the url is overkill.

I already tried to simulate a pjax cachepush followed by a pushstate with a manually created state but pjax:popstate is not firing.

So is there a way to add a state that would trigger pjax:popstate manually ?

@marczking did you come up with a solution ?

@mislav
Copy link
Collaborator

mislav commented Jun 26, 2014

Right now it's tricky to mix pjax stuff with manual pushState/popstate stuff. You shouldn't expect pjax:popstate to fire, though, if you didn't use pjax. If it does, that's a bug.

I'll leave this open as a reminder that we need to improve pjax in scenarios where you mix-n-match it with other pushState functionality.

@kirkbushell
Copy link

This kind of requirement usually smells of an anti-pattern. You generally only want pushstate updates when big changes happen (such as general content replacement). Anything smaller is usually a code smell. You don't want URLs acting as application state management tools.

@samdark
Copy link

samdark commented Jan 22, 2015

    // disable and then re-enable to make sure our handler is before PJAX's
    $.pjax.disable();
    $(window).on('popstate', function (e) {
        if (!needPjax()) {
            $.pjax.disable();
            e.stopImmediatePropagation();
            // do your non-PJAX stuff here
            $.pjax.enable();
        }
    });
    $.pjax.enable();

@samdark
Copy link

samdark commented Jan 22, 2015

But overall I'd love to be able to prevent fragment replacing if pjax:popstate handler returns false or prevents default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants