Skip to content

Commit

Permalink
v4.0.2
Browse files Browse the repository at this point in the history
* Combines existing history state on in-page navigation
* Avoids errors on old browsers (e.g., IE9) that don’t support
history.pushState() and history.replaceState()
  • Loading branch information
zengabor committed Feb 28, 2018
1 parent b8edb6c commit e71b5c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenscroll",
"version": "4.0.1",
"version": "4.0.2",
"description": "A module to smooth-scroll web pages and scrollable elements (like DIVs)",
"main": "zenscroll.js",
"files": ["zenscroll.js", "zenscroll-min.js"],
Expand Down
2 changes: 1 addition & 1 deletion zenscroll-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions zenscroll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Zenscroll 4.0.1
* Zenscroll 4.0.2
* https://github.com/zengabor/zenscroll/
*
* Copyright 2015–2018 Gabor Lenard
Expand Down Expand Up @@ -258,8 +258,8 @@
// Exclude IE8- or when native is enabled or Zenscroll auto- is disabled
if ("addEventListener" in window && !window.noZensmooth && !isNativeSmoothScrollEnabledOn(document.body)) {


var isScrollRestorationSupported = "scrollRestoration" in history
var isHistorySupported = "history" in window && "pushState" in history
var isScrollRestorationSupported = isHistorySupported && "scrollRestoration" in history

// On first load & refresh make sure the browser restores the position first
if (isScrollRestorationSupported) {
Expand Down Expand Up @@ -313,8 +313,10 @@
}
// Save the current scrolling position so it can be used for scroll restoration:
if (isScrollRestorationSupported) {
var historyState = history.state && typeof history.state === "object" ? history.state : {}
historyState.zenscrollY = zenscroll.getY()
try {
history.replaceState({ zenscrollY: zenscroll.getY() }, "")
history.replaceState(historyState, "")
} catch (e) {
// Avoid the Chrome Security exception on file protocol, e.g., file://index.html
}
Expand All @@ -338,7 +340,9 @@
var edgeOffset = zenscroll.setup().edgeOffset
if (edgeOffset) {
targetY = Math.max(0, targetY - edgeOffset)
onDone = function () { history.pushState(null, "", href) }
if (isHistorySupported) {
onDone = function () { history.pushState({}, "", href) }
}
}
zenscroll.toY(targetY, null, onDone)
}
Expand Down

0 comments on commit e71b5c9

Please sign in to comment.