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 selectedPhotos = []; var selectedYears = []; var selectedMonths = []; var selectedGenres = [];
var selectedThemes = []; var selectedPlaces = []; var selectedTags = []; var selectedDimensions = []; var selectedHelps = [];*/
var selectedOptions = [];
// filter data depending of parameters
@ -91,18 +88,6 @@ jQuery(document).ready(function($)
}
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(CheckDimension);
@ -228,9 +213,9 @@ jQuery(document).ready(function($)
if (p == "90") for (i = 90; i <= 99; 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"))
{
//removeFromArray(selectedOptions.photos, photo);
selectedPhotos.push("bad");
selectedPhotos.push("ok");
selectedPhotos.push("good");
@ -243,59 +228,15 @@ jQuery(document).ready(function($)
var originalAvailableOptions = gatherData();
selectedOptions = gatherURLdata();
filterData(selectedOptions);
availableOptions = gatherData();
// menu initial generation
$.getScript("scripts/explorer_menu.js", function() {
$.getScript("scripts/explorer_menu.js", function()
{
generateMenu(originalAvailableOptions);
selectedOptions = gatherURLdata();
data = originalData;
console.log("gather url data", selectedOptions);
filterData(selectedOptions);
//availableOptions = [];
availableOptions = gatherData();
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);
URLGeneration(availableOptions);
@ -304,15 +245,10 @@ jQuery(document).ready(function($)
$('input[name="' + name + '"]').change(function()
{
if (this.checked)
{
console.log("checked");
param.push(this.id);
}
else
{
console.log("unchecked");
removeFromArray(param, this.id);
}
selectedOptions = gatherURLdata();
data = originalData;
filterData(selectedOptions);
@ -336,8 +272,6 @@ jQuery(document).ready(function($)
filterData(selectedOptions);
availableOptions = [];
availableOptions = gatherData();
console.log("select", selectedOptions);
console.log("avail", availableOptions);
updateMenu(availableOptions);
});
}
@ -352,26 +286,6 @@ jQuery(document).ready(function($)
visualFilterListItem("place", paramPlace);
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);
// gallery
paintingList.push(i.number);
if (paintingList.length % (pageSize + 1) == 0)
@ -477,14 +392,13 @@ jQuery(document).ready(function($)
if (urlParams.get('page') != "")
targetPage = urlParams.get('page');
//generateMenu();
var res = generateTable();
if (res) // display table or no result depending of computed result
{
$(".style-select").show();
$("article.explorer h2").removeClass("active")
//$("form").slideUp(200);
$("form").slideUp(200);
$("article.explorer p.result").css("display", "block");
// pagination configuration
@ -503,29 +417,6 @@ jQuery(document).ready(function($)
$("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
$.getScript("scripts/fancybox.js", function() {

View File

@ -1,7 +1,5 @@
function generateMenu(availableOptions)
{
console.log("generate menu", availableOptions);
function createPhotoName(photo)
{
if (photo == "none") return "&#x2606; inexistant";
@ -100,20 +98,16 @@ function generateMenu(availableOptions)
$(".box.places select").append('<option value="">Aucun</option');
for (place of availableOptions.places)
{
//console.log(place);
$(".box.places select").append('<option value="' + place + '">' + place + '</option');
}
$(".box.tags select").append('<option value="">Aucun</option');
for (tag of availableOptions.tags)
$(".box.tags select").append('<option value="' + tag + '">' + tag + '</option');
}
function updateMenu(availableOptions)
{
console.log("updateMenu", availableOptions);
function checkItem(name, array)
{
$('.' + name + ' .item-cont span input').each(function()
@ -149,10 +143,7 @@ function updateMenu(availableOptions)
$(this).hide();
}
else
{
console.log("show");
$(this).show();
}
});
}
@ -234,7 +225,6 @@ function URLGeneration(availableOptions)
// URL special case for photos with "exist"
if (paramPhoto.includes("exist"))
{
console.log("paramPhoto!!!", paramPhoto);
$('input[id="exist"]').prop("checked", 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);
@ -242,6 +232,7 @@ function URLGeneration(availableOptions)
}
}
function userActionHandle(availableOptions)
{
// 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)
{
$(selector).on('change', 'select[name="' + name + '"]', function()
@ -303,7 +294,6 @@ function userActionHandle(availableOptions)
allCheckBoxSelected("tags", "tag");
allCheckBoxSelected("photos", "photo");
allCheckBoxSelected("helps", "help");
//listOptionSelected(".box.places", "place", availableOptions.places);
listOptionSelected(".box.tags", "tag", availableOptions.tags);
// 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);
}
});
// 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);
});
});