2019-08-16 12:05:56 +02:00
|
|
|
$(function () {
|
|
|
|
|
|
|
|
// Fichiers qui contient les variables
|
|
|
|
$.getScript("/scripts/variables.js", function() {
|
|
|
|
|
|
|
|
// Fichiers qui contient les fonctions
|
|
|
|
$.getScript("/scripts/fonctions.js", function() {
|
|
|
|
|
|
|
|
/* ÉXECUTION DES FONCTONS */
|
|
|
|
|
2019-08-29 12:50:17 +02:00
|
|
|
$( "#submitWeatherRequest" ).click(function()
|
|
|
|
{
|
|
|
|
let city = $('#cityName').val();
|
|
|
|
let cityName = city.split(' ').join('+');
|
|
|
|
if(isEmptyValue(cityName))
|
|
|
|
{
|
|
|
|
$('.results').html(emptyMessageError);
|
|
|
|
$("#cityName, #submitWeatherRequest").click(function() {
|
|
|
|
document.location.replace("../function-views/weatherRequest.php");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-13 21:56:36 +02:00
|
|
|
let url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=fr&units=metric&appid=" + config.APIkeyWeather + "";
|
2019-09-16 18:17:02 +02:00
|
|
|
weatherRequest(url);
|
2019-08-29 12:50:17 +02:00
|
|
|
}
|
|
|
|
});
|
2019-08-28 13:41:26 +02:00
|
|
|
|
|
|
|
$("#submitRandomNumber").click(function()
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
|
|
|
let minEntered = $('#minValue').val();
|
|
|
|
let maxEntered = $('#maxValue').val();
|
|
|
|
|
|
|
|
if(isEmptyValue(minEntered) || isEmptyValue(maxEntered))
|
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
$('.results').html(emptyMessageError);
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
2019-09-13 14:39:29 +02:00
|
|
|
else if (!isNaN(parseInt(minEntered)) && !isNaN(parseInt(maxEntered)))
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
|
|
|
let result = randomNumber(minEntered, maxEntered);
|
2019-09-13 14:39:29 +02:00
|
|
|
if (minEntered < maxEntered)
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
2019-09-13 14:39:29 +02:00
|
|
|
$('.results').html("Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + formatNumberResult(result));
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
2019-09-13 14:39:29 +02:00
|
|
|
else if (minEntered > maxEntered) {
|
|
|
|
$('.results').html("Votre nombre minimum est plus grand que le nombre maximum.");
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
2019-09-13 14:39:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-28 13:41:26 +02:00
|
|
|
$("#submitCalculateAge").click(function()
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
let birthDateEntered = $('#birthDateValue').val();
|
2019-08-16 12:05:56 +02:00
|
|
|
|
2019-08-18 20:06:06 +02:00
|
|
|
if(isEmptyValue(birthDateEntered))
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
$('.results').html(emptyMessageError);
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
let result = calculateAge(birthDateEntered);
|
2019-08-16 12:05:56 +02:00
|
|
|
if(result === messageError)
|
|
|
|
{
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('.results').html(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-28 13:41:26 +02:00
|
|
|
$("#submitConvertTemperature").click(function()
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
|
|
|
let temperatureValue = $('#temperatureValue').val();
|
|
|
|
let degree = parseFloat(temperatureValue.slice(0, temperatureValue.length - 2));
|
|
|
|
let unit = temperatureValue.slice(temperatureValue.length - 2);
|
|
|
|
|
|
|
|
if(isEmptyValue(temperatureValue))
|
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
$('.results').html(emptyMessageError);
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let result = convertTemperature(degree, unit);
|
|
|
|
if(result === messageError)
|
|
|
|
{
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('.results').html(degree + " " + unit + " = " + result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-28 13:41:26 +02:00
|
|
|
$("#submitConvertDistance").click(function()
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
2019-08-29 23:35:40 +02:00
|
|
|
let firstValue = $('#firstValue').val();
|
|
|
|
let unitFirstValue = $("#firstValueUnit option:selected").text();
|
|
|
|
let secondValue = $("#secondValue option:selected").text();
|
2019-08-16 12:05:56 +02:00
|
|
|
|
2019-08-29 23:35:40 +02:00
|
|
|
if(isEmptyValue(firstValue) || isEmptyValue(secondValue))
|
2019-08-16 12:05:56 +02:00
|
|
|
{
|
2019-08-18 20:06:06 +02:00
|
|
|
$('.results').html(emptyMessageError);
|
2019-08-16 12:05:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-15 09:45:20 +02:00
|
|
|
firstValue = parseFloat(firstValue.replace(/\s/g,''));
|
|
|
|
let result = convertDistance(firstValue, unitFirstValue, secondValue);
|
2019-08-16 12:05:56 +02:00
|
|
|
if(result === messageError)
|
|
|
|
{
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('.results').html(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-29 14:53:15 +02:00
|
|
|
$("#submitFilterStudents").click(function()
|
|
|
|
{
|
|
|
|
let nameEntered = $('#nameEntered').val();
|
|
|
|
let filteredLetter = $("#filteredLetter").val();
|
|
|
|
|
|
|
|
if(isEmptyValue(nameEntered) || isEmptyValue(filteredLetter))
|
|
|
|
{
|
|
|
|
$('.results').html(emptyMessageError);
|
|
|
|
}
|
|
|
|
else if(filteredLetter.length === 1)
|
|
|
|
{
|
|
|
|
let students = nameEntered.split(', ');
|
|
|
|
filteredLetter = capitalize(filteredLetter);
|
|
|
|
let result = filterStudents(filteredLetter, students);
|
|
|
|
$('.results').html(result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-13 14:39:29 +02:00
|
|
|
let randomQuoteClicked;
|
|
|
|
$("#submitRandomQuote").click(function()
|
|
|
|
{
|
|
|
|
randomQuoteClicked = true;
|
|
|
|
$('.resultsRandomQuote').html(getRandomQuote());
|
|
|
|
});
|
|
|
|
// Affichage d'une citation au chargement de la page
|
|
|
|
if (randomQuoteClicked != true && window.location.href.indexOf("randomQuote") > -1) {
|
|
|
|
$('.resultsRandomQuote').html(getRandomQuote());
|
|
|
|
}
|
|
|
|
|
2019-09-13 15:58:51 +02:00
|
|
|
/* Permet d'afficher la liste des citations/proverbes */
|
|
|
|
if(chemin === "/views/quote-list.php") {
|
2019-09-14 22:34:27 +02:00
|
|
|
window.onload = $('.totalLengthQuote').html('Total de ' + quotes.length + ' citations.');
|
2019-09-13 15:58:51 +02:00
|
|
|
for (index in quotes) {
|
|
|
|
$( ".quote-list" ).append('<tr> <td class="quote-element-list important">' + quotes[index]["source"] + '</td> <td class="quote-element-list">" ' + quotes[index]["quote"] + ' "</td> </tr>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 21:56:36 +02:00
|
|
|
$("#submitConvertCurrency").click(function()
|
|
|
|
{
|
2019-09-16 20:39:30 +02:00
|
|
|
let value = $('#value').val();
|
|
|
|
let currencyOfTheValue = $("#currencyOfTheValue option:selected").val();
|
|
|
|
let currencyAfter = $("#currencyAfter option:selected").val();
|
|
|
|
if(isEmptyValue(value) || isNaN(parseFloat(value)))
|
2019-09-13 21:56:36 +02:00
|
|
|
{
|
|
|
|
$('.results').html(emptyMessageError);
|
2019-09-16 20:39:30 +02:00
|
|
|
$("#value, #submitConvertCurrency").click(function() {
|
2019-09-13 21:56:36 +02:00
|
|
|
document.location.replace("../function-views/convertCurrency.php");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-16 20:39:30 +02:00
|
|
|
let url = 'https://api.exchangeratesapi.io/latest?base=' + currencyOfTheValue;
|
|
|
|
value = parseFloat(value);
|
|
|
|
convertCurrency(value, currencyAfter, url);
|
2019-09-13 21:56:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-14 17:38:30 +02:00
|
|
|
$("#submitConvertBinaryText").click(function()
|
|
|
|
{
|
|
|
|
let binaryTextValue = $('#binaryTextValue').val();
|
2019-09-15 21:51:54 +02:00
|
|
|
let convertIn = $("#convertIn option:selected").text();
|
2019-09-14 17:38:30 +02:00
|
|
|
|
|
|
|
if(isEmptyValue(binaryTextValue)) {
|
|
|
|
$('.results').html(emptyMessageError);
|
|
|
|
}
|
2019-09-15 22:04:51 +02:00
|
|
|
else if (convertIn === 'Texte') {
|
2019-09-14 17:38:30 +02:00
|
|
|
// Le replace enlève les espaces
|
|
|
|
let textResult = binToUtf8(binaryTextValue.replace(/\s/g,''));
|
|
|
|
|
|
|
|
$('.results').html(textResult);
|
|
|
|
}
|
2019-09-15 22:04:51 +02:00
|
|
|
else if (convertIn === 'Binaire') {
|
2019-09-14 17:38:30 +02:00
|
|
|
// Les 2 replace permettent de rajouter un espace tout les 8 bits
|
|
|
|
let binaryResult = utf8ToBin(binaryTextValue);
|
|
|
|
binaryResult = binaryResult.replace(/(\d{8})/g, '$1 ').replace(/(^\s+|\s+$)/,'');
|
|
|
|
|
|
|
|
$('.results').html(binaryResult);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('.results').html(messageError);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-13 15:58:51 +02:00
|
|
|
|
2019-08-18 20:06:06 +02:00
|
|
|
/* Permet d'afficher l'heure en temps réel sur le footer */
|
2019-08-17 12:32:35 +02:00
|
|
|
window.onload = realDateTime('realDateTime');
|
|
|
|
|
2019-08-23 20:23:57 +02:00
|
|
|
/* Window Scroll Top Button */
|
2019-08-28 13:41:26 +02:00
|
|
|
var $btnScrollTop = $('.scroll-top-arrow');
|
2019-08-23 20:23:57 +02:00
|
|
|
$btnScrollTop.on('click', function () {
|
|
|
|
$('html, body').animate({scrollTop: 0}, 800);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2019-08-29 22:33:07 +02:00
|
|
|
/* Date Picker */
|
|
|
|
$.fn.datepicker.dates['fr'] = {
|
|
|
|
days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
|
|
|
|
daysShort: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
|
|
|
|
daysMin: ["d", "l", "ma", "me", "j", "v", "s"],
|
|
|
|
months: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
|
|
|
|
monthsShort: ["janv.", "févr.", "mars", "avril", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."],
|
|
|
|
today: "Aujourd'hui",
|
|
|
|
monthsTitle: "Mois",
|
|
|
|
clear: "Effacer",
|
|
|
|
weekStart: 1,
|
|
|
|
format: "dd/mm/yyyy"
|
|
|
|
};
|
|
|
|
$('.datepicker').datepicker({
|
|
|
|
language: 'fr',
|
|
|
|
autoclose: true,
|
|
|
|
todayHighlight: true
|
|
|
|
})
|
|
|
|
|
2019-08-16 12:05:56 +02:00
|
|
|
// Fin de l'import des fonctions
|
|
|
|
});
|
|
|
|
// Fin de l'import des variables
|
|
|
|
});
|
|
|
|
})
|