This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/scripts/main.js

244 lines
7.9 KiB
JavaScript
Raw Normal View History

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 */
$( "#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 + "";
weatherRequest(url, 'weather');
}
});
$("#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
}
});
$("#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);
}
}
});
$("#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);
}
}
});
$("#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());
}
/* Permet d'afficher la liste des citations/proverbes */
if(chemin === "/views/quote-list.php") {
window.onload = $('.totalLengthQuote').html('Total de ' + quotes.length + ' citations.');
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()
{
let euroValue = $('#euroValue').val();
let euroToCurrency = $("#euroToCurrency option:selected").val();
if(isEmptyValue(euroValue) || isNaN(parseFloat(euroValue)))
{
$('.results').html(emptyMessageError);
$("#euroValue, #submitConvertCurrency").click(function() {
document.location.replace("../function-views/convertCurrency.php");
});
}
else
{
euroValue = parseFloat(euroValue);
2019-09-13 23:00:41 +02:00
convertCurrency(euroToCurrency, euroValue);
2019-09-13 21:56:36 +02:00
}
});
2019-09-14 17:38:30 +02:00
$("#submitConvertBinaryText").click(function()
{
let binaryTextValue = $('#binaryTextValue').val();
let isBinaryValue = isStringBin(binaryTextValue);
if(isEmptyValue(binaryTextValue)) {
$('.results').html(emptyMessageError);
}
else if (isBinaryValue === true) {
// Le replace enlève les espaces
let textResult = binToUtf8(binaryTextValue.replace(/\s/g,''));
$('.results').html(textResult);
}
else if (isBinaryValue === false) {
// 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-08-18 20:06:06 +02:00
/* Permet d'afficher l'heure en temps réel sur le footer */
window.onload = realDateTime('realDateTime');
2019-08-23 20:23:57 +02:00
/* Window Scroll Top Button */
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
});
})