IW4M-Admin/WebfrontCore/wwwroot/js/penalty.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-02-21 20:29:23 -05:00
let offset = 15;
function loadMorePenalties() {
showLoader();
2018-02-21 20:29:23 -05:00
$.get('/Penalty/ListAsync', { offset: offset })
.done(function (response) {
$('#penalty_table').append(response);
hideLoader();
})
.fail(function (jqxhr, statis, error) {
errorLoader();
2018-02-21 20:29:23 -05:00
});
offset += 15;
}
if ($('#penalty_table').length == 1) {
/*
https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll
*/
2018-02-21 20:29:23 -05:00
$('html').bind('mousewheel DOMMouseScroll', function (e) {
var delta = (e.originalEvent.wheelDelta || -e.originalEvent.detail);
2018-02-21 20:29:23 -05:00
if (delta < 0 && !hasScrollBar) {
loadMorePenalties();
}
});
2018-02-21 20:29:23 -05:00
/*
https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom
*/
2018-02-21 20:29:23 -05:00
var _throttleTimer = null;
var _throttleDelay = 100;
var $window = $(window);
var $document = $(document);
var hasScrollBar = false;
2018-02-21 20:29:23 -05:00
$document.ready(function () {
2018-02-21 20:29:23 -05:00
$window
.off('scroll', ScrollHandler)
.on('scroll', ScrollHandler);
});
2018-02-21 20:29:23 -05:00
function ScrollHandler(e) {
//throttle event:
hasScrollBar = true;
clearTimeout(_throttleTimer);
_throttleTimer = setTimeout(function () {
2018-02-21 20:29:23 -05:00
//do work
if ($window.scrollTop() + $window.height() > $document.height() - 100) {
loadMorePenalties();
}
2018-02-21 20:29:23 -05:00
}, _throttleDelay);
}
2018-02-21 20:29:23 -05:00
}