Skip to content

Conversation

SilverFire
Copy link
Member

This PR adds skipOuter option.

The use case:

<div class="container" id="pjax-container"> Go to <a href="/page/2">next page</a>. <div class="status-container" id="pjax-status-container"> <span>Last check found no errors on page 1</span> <a href="/update-status/page/1">Check again</a> </div> </div> <script> $(document).pjax('a', '#pjax-container'); $(document).pjax('a', '#pjax-status-container', { push: false, replace: false, timeout: 0 }) </script>

I want to use a link inside div#pjax-container to navigate between pages with pushing URLs to the history. Every page displays some info and has a button Check again to update that info without page refresh or pushing to the browser history. As you see, I placed the button inside new container and defined a special config for it.

Without out this PR, the config of #pjax-status-container is useless, because the network request of #pjax-status-container will be immediately aborted by #pjax-container. Then #pjax-container will create his own request and process it according to it's rules.

When skipOuter = true only the closest container will handle the request.

The options defaults to false, so it doesn't break BC.

@SilverFire
Copy link
Member Author

@nkovacs I know you are familiar with pjax. Could you take a look, please?

@samdark
Copy link
Member

samdark commented Nov 19, 2015

Name sounds a bit too vague to me. The logic of the change is OK.

@SilverFire
Copy link
Member Author

There were two other names, that I tried:

  • skipOuterPjax: we are configuring pjax, there's no necessity in pjax tie
  • skipOuterContainers: clear, but long

When anyone has better name - please, text it!

@samdark
Copy link
Member

samdark commented Nov 20, 2015

skipOuterContainers sounds much better to me even if it's longer.

@SilverFire
Copy link
Member Author

Okay, let it be skipOuterContaiters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\r\n -> \n

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@nkovacs
Copy link

nkovacs commented Nov 20, 2015

There are some fixes to nested containers and pjax's cache upstream. It's also possible Yii's widget is initializing the pjax code incorrectly.

@SilverFire
Copy link
Member Author

There are some fixes to nested containers

Yeah, it's time to merge with origin. @samdark ?

It's also possible Yii's widget is initializing the pjax code incorrectly.

Why?

@nkovacs
Copy link

nkovacs commented Nov 20, 2015

There are various ways to configure pjax, e.g. you can add data-pjax="container-selector" on links to specify a container instead of doing it in the $.pjax call. Maybe some combination of these makes nested containers work, and another breaks them.
I'd try reproducing this with the upstream version, without Yii, first.

@nkovacs
Copy link

nkovacs commented Nov 20, 2015

Looking at the pjax code:
it calls preventDefault:
https://github.com/defunkt/jquery-pjax/blob/master/jquery.pjax.js#L98
and it checks for isDefaultPrevented: https://github.com/defunkt/jquery-pjax/blob/master/jquery.pjax.js#L83

So the outer container should receive the event with isDefaultPrevented, and abort.

@SilverFire
Copy link
Member Author

@nkovacs You think we should call event.preventDefault() instead on return here?

@SilverFire
Copy link
Member Author

Will merge this if nobody complains

@SilverFire
Copy link
Member Author

@nkovacs I checked it. It's not the same.

@SilverFire SilverFire changed the title Added skipOuter option Added skipOuterContainers option Nov 23, 2015
@SilverFire
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants