2018-06-01 20:55:26 -04:00
|
|
|
|
let loaderOffset = 10;
|
|
|
|
|
let loadCount = 10;
|
2018-05-30 21:50:20 -04:00
|
|
|
|
let isLoaderLoading = false;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
let loadUri = '';
|
|
|
|
|
let loaderResponseId = '';
|
|
|
|
|
|
2018-06-01 20:55:26 -04:00
|
|
|
|
function initLoader(location, loaderId, count = 10) {
|
2018-05-28 21:30:31 -04:00
|
|
|
|
loadUri = location;
|
|
|
|
|
loaderResponseId = loaderId;
|
2018-06-01 20:55:26 -04:00
|
|
|
|
loadCount = count;
|
|
|
|
|
loaderOffset = count;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
setupListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadMoreItems() {
|
2018-05-30 21:50:20 -04:00
|
|
|
|
if (isLoaderLoading) {
|
2018-05-28 21:30:31 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showLoader();
|
2018-05-30 21:50:20 -04:00
|
|
|
|
isLoaderLoading = true;
|
|
|
|
|
$.get(loadUri, { offset: loaderOffset, count : loadCount })
|
2018-05-28 21:30:31 -04:00
|
|
|
|
.done(function (response) {
|
|
|
|
|
$(loaderResponseId).append(response);
|
|
|
|
|
if (response.trim().length === 0) {
|
|
|
|
|
staleLoader();
|
|
|
|
|
}
|
2018-05-31 20:17:52 -04:00
|
|
|
|
$(document).trigger("loaderFinished", response);
|
2018-05-28 21:30:31 -04:00
|
|
|
|
hideLoader();
|
2018-05-30 21:50:20 -04:00
|
|
|
|
isLoaderLoading = false;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
})
|
|
|
|
|
.fail(function (jqxhr, statis, error) {
|
|
|
|
|
errorLoader();
|
2018-05-30 21:50:20 -04:00
|
|
|
|
isLoaderLoading = false;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
});
|
2018-05-30 21:50:20 -04:00
|
|
|
|
loaderOffset += loadCount;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setupListeners() {
|
|
|
|
|
if ($(loaderResponseId).length === 1) {
|
|
|
|
|
/*
|
|
|
|
|
https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$('html').bind('mousewheel DOMMouseScroll', function (e) {
|
2018-09-07 23:29:42 -04:00
|
|
|
|
var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
|
|
|
|
|
if (delta < 0 && !hasScrollBar) {
|
|
|
|
|
loadMoreItems();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var _throttleTimer = null;
|
|
|
|
|
var _throttleDelay = 100;
|
|
|
|
|
var $window = $(window);
|
|
|
|
|
var $document = $(document);
|
|
|
|
|
var hasScrollBar = false;
|
|
|
|
|
|
|
|
|
|
$document.ready(function () {
|
|
|
|
|
$window
|
|
|
|
|
.off('scroll', ScrollHandler)
|
|
|
|
|
.on('scroll', ScrollHandler);
|
|
|
|
|
|
|
|
|
|
/*$('#load_penalties_button').click(function () {
|
|
|
|
|
loadMorePenalties();
|
|
|
|
|
});*/
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function ScrollHandler(e) {
|
|
|
|
|
//throttle event:
|
|
|
|
|
hasScrollBar = true;
|
|
|
|
|
clearTimeout(_throttleTimer);
|
|
|
|
|
_throttleTimer = setTimeout(function () {
|
|
|
|
|
|
|
|
|
|
//do work
|
|
|
|
|
if ($window.scrollTop() + $window.height() > $document.height() - 100) {
|
|
|
|
|
loadMoreItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, _throttleDelay);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|