Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): fix compatibility with IE #1659

Merged
merged 1 commit into from
May 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@layershifter layershifter May 7, 2017

Choose a reason for hiding this comment

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

pageYOffset is alias for scrollY, but it's supported from IE 9


// 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)
Copy link
Member Author

Choose a reason for hiding this comment

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

Math.sign is not supported in IE at all.


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

Expand Down