First test of separation of javascript

This commit is contained in:
2021-02-17 18:48:52 +01:00
parent 1dffff9c83
commit bf60722e22
4 changed files with 159 additions and 230 deletions

62
scripts/pagination.js Normal file
View File

@ -0,0 +1,62 @@
function paginationInit(data, paintingList, explorer)
{
function getPageRange()
{
if (window.innerWidth >= 600)
return explorer ? 6 : null;
else if (window.innerWidth < 600 && window.innerWidth > 450)
return 4;
else
return 1;
}
var options =
{
dataSource: paintingList,
pageSize: pageSize,
pageRange: getPageRange(),
className: 'paginationjs-theme-ginou',
hideWhenLessThanOnePage: true,
callback: function (response, pagination)
{
currentPage = pagination.pageNumber;
// url handling
if (explorer)
{
urlParams = new URLSearchParams(window.location.search)
if (urlParams.get('page') == undefined)
{
window.history.replaceState('', '', window.location.pathname + window.location.search + '&page=' + currentPage + window.location.hash);
}
else
{
trimSearch = window.location.search.substr(0, window.location.search.lastIndexOf('&'));
window.history.replaceState('', '', window.location.pathname + trimSearch + '&page=' + currentPage + window.location.hash);
}
}
else
{
window.history.replaceState('', '', window.location.pathname + '?page=' + currentPage + window.location.hash);
}
if (previousArray.length > 0)
{
for (i of previousArray)
$('[data-fancybox-index="'+i+'"]').parent().removeClass("active").addClass("inactive");
}
previousArray = response;
$.each(response, function(index, item)
{
$('[data-fancybox="exposition"][data-fancybox-index="'+item+'"]').parent().removeClass("inactive").addClass("active");
if (data[item >= 1000 ? (item - 1000 + 383 - 1) : (item - 1)].photo != "none") // inédit: index starts at 1000 // 383: total number of paintings except inédit
$('[data-fancybox="exposition"][data-fancybox-index="'+item+'"] img').attr("src", "photos/paintings/mini/"+item+".jpg");
else
$('[data-fancybox="exposition"][data-fancybox-index="'+item+'"] img').attr("src", "images/unknown.jpg");
});
}
};
$('#pagination').pagination(options);
}