Fix painting not working with filter

This commit is contained in:
Théo Marchal 2021-03-06 11:43:53 +01:00
parent 3a964098e7
commit 35b1e06dfc

View File

@ -2,14 +2,17 @@ jQuery(document).ready(function($)
{ {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const pageId = urlParams.get('number'); const pageId = urlParams.get('number');
if (pageId > 1000)
i = pageId - 1000 + 383 - 1; // inédit: index starts at 1000 // 383: total number of paintings except inédit
else
i = pageId - 1; // index is 0
$.getJSON("data.json", function(data) $.getJSON("data.json", function(data)
{ {
if (!data[i]) // the number specified in URL does not exist var idx = 0; // search the index of the painting of filtered data
for (i = 0; i < data.length; i++)
{
if (data[i].number == pageId)
idx = i;
}
if (!data[idx]) // the number specified in URL does not exist
{ {
$(".container").css("display", "none"); $(".container").css("display", "none");
$("#info").css("display", "none"); $("#info").css("display", "none");
@ -18,75 +21,75 @@ jQuery(document).ready(function($)
function GetNumber() function GetNumber()
{ {
if (data[i].number > 1000) if (data[idx].number > 1000)
return "Inédit"; return "Inédit";
return data[i].number; return data[idx].number;
} }
// page title // page title
$("head title").append(GetNumber()); $("head title").append(GetNumber());
// photo // photo
if (data[i].photo != "none") if (data[idx].photo != "none")
$(".photo img").attr("src", "photos/paintings/normal/" + data[i].number + ".jpg"); $(".photo img").attr("src", "photos/paintings/normal/" + data[idx].number + ".jpg");
else else
$(".photo img").attr("src", "images/unknown.jpg"); $(".photo img").attr("src", "images/unknown.jpg");
$(".photo img").attr("alt", "Tableau " + data[i].number); $(".photo img").attr("alt", "Tableau " + data[idx].number);
// metadata // metadata
$(".metadata .content.number").append(GetNumber()); $(".metadata .content.number").append(GetNumber());
if (data[i].month != "—") if (data[idx].month != "—")
$(".metadata .content.date").append(data[i].month + " " + data[i].year); $(".metadata .content.date").append(data[idx].month + " " + data[idx].year);
else else
$(".metadata .content.date").append(data[i].year); $(".metadata .content.date").append(data[idx].year);
$(".metadata .content.dimension").append(data[i].dimension); $(".metadata .content.dimension").append(data[idx].dimension);
$(".metadata .content.support").append(data[i].support); $(".metadata .content.support").append(data[idx].support);
$(".metadata .content.genre").append(data[i].genre); $(".metadata .content.genre").append(data[idx].genre);
$(".metadata .content.theme").append(data[i].theme); $(".metadata .content.theme").append(data[idx].theme);
$(".metadata .content.place").append(data[i].place); $(".metadata .content.place").append(data[idx].place);
if (data[i].photo == "none") photoState = "aucune"; if (data[idx].photo == "none") photoState = "aucune";
if (data[i].photo == "bad") photoState = "mauvais"; if (data[idx].photo == "bad") photoState = "mauvais";
if (data[i].photo == "ok") photoState = "acceptable"; if (data[idx].photo == "ok") photoState = "acceptable";
if (data[i].photo == "good") photoState = "bon"; if (data[idx].photo == "good") photoState = "bon";
$(".metadata .content.photo").append(photoState); $(".metadata .content.photo").append(photoState);
if (data[i].help == "yes") if (data[idx].help == "yes")
$(".metadata .content.help").append('<a href="informations.html"><strong>oui (!)</strong></a>'); $(".metadata .content.help").append('<a href="informations.html"><strong>oui (!)</strong></a>');
else else
$(".metadata .content.help").append("non"); $(".metadata .content.help").append("non");
if (data[i].tags != "—") if (data[idx].tags != "—")
$(".metadata .content.tag").append(data[i].tags); $(".metadata .content.tag").append(data[idx].tags);
else else
$(".metadata .content.tag").parent().css("display", "none"); $(".metadata .content.tag").parent().css("display", "none");
if (data[i].comment != "—") if (data[idx].comment != "—")
$(".metadata .content.comment").append(data[i].comment); $(".metadata .content.comment").append(data[idx].comment);
else else
$(".metadata .content.comment").parent().css("display", "none"); $(".metadata .content.comment").parent().css("display", "none");
if (data[i].photo != "none") if (data[idx].photo != "none")
$(".metadata .content.original a").attr("href", "photos/paintings/original/" + data[i].number + ".jpg"); $(".metadata .content.original a").attr("href", "photos/paintings/original/" + data[idx].number + ".jpg");
else else
$(".metadata .content.original").parent().css("display", "none"); $(".metadata .content.original").parent().css("display", "none");
// cartel // cartel
$("#info .title").append(data[i].title); $("#info .title").append(data[idx].title);
if (data[i].month != "—") if (data[idx].month != "—")
$("#info .year").append(data[i].month + " " + data[i].year); $("#info .year").append(data[idx].month + " " + data[idx].year);
else else
$("#info .year").append(data[i].year); $("#info .year").append(data[idx].year);
format = data[i].paint + " sur " + data[i].support.toLowerCase(); format = data[idx].paint + " sur " + data[idx].support.toLowerCase();
if (data[i].dimension != "—") if (data[idx].dimension != "—")
format += " (" + data[i].dimension + ")"; format += " (" + data[idx].dimension + ")";
$("#info .format").append(format); $("#info .format").append(format);
if (data[i].comment != "—") if (data[idx].comment != "—")
$("#info .comment").prepend(data[i].comment); $("#info .comment").prepend(data[idx].comment);
else else
$("#info .comment").css("display", "none"); $("#info .comment").css("display", "none");
}); });