mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-13 00:36:05 +01:00
Fill view with media, add infinite loading
This commit is contained in:
@@ -25,8 +25,12 @@ $(function() {
|
||||
|
||||
$('body').on('click', '[data-mediapicker-modal-trigger]', function() {
|
||||
var modal_identifier = $(this).data('grav-mediapicker-unique-identifier');
|
||||
modal = $.remodal.lookup[$('body').find('[data-remodal-unique-identifier="' + modal_identifier + '"]').data('remodal')];
|
||||
var modal_element = $('body').find('[data-remodal-unique-identifier="' + modal_identifier + '"]');
|
||||
modal = $.remodal.lookup[modal_element.data('remodal')];
|
||||
modal.open();
|
||||
|
||||
// load all media
|
||||
modal_element.find('.js__files').trigger('fillView');
|
||||
});
|
||||
|
||||
/* handle media modal click actions */
|
||||
|
||||
@@ -31,7 +31,8 @@ export let Instance = new Filter();
|
||||
var isLoading = false;
|
||||
|
||||
var filters = {};
|
||||
var global_index = 0;
|
||||
var global_index = 1;
|
||||
var files_ended = false;
|
||||
|
||||
/* handle changing file type / date filter */
|
||||
$('body').on('change', '.thumbs-list-container select.filter', (event) => {
|
||||
@@ -113,6 +114,10 @@ var filterFiles = function filterFiles() {
|
||||
loadMedia(filters, function(content) {
|
||||
if (!$(content).length) {
|
||||
showEmptyState();
|
||||
} else {
|
||||
if (!filters.page) {
|
||||
enableInfiniteScrolling();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -159,25 +164,46 @@ $('body').on('click', '.js__reset-pages-filter', (event) => {
|
||||
/* handle infinite loading */
|
||||
var enableInfiniteScrolling = function enableInfiniteScrolling() {
|
||||
$('.spinning-wheel').hide();
|
||||
var files_ended = false;
|
||||
var view = $('.content-wrapper');
|
||||
var view = $('.mediapicker-scroll');
|
||||
view.scroll(function() {
|
||||
if (files_ended) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
|
||||
loadMedia({}, function(content) {
|
||||
if (!$(content).length) {
|
||||
files_ended = true;
|
||||
}
|
||||
});
|
||||
if (($(this).scrollTop() + $(this).innerHeight() + 100) >= $(this)[0].scrollHeight) {
|
||||
fillView();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var loadNextBatch = function loadNextBatch(callback) {
|
||||
if (files_ended) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadMedia({}, function(content) {
|
||||
if (!$(content).length) {
|
||||
files_ended = true;
|
||||
} else {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var fillView = function fillView() {
|
||||
if ($('.js__files').find('.card-item').last().offset().top < $('.media-container').height()) {
|
||||
loadNextBatch(function() {
|
||||
fillView();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/* disable infinite loading */
|
||||
var disableInfiniteScrolling = function disableInfiniteScrolling() {
|
||||
$('.spinning-wheel').hide();
|
||||
$('.content-wrapper').unbind('scroll');
|
||||
};
|
||||
|
||||
$('.js__files').on('fillView', function(event) {
|
||||
fillView();
|
||||
enableInfiniteScrolling();
|
||||
});
|
||||
|
||||
6
themes/grav/js/admin.min.js
vendored
6
themes/grav/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user