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

130 lines
3.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('+');
2019-08-18 20:06:06 +02:00
if(isEmptyValue(cityName))
2019-08-16 12:05:56 +02:00
{
2019-08-18 20:06:06 +02:00
$('.results').html(emptyMessageError);
$("#cityName, #submitWeatherRequest").click(function() {
2019-08-16 12:05:56 +02:00
document.location.replace("../function-views/weatherRequest.php");
2019-08-18 20:06:06 +02:00
});
2019-08-16 12:05:56 +02:00
}
else
{
let url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=fr&units=metric&appid=" + config.APIkey + "";
weatherRequest(url, 'weather');
}
});
$( "#submitRandomNumber" ).click(function()
{
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
}
else
{
let result = randomNumber(minEntered, maxEntered);
if(result === messageError)
{
$('.results').html(messageError);
}
else
{
$('.results').html("Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + result);
}
}
});
$( "#submitCalculateAge" ).click(function()
{
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()
{
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()
{
let firstValueEntered = $('#firstValue').val();
let secondValueEntered = $("#secondValue option:selected").text();
2019-08-16 12:05:56 +02:00
if(isEmptyValue(firstValueEntered) || isEmptyValue(secondValueEntered))
{
2019-08-18 20:06:06 +02:00
$('.results').html(emptyMessageError);
2019-08-16 12:05:56 +02:00
}
else
{
let firstValue = parseFloat(firstValueEntered.slice(0, firstValueEntered.length - 2));;
let unitFirstValue = firstValueEntered.slice(firstValueEntered.length - 2);
let result = convertDistance(firstValue, unitFirstValue, secondValueEntered);
if(result === messageError)
{
$('.results').html(messageError);
}
else
{
$('.results').html(result);
}
}
});
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-16 12:05:56 +02:00
// Fin de l'import des fonctions
});
// Fin de l'import des variables
});
})