Last active
March 11, 2017 09:27
-
-
Save byverdu/cdcdac38dd96ad5297b36fdf75e9d328 to your computer and use it in GitHub Desktop.
entry point file, imports modules and appends functions to DOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { whichUserAgent, isFirefoxAgent, isWebKitAgent, isOldInternetExplorer } from './modules/userAgent'; | |
import { doHttpRequest } from './modules/httpRequest'; | |
document.addEventListener( 'DOMContentLoaded', () => { | |
/** | |
* checkHeightBody - Calls isFirefoxAgent, isWebKitAgent or isOldInternetExplorer | |
* dependig on userAgent | |
* | |
* @param {Object} navigatorObject navigator Object | |
* @return {Boolean} - | |
*/ | |
function checkHeightBody( navigatorObject ) { | |
let checkHeight; | |
const actualUserAgent = whichUserAgent( navigatorObject ); | |
switch ( actualUserAgent ) { | |
// Firefox | |
case 'Firefox' : | |
checkHeight = isFirefoxAgent(); | |
break; | |
// Chrome, Safari, IE Edge | |
case 'AppleWebKit' : | |
checkHeight = isWebKitAgent(); | |
break; | |
// IE old versions | |
case 'Trident' : | |
checkHeight = isOldInternetExplorer(); | |
break; | |
default: | |
checkHeight = ''; | |
} | |
return checkHeight; | |
} | |
/** | |
* loadInfiniteScroll - callback passed to scroll event, | |
* checks if scroll reaches the bottom | |
*/ | |
function loadInfiniteScroll() { | |
const checkHeight = checkHeightBody( navigator ); | |
if ( checkHeight ) { | |
doHttpRequest(); | |
} | |
} | |
document.addEventListener( 'scroll', loadInfiniteScroll ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment