This repository was archived by the owner on Jan 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Fix for opening url with hash and scrolling webpage to correct place. #8
Open
adamlukaszczyk
wants to merge
3
commits into
Prinzhorn:master
Choose a base branch
from
adamlukaszczyk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,13 +138,33 @@ | |
|
|
||
| if(supportsHistory) { | ||
| window.addEventListener('popstate', function(e) { | ||
| var state = e.state || {}; | ||
| var top = state.top || 0; | ||
|
|
||
| defer(function() { | ||
| _skrollrInstance.setScrollTop(top); | ||
| }); | ||
| if (e.state) { | ||
| var state = e.state || {}; | ||
| var top = state.top || 0; | ||
|
|
||
| defer(function() { | ||
| _skrollrInstance.setScrollTop(top); | ||
| }); | ||
| } | ||
| }, false); | ||
|
|
||
| //In case the page was opened with a hash, prevent jumping to it. | ||
| //http://stackoverflow.com/questions/3659072/jquery-disable-anchor-jump-when-loading-a-page | ||
| defer(function() { | ||
| if(window.location.hash) { | ||
|
|
||
| window.scrollTo(0, 0); | ||
|
|
||
| if(document.querySelector) { | ||
| var link = document.querySelector('a[href="' + window.location.hash + '"]'); | ||
|
|
||
| if(link) { | ||
| handleLink(link, true); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Prinzhorn regarding your comments i'll put my explanation here as we have here all changes in one place. So I moved whole block of this code because you execute handleLink method here - it happens at script load time - and this is serious bug as handleLink can be executed only after initialization of module inside skrollr.menu.init() About window.scrollTo(0, 0); - I was not sure for what is it. So it can stay in old place. |
||
| }; | ||
|
|
||
|
|
@@ -155,19 +175,4 @@ | |
| var _duration; | ||
| var _animate; | ||
|
|
||
| //In case the page was opened with a hash, prevent jumping to it. | ||
| //http://stackoverflow.com/questions/3659072/jquery-disable-anchor-jump-when-loading-a-page | ||
| defer(function() { | ||
| if(window.location.hash) { | ||
| window.scrollTo(0, 0); | ||
|
|
||
| if(document.querySelector) { | ||
| var link = document.querySelector('a[href="' + window.location.hash + '"]'); | ||
|
|
||
| if(link) { | ||
| handleLink(link, true); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }(document, window)); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much experience with history manipulation and popstate event but I noticed that popstate event in Chrome is raised every time on page load event.
And on page load the e.state is null so then _skrollrInstance.setScrollTop(top); wants to scroll to top of the page (0px).
This is unwanted behavior as few moments before we scrolled down page to the accurate place pointed by the hash in URL.
Just take a look on it in action on my page:
http://smarttvrocket.com/#/pl/smart-tv
http://smarttvrocket.com/#/pl/oferta/mobileapps
http://smarttvrocket.com/#/pl/kontakt
Although I have not test it in Firefox ;)