Skip to content

Commit

Permalink
fix(docs): fix compatibility with IE (Semantic-Org#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and levithomason committed May 8, 2017
1 parent 9820e62 commit df96ba4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions docs/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const parentComponents = _.flow(
_.sortBy('_meta.name')
)(semanticUIReact)

const mathSign = Math.sign || function (x) {
x = +x
if (x === 0 || isNaN(x)) {
return x
}
return x > 0 ? 1 : -1
}

/**
* Get the Webpack Context for all doc site examples.
*/
Expand All @@ -27,6 +35,7 @@ export const semanticUICSSRepoURL = 'https://github.com/Semantic-Org/Semantic-UI

export const scrollToAnchor = () => {
const anchor = location.hash && document.querySelector(location.hash)
const offsetY = window.scrollY || window.pageYOffset

// no scroll to target, stop
if (!anchor) return
Expand All @@ -37,9 +46,9 @@ export const scrollToAnchor = () => {
if (elementTop === 0) return

// hit max scroll boundaries, stop
const isScrolledToTop = scrollY === 0
const isScrolledToBottom = scrollY + document.body.clientHeight === document.body.scrollHeight
const scrollStep = Math.ceil((Math.abs(elementTop / 8))) * Math.sign(elementTop)
const isScrolledToTop = offsetY === 0
const isScrolledToBottom = offsetY + document.body.clientHeight === document.body.scrollHeight
const scrollStep = Math.ceil((Math.abs(elementTop / 8))) * mathSign(elementTop)

if (isScrolledToBottom && scrollStep > 0 || isScrolledToTop && scrollStep < 0) return

Expand Down

0 comments on commit df96ba4

Please sign in to comment.