2019-05-02 23:33:38 -04:00
|
|
|
|
let offset = 15;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
let isLoading = false;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2019-07-19 15:54:39 -04:00
|
|
|
|
|
2019-07-24 11:36:37 -04:00
|
|
|
|
function PenaltyScrollHandler(e) {
|
2019-07-19 15:54:39 -04:00
|
|
|
|
//throttle event:
|
|
|
|
|
hasScrollBar = true;
|
|
|
|
|
clearTimeout(_throttleTimer);
|
|
|
|
|
_throttleTimer = setTimeout(function () {
|
|
|
|
|
|
|
|
|
|
//do work
|
|
|
|
|
if ($window.scrollTop() + $window.height() > $document.height() - 100) {
|
|
|
|
|
loadMorePenalties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, _throttleDelay);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
function loadMorePenalties() {
|
2018-04-16 16:31:14 -04:00
|
|
|
|
if (isLoading) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
showLoader();
|
2018-04-16 16:31:14 -04:00
|
|
|
|
isLoading = true;
|
2020-02-12 14:13:59 -05:00
|
|
|
|
$.get('/Penalty/ListAsync', {
|
|
|
|
|
offset: offset,
|
|
|
|
|
showOnly: $('#penalty_filter_selection').val(),
|
|
|
|
|
hideAutomatedPenalties: document.getElementById('hide_automated_penalties_checkbox').checked
|
|
|
|
|
})
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.done(function (response) {
|
|
|
|
|
$('#penalty_table').append(response);
|
2018-05-04 00:22:10 -04:00
|
|
|
|
if (response.trim().length === 0) {
|
|
|
|
|
staleLoader();
|
|
|
|
|
}
|
2018-04-09 23:33:42 -04:00
|
|
|
|
hideLoader();
|
2018-04-16 16:31:14 -04:00
|
|
|
|
isLoading = false;
|
2018-04-09 23:33:42 -04:00
|
|
|
|
})
|
|
|
|
|
.fail(function (jqxhr, statis, error) {
|
|
|
|
|
errorLoader();
|
2018-04-16 16:31:14 -04:00
|
|
|
|
isLoading = false;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
});
|
2019-05-02 23:33:38 -04:00
|
|
|
|
offset += 15;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
if ($('#penalty_table').length === 1) {
|
2020-02-12 14:13:59 -05:00
|
|
|
|
|
|
|
|
|
$('#penalty_filter_selection').change(function () {
|
|
|
|
|
location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val() + '&hideAutomatedPenalties=' + document.getElementById('hide_automated_penalties_checkbox').checked;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#hide_automated_penalties_checkbox').click(function () {
|
|
|
|
|
location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val() + '&hideAutomatedPenalties=' + document.getElementById('hide_automated_penalties_checkbox').checked;
|
2018-05-04 00:22:10 -04:00
|
|
|
|
});
|
2019-05-17 10:02:09 -04:00
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
/*
|
2018-04-09 23:33:42 -04:00
|
|
|
|
https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll
|
|
|
|
|
*/
|
|
|
|
|
$('html').bind('mousewheel DOMMouseScroll', function (e) {
|
2019-07-19 15:54:39 -04:00
|
|
|
|
var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
if (delta < 0 && !hasScrollBar) {
|
|
|
|
|
loadMorePenalties();
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
/*
|
|
|
|
|
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;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2018-04-09 23:33:42 -04:00
|
|
|
|
$document.ready(function () {
|
|
|
|
|
$window
|
2019-08-01 10:37:33 -04:00
|
|
|
|
.off('scroll', PenaltyScrollHandler)
|
|
|
|
|
.on('scroll', PenaltyScrollHandler);
|
2018-04-16 16:31:14 -04:00
|
|
|
|
|
2018-04-19 01:48:14 -04:00
|
|
|
|
$('#load_penalties_button').click(function () {
|
2018-04-16 16:31:14 -04:00
|
|
|
|
loadMorePenalties();
|
|
|
|
|
});
|
2018-04-09 23:33:42 -04:00
|
|
|
|
});
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|