Clean up organisation and comments

This commit is contained in:
Théo Marchal 2021-03-03 09:56:26 +01:00
parent 10dea8e993
commit dae17821ad
3 changed files with 74 additions and 204 deletions

View File

@ -41,9 +41,6 @@ jQuery(document).ready(function($)
/**********/ /**********/
var availableOptions = []; var availableOptions = [];
/*var selectedPhotos = []; var selectedYears = []; var selectedMonths = []; var selectedGenres = [];
var selectedThemes = []; var selectedPlaces = []; var selectedTags = []; var selectedDimensions = []; var selectedHelps = [];*/
var selectedOptions = []; var selectedOptions = [];
// filter data depending of parameters // filter data depending of parameters
@ -91,18 +88,6 @@ jQuery(document).ready(function($)
} }
return false; return false;
} }
// change "exist" with the associeted value ; this needs to be done here (!), after visual menu generation
/*for (photo of selectedOptions.photos)
{
if (photo == "exist")
{
//removeFromArray(selectedOptions.photos, photo);
selectedOptions.photos.push("bad");
selectedOptions.photos.push("ok");
selectedOptions.photos.push("good");
}
}*/
data = data.filter(CheckTag); data = data.filter(CheckTag);
data = data.filter(CheckDimension); data = data.filter(CheckDimension);
@ -228,9 +213,9 @@ jQuery(document).ready(function($)
if (p == "90") for (i = 90; i <= 99; i++) selectedDimensions.push(i); if (p == "90") for (i = 90; i <= 99; i++) selectedDimensions.push(i);
if (p == "100") for (i = 100; i <= 109; i++) selectedDimensions.push(i); if (p == "100") for (i = 100; i <= 109; i++) selectedDimensions.push(i);
} }
// special case of a multi selector
if (selectedPhotos.includes("exist")) if (selectedPhotos.includes("exist"))
{ {
//removeFromArray(selectedOptions.photos, photo);
selectedPhotos.push("bad"); selectedPhotos.push("bad");
selectedPhotos.push("ok"); selectedPhotos.push("ok");
selectedPhotos.push("good"); selectedPhotos.push("good");
@ -243,59 +228,15 @@ jQuery(document).ready(function($)
var originalAvailableOptions = gatherData(); var originalAvailableOptions = gatherData();
selectedOptions = gatherURLdata(); selectedOptions = gatherURLdata();
filterData(selectedOptions); filterData(selectedOptions);
availableOptions = gatherData();
// menu initial generation // menu initial generation
$.getScript("scripts/explorer_menu.js", function() { $.getScript("scripts/explorer_menu.js", function()
{
generateMenu(originalAvailableOptions); generateMenu(originalAvailableOptions);
selectedOptions = gatherURLdata();
data = originalData;
console.log("gather url data", selectedOptions);
filterData(selectedOptions);
//availableOptions = [];
availableOptions = gatherData(); availableOptions = gatherData();
updateMenu(availableOptions); updateMenu(availableOptions);
// menu configurer show / hide
$("article.explorer h2").click(function()
{
if ($(this).hasClass("active"))
{
$(this).removeClass("active");
$("form").slideUp(200);
}
else
{
$(this).addClass("active");
$("form").slideDown(200);
}
});
// menu configurer child on mobile show/hide
if ($(window).width() <= 600)
{
$("article.explorer .box h3").click(function()
{
if ($(this).parent().hasClass("active"))
{
$(this).parent().removeClass("active");
$(this).parent().children(".item-cont").slideUp(200);
}
else
{
$(this).parent().addClass("active");
$(this).parent().children(".item-cont").slideDown(200);
}
});
}
userActionHandle(availableOptions); userActionHandle(availableOptions);
URLGeneration(availableOptions); URLGeneration(availableOptions);
@ -304,15 +245,10 @@ jQuery(document).ready(function($)
$('input[name="' + name + '"]').change(function() $('input[name="' + name + '"]').change(function()
{ {
if (this.checked) if (this.checked)
{
console.log("checked");
param.push(this.id); param.push(this.id);
}
else else
{
console.log("unchecked");
removeFromArray(param, this.id); removeFromArray(param, this.id);
}
selectedOptions = gatherURLdata(); selectedOptions = gatherURLdata();
data = originalData; data = originalData;
filterData(selectedOptions); filterData(selectedOptions);
@ -336,8 +272,6 @@ jQuery(document).ready(function($)
filterData(selectedOptions); filterData(selectedOptions);
availableOptions = []; availableOptions = [];
availableOptions = gatherData(); availableOptions = gatherData();
console.log("select", selectedOptions);
console.log("avail", availableOptions);
updateMenu(availableOptions); updateMenu(availableOptions);
}); });
} }
@ -352,26 +286,6 @@ jQuery(document).ready(function($)
visualFilterListItem("place", paramPlace); visualFilterListItem("place", paramPlace);
visualFilterListItem("tag", paramTag); visualFilterListItem("tag", paramTag);
/*$('input[id="exist"]').click(function()
{
if (this.checked)
{
console.log("exsit checked");
paramPhoto.push(this.id);
paramPhoto.push("bad");
paramPhoto.push("ok");
paramPhoto.push("good");
}
else
{
console.log("exist unchecked");
removeFromArray(paramPhoto, this.id);
removeFromArray(paramPhoto, "bad");
removeFromArray(paramPhoto, "ok");
removeFromArray(paramPhoto, "good");
}
});*/
}); });
/*********************/ /*********************/
@ -438,6 +352,7 @@ jQuery(document).ready(function($)
$("table").append(result); $("table").append(result);
// gallery // gallery
paintingList.push(i.number); paintingList.push(i.number);
if (paintingList.length % (pageSize + 1) == 0) if (paintingList.length % (pageSize + 1) == 0)
@ -477,14 +392,13 @@ jQuery(document).ready(function($)
if (urlParams.get('page') != "") if (urlParams.get('page') != "")
targetPage = urlParams.get('page'); targetPage = urlParams.get('page');
//generateMenu();
var res = generateTable(); var res = generateTable();
if (res) // display table or no result depending of computed result if (res) // display table or no result depending of computed result
{ {
$(".style-select").show(); $(".style-select").show();
$("article.explorer h2").removeClass("active") $("article.explorer h2").removeClass("active")
//$("form").slideUp(200); $("form").slideUp(200);
$("article.explorer p.result").css("display", "block"); $("article.explorer p.result").css("display", "block");
// pagination configuration // pagination configuration
@ -503,29 +417,6 @@ jQuery(document).ready(function($)
$("article.explorer p.result").css("display", "none"); $("article.explorer p.result").css("display", "none");
} }
// on mobile, show only the first item slided down
if ($(window).width() <= 600)
{
$("article.explorer .container .box").each(function()
{
if (!$(this).hasClass('active'))
{
$(this).children(".item-cont").slideUp(200);
}
});
}
// change display: gallery/table
$(".style-select.frame").click(function()
{
$("table").hide();
$("#gallery").show();
})
$(".style-select.list").click(function()
{
$("#gallery").hide();
$("table").show();
})
// fancybox configuration // fancybox configuration
$.getScript("scripts/fancybox.js", function() { $.getScript("scripts/fancybox.js", function() {

View File

@ -1,7 +1,5 @@
function generateMenu(availableOptions) function generateMenu(availableOptions)
{ {
console.log("generate menu", availableOptions);
function createPhotoName(photo) function createPhotoName(photo)
{ {
if (photo == "none") return "&#x2606; inexistant"; if (photo == "none") return "&#x2606; inexistant";
@ -100,20 +98,16 @@ function generateMenu(availableOptions)
$(".box.places select").append('<option value="">Aucun</option'); $(".box.places select").append('<option value="">Aucun</option');
for (place of availableOptions.places) for (place of availableOptions.places)
{
//console.log(place);
$(".box.places select").append('<option value="' + place + '">' + place + '</option'); $(".box.places select").append('<option value="' + place + '">' + place + '</option');
}
$(".box.tags select").append('<option value="">Aucun</option'); $(".box.tags select").append('<option value="">Aucun</option');
for (tag of availableOptions.tags) for (tag of availableOptions.tags)
$(".box.tags select").append('<option value="' + tag + '">' + tag + '</option'); $(".box.tags select").append('<option value="' + tag + '">' + tag + '</option');
} }
function updateMenu(availableOptions) function updateMenu(availableOptions)
{ {
console.log("updateMenu", availableOptions);
function checkItem(name, array) function checkItem(name, array)
{ {
$('.' + name + ' .item-cont span input').each(function() $('.' + name + ' .item-cont span input').each(function()
@ -149,10 +143,7 @@ function updateMenu(availableOptions)
$(this).hide(); $(this).hide();
} }
else else
{
console.log("show");
$(this).show(); $(this).show();
}
}); });
} }
@ -234,7 +225,6 @@ function URLGeneration(availableOptions)
// URL special case for photos with "exist" // URL special case for photos with "exist"
if (paramPhoto.includes("exist")) if (paramPhoto.includes("exist"))
{ {
console.log("paramPhoto!!!", paramPhoto);
$('input[id="exist"]').prop("checked", true); $('input[id="exist"]').prop("checked", true);
$('input[id="bad"]').prop("checked", true); $('input[id="bad"]').prop("disabled", true); $('input[id="bad"]').prop("checked", true); $('input[id="bad"]').prop("disabled", true);
$('input[id="ok"]').prop("checked", true); $('input[id="ok"]').prop("disabled", true); $('input[id="ok"]').prop("checked", true); $('input[id="ok"]').prop("disabled", true);
@ -242,6 +232,7 @@ function URLGeneration(availableOptions)
} }
} }
function userActionHandle(availableOptions) function userActionHandle(availableOptions)
{ {
// if "all" is selected, check all other options and disable them // if "all" is selected, check all other options and disable them
@ -262,7 +253,7 @@ function userActionHandle(availableOptions)
}); });
} }
// for places and tags // for tags
function listOptionSelected(selector, name, names) function listOptionSelected(selector, name, names)
{ {
$(selector).on('change', 'select[name="' + name + '"]', function() $(selector).on('change', 'select[name="' + name + '"]', function()
@ -303,7 +294,6 @@ function userActionHandle(availableOptions)
allCheckBoxSelected("tags", "tag"); allCheckBoxSelected("tags", "tag");
allCheckBoxSelected("photos", "photo"); allCheckBoxSelected("photos", "photo");
allCheckBoxSelected("helps", "help"); allCheckBoxSelected("helps", "help");
//listOptionSelected(".box.places", "place", availableOptions.places);
listOptionSelected(".box.tags", "tag", availableOptions.tags); listOptionSelected(".box.tags", "tag", availableOptions.tags);
// special case for photos with "exist" // special case for photos with "exist"
@ -322,4 +312,69 @@ function userActionHandle(availableOptions)
$('input[id="good"]').prop("checked", false); $('input[id="good"]').prop("disabled", false); $('input[id="good"]').prop("checked", false); $('input[id="good"]').prop("disabled", false);
} }
}); });
// menu configurer show / hide
$("article.explorer h2").click(function()
{
if ($(this).hasClass("active"))
{
$(this).removeClass("active");
$("form").slideUp(200);
}
else
{
$(this).addClass("active");
$("form").slideDown(200);
}
});
// menu configurer child on mobile show/hide
if ($(window).width() <= 600)
{
$("article.explorer .box h3").click(function()
{
if ($(this).parent().hasClass("active"))
{
$(this).parent().removeClass("active");
$(this).parent().children(".item-cont").slideUp(200);
}
else
{
$(this).parent().addClass("active");
$(this).parent().children(".item-cont").slideDown(200);
}
});
}
// on mobile, show only the first item slided down
if ($(window).width() <= 600)
{
$("article.explorer .container .box").each(function()
{
if (!$(this).hasClass('active'))
{
$(this).children(".item-cont").slideUp(200);
}
});
}
// change display: gallery/table
$(".style-select.frame").click(function()
{
$("table").hide();
$("#gallery").show();
});
$(".style-select.list").click(function()
{
$("#gallery").hide();
$("table").show();
});
} }

View File

@ -1,76 +0,0 @@
jQuery(document).ready(function($)
{
$.getJSON("data.json", function(data)
{
function removeFromArray(array, item)
{
const index = array.indexOf(item);
if (index > -1)
array.splice(index, 1);
return array;
}
var availableYears = [];
var availableTags = [];
selectedTags = ["Chat", "Fleur"];
selectedYears = ["2001", "2007"];
newData = data;
function CheckTag(item)
{
for (tag of selectedTags)
{
if (!item.tags.includes(tag))
return false;
}
return true;
}
function CheckYear(item)
{
for (year of selectedYears)
{
if (item.year == year)
return true;
}
return false;
}
newData = newData.filter(CheckTag);
newData = newData.filter(CheckYear);
console.log(newData);
/*for (dat of data)
{
for (tag of selectedTags)
{
if (dat.tags.includes(tag))
{
if (!availableYears.includes(dat.year))
availableYears.push(dat.year);
else
{
console.log("remove year", dat.year);
}
splitTags = dat.tags.split(", ");
for (splitTag of splitTags)
{
if (!availableTags.includes(splitTag))
availableTags.push(splitTag);
}
}
}
}*/
console.log("availableYears", availableYears);
console.log("availableTags", availableTags);
});
});