From d8070b626096eeaa9a667a5b08427451bba56884 Mon Sep 17 00:00:00 2001 From: mberard Date: Thu, 11 Nov 2021 15:18:01 +0100 Subject: [PATCH] fix: attachment and gitignore --- .gitignore | 2 + index.php | 4 +- src/formValidation.js | 60 +++++--- src/translation.js | 341 +++++++++++++++++++++--------------------- 4 files changed, 214 insertions(+), 193 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6be137d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.history/ \ No newline at end of file diff --git a/index.php b/index.php index d7800fe..38fdeff 100644 --- a/index.php +++ b/index.php @@ -82,10 +82,10 @@
- +
- +
diff --git a/src/formValidation.js b/src/formValidation.js index 177811f..d793e48 100644 --- a/src/formValidation.js +++ b/src/formValidation.js @@ -1,31 +1,43 @@ -var validExpeMail = false -var validExpeLoc = false //turned to true in geocoder.js -var validDestMail = false -var validDestLoc = false //turned to true in geocoder.js +var validExpeMail = false; +var validExpeLoc = false; //turned to true in geocoder.js +var validDestMail = false; +var validDestLoc = false; //turned to true in geocoder.js -function validateEmail(email) { //from https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript - const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return re.test(String(email).toLowerCase()); +function validateEmail(email) { + //from https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript + const re = + /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(String(email).toLowerCase()); } -$("#expeMail").change(function() { - validExpeMail = validateEmail($("#expeMail").val()) - checkFormValid() -}) +$("#expeMail").change(function () { + validExpeMail = validateEmail($("#expeMail").val()); + checkFormValid(); +}); -$("#destMail").change(function() { - validDestMail = validateEmail($("#destMail").val()) - checkFormValid() -}) +$("#destMail").change(function () { + validDestMail = validateEmail($("#destMail").val()); + checkFormValid(); +}); -document.querySelector('.custom-file-input').addEventListener('change',function(e){ - var fileName = document.getElementById("attachmentPlane").files[0].name; - var nextSibling = e.target.nextElementSibling - nextSibling.innerText = fileName -}) +document + .querySelector(".custom-file-input") + .addEventListener("change", function (e) { + const file = e.target.files[0]; + const fileName = file.name; + var nextSibling = e.target.nextElementSibling; + nextSibling.innerText = fileName; -function checkFormValid(){ - if(validExpeMail && validExpeLoc && validDestMail && validDestLoc){ - $('#sendNewPlane').prop("disabled", false) - } + const filesize = (file.size / 1024 / 1024).toFixed(4); // MB + if (filesize >= 2.2) { + e.target.classList.add("is-invalid"); + } else { + e.target.classList.remove("is-invalid"); + } + }); + +function checkFormValid() { + if (validExpeMail && validExpeLoc && validDestMail && validDestLoc) { + $("#sendNewPlane").prop("disabled", false); + } } diff --git a/src/translation.js b/src/translation.js index 524e3a5..baaa6e3 100644 --- a/src/translation.js +++ b/src/translation.js @@ -1,186 +1,193 @@ // Default lang -var lang = 'en' +var lang = "en"; // Lang by session -var langSession = sessionStorage.getItem('lang'); +var langSession = sessionStorage.getItem("lang"); // Lang by navigator config var userLang = navigator.userLanguage || navigator.language; if (langSession) { - lang = langSession.substring(0,2) + lang = langSession.substring(0, 2); } else if (userLang) { - lang = userLang.substring(0,2) + lang = userLang.substring(0, 2); } //loading the lang.json file -$(document).ready(function(){ - translateUI(lang) - $.getJSON("lang/lang.json", function(data){ - //creating dropdown list of languages in navbar - for (var key in data){ - $("#langChoices").append( ''+data[key]+'' ) - $("#selectDestLang").append( '' ) - } - //setting the user lang - if(data[lang]){ - //$("#navbarDropdownLang").html(data[lang]) - translateUI(lang) - } - //or english if not in list - else{ - //$("#navbarDropdownLang").html("English") - translateUI('en') - } - $(".langSelect").on('click',function(e){ - lang = e.currentTarget.attributes[1].value - sessionStorage.setItem('lang', lang); - translateUI(lang) - //$("#navbarDropdownLang").html($(this).html()) - }) - }).fail(function(error){ - console.log(error); - }); +$(document).ready(function () { + translateUI(lang); + $.getJSON("lang/lang.json", function (data) { + //creating dropdown list of languages in navbar + for (var key in data) { + $("#langChoices").append( + '' + + data[key] + + "" + ); + $("#selectDestLang").append( + '" + ); + } + //setting the user lang + if (data[lang]) { + //$("#navbarDropdownLang").html(data[lang]) + translateUI(lang); + } + //or english if not in list + else { + //$("#navbarDropdownLang").html("English") + translateUI("en"); + } + $(".langSelect").on("click", function (e) { + lang = e.currentTarget.attributes[1].value; + sessionStorage.setItem("lang", lang); + translateUI(lang); + //$("#navbarDropdownLang").html($(this).html()) + }); + }).fail(function (error) { + console.log(error); + }); }); -var dictionnary = [] +var dictionnary = []; -function translateUI(l){ - $.getJSON("lang/"+l+"", function(s){ - dictionnary = s - //if arabic : display left to right (ltr) + troubleshooting a lot of individual elements - if (lang == "ar"){ - //navbar - $("nav").css('direction','rtl') - $(".nav-menus").removeClass('mr-auto') - $(".nav-button").addClass('mr-auto') - //form - // $(".ql-container").css('direction','rtl') - // $(".ql-container").css('float','right') - // $(".ql-editor").css('float','right') - // $(".ql-editor p").css('float','right') - $(".modal-content").css('direction','rtl') - $(".bold").css('float','right') - $("#public").css('margin-left','5px') - $("#prive").css('margin-left','5px') - $("#newPlaneModalAnonyme").css('margin-right','25px') - $("#newPlaneModalCancel").css('margin-left','8px') - $("#closeModal").css('margin-left','0px') - $("#closeModal").css('padding-left','0px') - //anthology - $("#anthology").css('direction','rtl') - $("#anthologyDisclaimer").css('float','right') - - } - else{ - //navbar - $("nav").css('direction','ltr') - $(".nav-menus").addClass('mr-auto') - $(".nav-button").removeClass('mr-auto') - //form - // $(".ql-container").css('direction','ltr') - // $(".ql-container").css('float','left') - // $(".ql-editor").css('float','left') - // $(".ql-editor p").css('float','none') - $(".modal-content").css('direction','ltr') - $(".bold").css('float','left') - $("#public").css('margin-left','0px') - $("#prive").css('margin-left','0px') - $("#newPlaneModalAnonyme").css('margin-right','0px') - $("#newPlaneModalCancel").css('margin-left','0px') - //anthology - $("#anthology").css('direction','ltr') - $("#anthologyDisclaimer").css('float','left') - } - - //changing all strings - //main page - $('head title', window.parent.document).text(s.avionpoeme); - $("#navTitle").html(s.avionpoeme) - $("#buttonAnthology").html(s.anthologie) - $("#buttonAbout").html(s.apropos) - if (typeof nbPlane !== 'undefined') { - $("#buttonNewPlane").val(s.lancer_avion+" "+nbPlane+"/100") - } else { - $("#buttonNewPlane").on('click', () => { - window.location.replace("/"); - }) - } - //new plane form - $("#newPlaneModalTitle").html(s.lancer_avion) - $("#newPlaneModalMessage").html(s.message) - $("#newPlaneModalPrive").html(s.prive) - $("#newPlaneModalPublic").html(s.public) - $("#labelAttachment").html(s.PJ_Ajouter) - console.log(s.PJ_Parcourir) - $("#attachmentPlaneLabel").attr('data-after', s.PJ_Parcourir) - $("#flightTime").html(s.temps_de_vol) - $("#newPlaneModalRandom").html(s.aléatoire) - $("#newPlaneModal3j").html(s.trois_jours) - $("#newPlaneModal7j").html(s.sept_jours) - $("#newPlaneModal30j").html(s.trente_jours) - $("#newPlaneModal365j").html(s.unan_jours) - $("#newPlaneModalExpediteur").html(s.expediteur) - $("#newPlaneModalDestinataire").html(s.destinataire) - $("#newPlaneModalAnonyme").html(s.anonyme) - $("#newPlaneModalCancel").html(s.annuler) - $("#sendNewPlane").html(s.lancer) - $("#destLang").html(s.langue_destinataire) - $("#expeMail").attr("placeholder", s.expeMail_placeholder) - $("#expeGeocoderPhoton").attr("placeholder", s.expeLoc_placeholder) - $("#destMail").attr("placeholder", s.destMail_placeholder) - $("#destGeocoderPhoton").attr("placeholder", s.destLoc_placeholder) - $('#anonymeTooltip').attr("title", s.anonyme_tooltip).tooltip("_fixTitle"); - $('#publicTooltip').attr("title", s.public_tooltip).tooltip("_fixTitle"); - - $('#selectDestLang option[value="'+lang+'"]').prop('selected', true); //selecting by default recipient language same as interface - //Anthology - displayAnthology() - $("#anthologyTitle").html(s.anthologie) - $("#anthologyDisclaimer").html(s.suppr_message_public) - $("#closeAnthologyAbout").html(s.retour_carte) - - //About - $("#aboutTitle").html(s.apropos) - $("#librairies").html(s.librairies) - $("#mapSources").html(s.source_carte) - $("#mapBackground").html(s.map_background) - $("#clouds").html(s.clouds) - $.getJSON("lang/about.json", function(e){ - if(lang !== 'en' && lang !== 'fr' && lang !== 'de'){ - $("#aboutText").html(e[0].en) - } - else{ - $("#aboutText").html(e[0][lang]) - } - $("#donationText").html(s.AvionPoeme_free_independent) - $("#donationButtonText").html(s.Soutenez_avionpoeme) - $("#donationButtonText").addClass(lang) - }) - - //plane limit tooltip - if (typeof nbPlane !== 'undefined') { - if (nbPlane > 99){ - $("#planeLimitTooltip").attr("title", s.AvionPoeme_epuise).tooltip("_fixTitle"); - } - else{ - var remainingPlanes = 100 - nbPlane; - s.NB_AvionPoeme_restant = s.NB_AvionPoeme_restant.replace('$NB_avion_poeme',remainingPlanes) - $("#planeLimitTooltip").attr("title", s.NB_AvionPoeme_restant).tooltip("_fixTitle"); - } - } - - }) - .always(function(callback) { - //console.log( callback ); - }); +function translateUI(l) { + $.getJSON("lang/" + l + "", function (s) { + dictionnary = s; + //if arabic : display left to right (ltr) + troubleshooting a lot of individual elements + if (lang == "ar") { + //navbar + $("nav").css("direction", "rtl"); + $(".nav-menus").removeClass("mr-auto"); + $(".nav-button").addClass("mr-auto"); + //form + // $(".ql-container").css('direction','rtl') + // $(".ql-container").css('float','right') + // $(".ql-editor").css('float','right') + // $(".ql-editor p").css('float','right') + $(".modal-content").css("direction", "rtl"); + $(".bold").css("float", "right"); + $("#public").css("margin-left", "5px"); + $("#prive").css("margin-left", "5px"); + $("#newPlaneModalAnonyme").css("margin-right", "25px"); + $("#newPlaneModalCancel").css("margin-left", "8px"); + $("#closeModal").css("margin-left", "0px"); + $("#closeModal").css("padding-left", "0px"); + //anthology + $("#anthology").css("direction", "rtl"); + $("#anthologyDisclaimer").css("float", "right"); + } else { + //navbar + $("nav").css("direction", "ltr"); + $(".nav-menus").addClass("mr-auto"); + $(".nav-button").removeClass("mr-auto"); + //form + // $(".ql-container").css('direction','ltr') + // $(".ql-container").css('float','left') + // $(".ql-editor").css('float','left') + // $(".ql-editor p").css('float','none') + $(".modal-content").css("direction", "ltr"); + $(".bold").css("float", "left"); + $("#public").css("margin-left", "0px"); + $("#prive").css("margin-left", "0px"); + $("#newPlaneModalAnonyme").css("margin-right", "0px"); + $("#newPlaneModalCancel").css("margin-left", "0px"); + //anthology + $("#anthology").css("direction", "ltr"); + $("#anthologyDisclaimer").css("float", "left"); + } + + //changing all strings + //main page + $("head title", window.parent.document).text(s.avionpoeme); + $("#navTitle").html(s.avionpoeme); + $("#buttonAnthology").html(s.anthologie); + $("#buttonAbout").html(s.apropos); + if (typeof nbPlane !== "undefined") { + $("#buttonNewPlane").val(s.lancer_avion + " " + nbPlane + "/100"); + } else { + $("#buttonNewPlane").on("click", () => { + window.location.replace("/"); + }); + } + //new plane form + $("#newPlaneModalTitle").html(s.lancer_avion); + $("#newPlaneModalMessage").html(s.message); + $("#newPlaneModalPrive").html(s.prive); + $("#newPlaneModalPublic").html(s.public); + $("#labelAttachment").html(s.PJ_Ajouter); + console.log(s); + $("#attachmentPlaneLabel").attr("data-after", s.PJ_Parcourir); + $("#flightTime").html(s.temps_de_vol); + $("#newPlaneModalRandom").html(s.aléatoire); + $("#newPlaneModal3j").html(s.trois_jours); + $("#newPlaneModal7j").html(s.sept_jours); + $("#newPlaneModal30j").html(s.trente_jours); + $("#newPlaneModal365j").html(s.unan_jours); + $("#newPlaneModalExpediteur").html(s.expediteur); + $("#newPlaneModalDestinataire").html(s.destinataire); + $("#newPlaneModalAnonyme").html(s.anonyme); + $("#newPlaneModalCancel").html(s.annuler); + $("#sendNewPlane").html(s.lancer); + $("#destLang").html(s.langue_destinataire); + $("#expeMail").attr("placeholder", s.expeMail_placeholder); + $("#expeGeocoderPhoton").attr("placeholder", s.expeLoc_placeholder); + $("#destMail").attr("placeholder", s.destMail_placeholder); + $("#destGeocoderPhoton").attr("placeholder", s.destLoc_placeholder); + $("#anonymeTooltip").attr("title", s.anonyme_tooltip).tooltip("_fixTitle"); + $("#publicTooltip").attr("title", s.public_tooltip).tooltip("_fixTitle"); + + $('#selectDestLang option[value="' + lang + '"]').prop("selected", true); //selecting by default recipient language same as interface + //Anthology + displayAnthology(); + $("#anthologyTitle").html(s.anthologie); + $("#anthologyDisclaimer").html(s.suppr_message_public); + $("#closeAnthologyAbout").html(s.retour_carte); + + //About + $("#aboutTitle").html(s.apropos); + $("#librairies").html(s.librairies); + $("#mapSources").html(s.source_carte); + $("#mapBackground").html(s.map_background); + $("#clouds").html(s.clouds); + $.getJSON("lang/about.json", function (e) { + if (lang !== "en" && lang !== "fr" && lang !== "de") { + $("#aboutText").html(e[0].en); + } else { + $("#aboutText").html(e[0][lang]); + } + $("#donationText").html(s.AvionPoeme_free_independent); + $("#donationButtonText").html(s.Soutenez_avionpoeme); + $("#donationButtonText").addClass(lang); + }); + + //plane limit tooltip + if (typeof nbPlane !== "undefined") { + if (nbPlane > 99) { + $("#planeLimitTooltip") + .attr("title", s.AvionPoeme_epuise) + .tooltip("_fixTitle"); + } else { + var remainingPlanes = 100 - nbPlane; + s.NB_AvionPoeme_restant = s.NB_AvionPoeme_restant.replace( + "$NB_avion_poeme", + remainingPlanes + ); + $("#planeLimitTooltip") + .attr("title", s.NB_AvionPoeme_restant) + .tooltip("_fixTitle"); + } + } + }).always(function (callback) { + //console.log( callback ); + }); } //hovering lang icon -$( "#navbarDropdownLang" ).mouseenter(function() { - $("#langIcon").attr("src","src/img/lang-hover.png"); +$("#navbarDropdownLang").mouseenter(function () { + $("#langIcon").attr("src", "src/img/lang-hover.png"); }); -$( "#navbarDropdownLang" ).mouseleave(function() { - $("#langIcon").attr("src","src/img/lang.png"); +$("#navbarDropdownLang").mouseleave(function () { + $("#langIcon").attr("src", "src/img/lang.png"); }); - -