aboutsummaryrefslogtreecommitdiff
path: root/src/client/javascript/scrollSnap.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-29 16:31:05 +0100
committerGitHub <noreply@github.com>2018-01-29 16:31:05 +0100
commit694580bc532239a32c2fbf61d7f09e793fd1cb11 (patch)
treeacd21e2654d6c5e70dc41c675972794ce95b4062 /src/client/javascript/scrollSnap.js
parentf18692872cdc28d29917247ef4f8ef7553a8b023 (diff)
parent9a9edd1865d619caada787231c8bb34be25af3af (diff)
Merge pull request #15 from nloomans/react
Move project over to react
Diffstat (limited to 'src/client/javascript/scrollSnap.js')
-rw-r--r--src/client/javascript/scrollSnap.js59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/client/javascript/scrollSnap.js b/src/client/javascript/scrollSnap.js
deleted file mode 100644
index afee979..0000000
--- a/src/client/javascript/scrollSnap.js
+++ /dev/null
@@ -1,59 +0,0 @@
-require('smoothscroll-polyfill').polyfill()
-
-const self = {}
-const schedule = require('./schedule')
-
-self._nodes = {
- search: document.querySelector('#search'),
- weekSelector: document.querySelector('#week-selector')
-}
-
-self._timeoutID = null
-
-self._getScrollPosition = function () {
- return (document.documentElement && document.documentElement.scrollTop) ||
- document.body.scrollTop
-}
-
-self._handleDoneScrolling = function () {
- const scrollPosition = self._getScrollPosition()
- const weekSelectorHeight =
- self._nodes.weekSelector.clientHeight - self._nodes.search.clientHeight
- if (scrollPosition < weekSelectorHeight && scrollPosition > 0) {
- window.scroll({ top: weekSelectorHeight, left: 0, behavior: 'smooth' })
- }
-}
-
-self._handleScroll = function () {
- if (self._timeoutID != null) window.clearTimeout(self._timeoutID)
- self._timeoutID = window.setTimeout(self._handleDoneScrolling, 500)
-
- const scrollPosition = self._getScrollPosition()
- const weekSelectorHeight =
- self._nodes.weekSelector.clientHeight - self._nodes.search.clientHeight
- if (scrollPosition >= weekSelectorHeight) {
- document.body.classList.add('week-selector-not-visible')
- } else {
- document.body.classList.remove('week-selector-not-visible')
- }
-}
-
-self._handleWindowResize = function () {
- const weekSelectorHeight =
- self._nodes.weekSelector.clientHeight - self._nodes.search.clientHeight
- const extraPixelsNeeded =
- weekSelectorHeight - (document.body.clientHeight - window.innerHeight)
- if (extraPixelsNeeded > 0) {
- document.body.style.marginBottom = extraPixelsNeeded + 'px'
- } else {
- document.body.style.marginBottom = null
- }
-}
-
-self.startListening = function () {
- window.addEventListener('scroll', self._handleScroll)
-}
-
-schedule.on('load', self._handleWindowResize)
-window.addEventListener('resize', self._handleWindowResize)
-module.exports = self