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.7 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") se fait exécuter dans weatherRequest.php
$("#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
}
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-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
{
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-23 20:23:57 +02:00
/* Window Scroll Top Button */
var $btnScrollTop = $('.scroll-top-arrow');
2019-08-23 20:23:57 +02:00
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$btnScrollTop.fadeIn();
} else {
$btnScrollTop.fadeOut();
}
});
$btnScrollTop.on('click', function () {
$('html, body').animate({scrollTop: 0}, 800);
return false;
});
2019-08-16 12:05:56 +02:00
// Fin de l'import des fonctions
});
// Fin de l'import des variables
});
})