|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
import $ from 'jquery' |
|
|
|
|
import _ from 'lodash' |
|
|
|
|
import { createStore } from 'redux' |
|
|
|
|
|
|
|
|
@ -32,3 +33,42 @@ export function initRedux (reducer, { main, render, debug } = {}) { |
|
|
|
|
} |
|
|
|
|
if (main) main(store) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function prependWithClingBottom ($el, content) { |
|
|
|
|
function userAtTop () { |
|
|
|
|
return window.scrollY < $('[data-selector="navbar"]').outerHeight() |
|
|
|
|
} |
|
|
|
|
if (userAtTop()) return $el.prepend(content) |
|
|
|
|
|
|
|
|
|
let isAnimating |
|
|
|
|
function setIsAnimating () { |
|
|
|
|
isAnimating = true |
|
|
|
|
} |
|
|
|
|
$el.on('animationstart', setIsAnimating) |
|
|
|
|
|
|
|
|
|
let startingScrollPosition = window.scrollY |
|
|
|
|
let endingScrollPosition = window.scrollY |
|
|
|
|
function userIsScrolling () { |
|
|
|
|
return window.scrollY < startingScrollPosition || endingScrollPosition < window.scrollY |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const clingDistanceFromBottom = document.body.scrollHeight - window.scrollY |
|
|
|
|
let clingBottomLoop = window.requestAnimationFrame(function clingBottom () { |
|
|
|
|
if (userIsScrolling()) return stopClinging() |
|
|
|
|
|
|
|
|
|
startingScrollPosition = window.scrollY |
|
|
|
|
endingScrollPosition = document.body.scrollHeight - clingDistanceFromBottom |
|
|
|
|
$(window).scrollTop(endingScrollPosition) |
|
|
|
|
clingBottomLoop = window.requestAnimationFrame(clingBottom) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function stopClinging () { |
|
|
|
|
window.cancelAnimationFrame(clingBottomLoop) |
|
|
|
|
$el.off('animationstart', setIsAnimating) |
|
|
|
|
$el.off('animationend animationcancel', stopClinging) |
|
|
|
|
} |
|
|
|
|
$el.on('animationend animationcancel', stopClinging) |
|
|
|
|
setTimeout(() => !isAnimating && stopClinging(), 100) |
|
|
|
|
|
|
|
|
|
return $el.prepend(content) |
|
|
|
|
} |
|
|
|
|