1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-11-15 09:35:17 +01:00
portfolio/gatsby-browser.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-28 22:30:20 +02:00
import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
// Global styles
2020-03-07 03:11:52 +01:00
import './src/styles/global.css'
2021-09-19 16:22:05 +02:00
import './src/styles/_toast.css'
2018-06-23 14:36:07 +02:00
2018-09-14 18:27:49 +02:00
// IntersectionObserver polyfill for gatsby-image (Safari, IE)
if (typeof window !== 'undefined' && !window.IntersectionObserver) {
import('intersection-observer')
2018-06-23 14:36:07 +02:00
}
2018-09-14 18:27:49 +02:00
2019-04-28 22:30:20 +02:00
// Layout with Page Transitions
export const wrapPageElement = wrapPageElementWithLayout
export const shouldUpdateScroll = ({
routerProps: { location },
getSavedScrollPosition
}) => {
if (location.action === 'PUSH') {
window.setTimeout(() => window.scrollTo(0, 0), 200)
} else {
const savedPosition = getSavedScrollPosition(location)
window.setTimeout(() => window.scrollTo(...(savedPosition || [0, 0])), 200)
}
return false
}
// Display a message when a service worker updates
// https://www.gatsbyjs.org/docs/add-offline-support-with-a-service-worker/#displaying-a-message-when-a-service-worker-updates
export const onServiceWorkerUpdateReady = () => {
2021-09-19 16:22:05 +02:00
const div = document.createElement('div')
div.id = 'toast'
div.classList.add('alert', 'alert-info')
div.innerHTML = `<button onClick="window.location.reload()">Updates are available. <span>Click to Reload</span>.</button>`
document.body.append(div)
}