Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Change History state without reloading content? #87

Open
wideopenspaces opened this issue Sep 11, 2014 · 3 comments
Open

Change History state without reloading content? #87

wideopenspaces opened this issue Sep 11, 2014 · 3 comments

Comments

@wideopenspaces
Copy link

Hello!

Wiselinks has been pretty much perfect for my application, but I have a situation where I'd like to push information into the History stack without causing a reload (namely, 'pagination' via infinite scroll)

What I want to do is:

User goes to

http://example.org/home

and then scrolls down a ways, and a second page of content is loaded. I want the url in the title bar and the History stack to reflect this:

http://example.org/home?page=2

What currently happens, though, is that when I attempt to change history:

History.pushState( { page: 2}, 'page the 2nd!', 'http://example.org/home?page=2' );

wiselinks kicks in and replaces my existing content with the content of page 2.

I'm thinking that I just need to provide a way to disable wiselinks' event listener for the pushState(?) event while I'm making the change, and then re-enable it afterward. Or would it pick up the new URL in the history the moment I re-enable?

@kshmir
Copy link

kshmir commented Oct 29, 2014

In this branch I am attempting to fix what you are reporting.

https://github.com/kshmir/wiselinks/tree/no_wiselinks_flag

@mjrk
Copy link

mjrk commented Nov 26, 2014

@kshmir thanks for sharing your approach!

However, there is a small pitfall in storing no_wiselinks (or skipLoadingPage in my case) in the state data object. If you continue and use the back button afterwards, your page won't be loaded because the data.no_wiselinks is still set. Therefore I implemented the feature like this

originalCall = window._Wiselinks.Page.prototype._call
window._Wiselinks.Page.prototype._call = (state) ->
  return if Wiselinks.skipLoadingPage
  originalCall.apply(this, arguments)

Wiselinks.skipLoadingPage = true
  # do your state changes
Wiselinks.skipLoadingPage = false

@kshmir
Copy link

kshmir commented Nov 26, 2014

Amazing! I didnt stop to bother around that issue sorry for not mentioning
it

On Wed, Nov 26, 2014, 12:33 mjrk [email protected] wrote:

@kshmir https://github.com/kshmir thanks for sharing your approach!

However, there is a small pitfall in storing no_wiselinks (or
skipLoadingPage in my case) in the state data object. If you continue and
use the back button afterwards, your page won't be loaded because the
data.no_wiselinks is still set. Therefore I implemented the feature like
this

originalCall = window._Wiselinks.Page.prototype._call
window._Wiselinks.Page.prototype._call = (state) ->
return if Wiselinks.skipLoadingPage
originalCall.apply(this, arguments)

Wiselinks.skipLoadingPage = true

do your state changes

Wiselinks.skipLoadingPage = false


Reply to this email directly or view it on GitHub
#87 (comment)
.

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

No branches or pull requests

3 participants