Skip to content

Instantly share code, notes, and snippets.

@byverdu
Last active March 11, 2017 09:27
Show Gist options
  • Save byverdu/cdcdac38dd96ad5297b36fdf75e9d328 to your computer and use it in GitHub Desktop.
Save byverdu/cdcdac38dd96ad5297b36fdf75e9d328 to your computer and use it in GitHub Desktop.
entry point file, imports modules and appends functions to DOM
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