1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 07:13:58 -05:00

huge commit for webfront facelift

This commit is contained in:
RaidMax
2022-04-19 18:43:58 -05:00
parent 7b78e0803a
commit d5b4c60e5a
105 changed files with 2981 additions and 2545 deletions

View File

@ -13,7 +13,26 @@ function initLoader(location, loaderId, count = 10, start = count, additional =
loadCount = count;
loaderOffset = start;
additionalParams = additional;
setupListeners();
setupMonitor();
$('#loaderLoad').click(function () {
loadMoreItems();
});
}
function setupMonitor() {
const element = document.querySelector('#loaderLoad')
const observer = new window.IntersectionObserver(([entry]) => {
if (entry.isIntersecting && $('.content-wrapper').scrollTop() > 10) {
loadMoreItems();
}
}, {
root: null,
threshold: 1,
})
observer.observe(element);
}
function loadMoreItems() {
@ -23,10 +42,10 @@ function loadMoreItems() {
showLoader();
isLoaderLoading = true;
let params = { offset: loaderOffset, count: loadCount, startAt: startAt };
for (i = 0; i < additionalParams.length; i++) {
let params = {offset: loaderOffset, count: loadCount, startAt: startAt};
for (let i = 0; i < additionalParams.length; i++) {
let param = additionalParams[i];
params[param.name] = param.value;
params[param.name] = param.value instanceof Function ? param.value() : param.value;
}
$.get(loadUri, params)
@ -35,69 +54,22 @@ function loadMoreItems() {
if (response.trim().length === 0) {
staleLoader();
loaderReachedEnd = true;
$('.loader-load-more').addClass('disabled');
$('.loader-load-more').remove('text-primary').addClass('text-muted');
}
$(document).trigger("loaderFinished", response);
startAt = $(response).filter('.loader-data-time').last().data('time');
hideLoader();
isLoaderLoading = false;
})
.fail(function (jqxhr, statis, error) {
.fail(function () {
errorLoader();
halfmoon.initStickyAlert({
content: 'Could not load more items...',
title: 'Error',
alertType: 'alert-danger',
fillType: 'filled'
});
isLoaderLoading = false;
});
loaderOffset += loadCount;
}
var hasScrollBar = false;
function _ScrollHandler(e) {
//throttle event:
/*
https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom
*/
var $window = $(window);
var $document = $(document);
hasScrollBar = true;
let _throttleTimer = null;
let _throttleDelay = 100;
clearTimeout(_throttleTimer);
_throttleTimer = setTimeout(function () {
//do work
if ($window.scrollTop() + $window.height() > $document.height() - 100) {
loadMoreItems();
}
}, _throttleDelay);
}
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) {
var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail;
if (delta < 0 && !hasScrollBar) {
loadMoreItems();
}
});
$(document).ready(function () {
$(window)
.off('scroll', _ScrollHandler)
.on('scroll', _ScrollHandler);
$('.loader-load-more:not(.disabled)').click(function (e) {
if (!isLoaderLoading) {
loadMoreItems();
}
});
});
}
}