2019-08-16 12:05:56 +02:00
$ ( 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 ) ;
}
else
{
2019-10-04 13:47:32 +02:00
createSessionCookie ( "city" , cityName ) ;
weatherRequest ( ) ;
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-10-04 20:10:38 +02:00
else
2019-08-16 12:05:56 +02:00
{
let result = randomNumber ( minEntered , maxEntered ) ;
2019-10-04 20:10:38 +02:00
if ( result === messageError ) {
2019-09-17 19:17:30 +02:00
$ ( '.results' ) . html ( messageError ) ;
2019-10-04 20:10:38 +02:00
} else {
$ ( '.results' ) . html ( "Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + formatNumberResult ( result ) ) ;
}
2019-08-16 12:05:56 +02:00
}
} ) ;
2019-10-11 19:08:28 +02:00
$ ( "#birthDateValue" ) . bind ( "keyup change" , function ( )
2019-08-16 12:05:56 +02:00
{
2019-08-18 20:06:06 +02:00
let birthDateEntered = $ ( '#birthDateValue' ) . val ( ) ;
2019-10-11 19:08:28 +02:00
let result = calculateAge ( birthDateEntered ) ;
if ( result === messageError )
2019-08-16 12:05:56 +02:00
{
2019-10-11 19:08:28 +02:00
$ ( '.results' ) . html ( messageError ) ;
2019-08-16 12:05:56 +02:00
}
else
{
2019-10-11 19:08:28 +02:00
$ ( '.results' ) . html ( result ) ;
2019-08-16 12:05:56 +02:00
}
} ) ;
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-10-04 23:53:26 +02:00
let resultat = "" ;
2019-09-13 15:58:51 +02:00
for ( index in quotes ) {
2019-10-04 23:53:26 +02:00
resultat = resultat + ` <tr> <td class="quote-element-list important"> ${ quotes [ index ] [ "source" ] } </td> <td class="quote-element-list"> ${ quotes [ index ] [ "quote" ] } </td> </tr> ` ;
2019-09-13 15:58:51 +02:00
}
2019-10-04 23:53:26 +02:00
$ ( ".quote-list" ) . append ( resultat ) ;
2019-09-13 15:58:51 +02:00
}
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-10-05 17:00:37 +02:00
$ ( "#submitConvertEncoding" ) . click ( function ( )
2019-09-14 17:38:30 +02:00
{
2019-10-05 17:00:37 +02:00
let value = $ ( '#value' ) . val ( ) ;
let option = $ ( "#option option:selected" ) . val ( ) ;
if ( isEmptyValue ( value ) )
{
$ ( '.results' ) . html ( messageError ) ;
2019-09-14 17:38:30 +02:00
}
2019-10-05 17:00:37 +02:00
else
{
if ( option === 'DecimalToBinary' || option === 'BinaryToDecimal' || option === 'DecimalToHexadecimal' || option === 'HexadecimalToDecimal' || option === 'BinaryToHexadecimal' || option === 'HexadecimalToBinary' ) {
let result = convertDecimalBinaryHexadecimal ( value , option ) ;
2019-10-05 17:29:27 +02:00
if ( result === messageError ) {
2019-10-05 17:00:37 +02:00
$ ( '.results' ) . html ( messageError ) ;
} else {
$ ( '.results' ) . html ( result ) ;
}
}
else if ( option === 'BinaryToText' ) {
2019-09-14 17:38:30 +02:00
// Le replace enlève les espaces
2019-10-05 17:00:37 +02:00
let textResult = binToUtf8 ( value . replace ( /\s/g , '' ) ) ;
2019-09-14 17:38:30 +02:00
$ ( '.results' ) . html ( textResult ) ;
2019-10-05 17:00:37 +02:00
}
else if ( option === 'TextToBinary' ) {
// Les 2 replace permettent de rajouter un espace tout les 8 bits
let binaryResult = utf8ToBin ( value ) ;
binaryResult = binaryResult . replace ( /(\d{8})/g , '$1 ' ) . replace ( /(^\s+|\s+$)/ , '' ) ;
$ ( '.results' ) . html ( binaryResult ) ;
}
2019-10-05 19:05:15 +02:00
else if ( option === 'TextToHexadecimal' ) {
let result = utf8ToHex ( value ) ;
$ ( '.results' ) . html ( result . toUpperCase ( ) ) ;
}
else if ( option === 'HexadecimalToText' ) {
let result = hexToUtf8 ( value . replace ( /\s/g , '' ) ) ;
$ ( '.results' ) . html ( result ) ;
}
2019-10-05 17:00:37 +02:00
else {
2019-09-14 17:38:30 +02:00
$ ( '.results' ) . html ( messageError ) ;
2019-10-05 17:00:37 +02:00
}
2019-09-14 17:38:30 +02:00
}
} ) ;
2019-09-21 19:45:54 +02:00
$ ( "#submitConvertRomanArabicNumbers" ) . click ( function ( )
{
let numbersValue = $ ( '#numbersArabic' ) . val ( ) ;
2019-09-22 10:09:25 +02:00
let convertNumberType = $ ( "#convertNumberType option:selected" ) . text ( ) ;
2019-09-21 19:45:54 +02:00
if ( isEmptyValue ( numbersValue ) ) {
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-09-22 10:09:25 +02:00
else if ( ! isNaN ( parseInt ( numbersValue ) ) && convertNumberType === "Nombre Romain" ) {
2019-10-06 21:03:50 +02:00
let result = convertArabicToRoman ( parseInt ( numbersValue . replace ( /\s/g , '' ) ) ) ;
let numbersValueFormat = formatNumberResult ( numbersValue . replace ( /\s/g , '' ) ) ;
if ( numbersValueFormat === messageError || result === messageError ) {
$ ( '.results' ) . html ( messageError ) ;
} else {
$ ( '.results' ) . html ( ` <b> ${ numbersValueFormat } </b> s'écrit <b> ${ result } </b> en chiffres romains. ` ) ;
}
2019-09-21 19:45:54 +02:00
}
2019-09-22 10:09:25 +02:00
else if ( convertNumberType === "Nombre Arabe" ) {
2019-10-06 21:23:07 +02:00
if ( ! isNaN ( Number ( numbersValue ) ) ) {
2019-09-22 10:09:25 +02:00
$ ( '.results' ) . html ( ` <b> ${ numbersValue } </b> est déjà en chiffres arabes. ` ) ;
} else {
2019-09-22 10:48:03 +02:00
numbersValue = numbersValue . toUpperCase ( ) ;
2019-09-22 10:09:25 +02:00
let result = convertRomanToArabic ( numbersValue ) ;
2019-10-06 21:03:50 +02:00
if ( result === 0 ) {
$ ( '.results' ) . html ( messageError ) ;
} else {
2019-10-08 11:18:34 +02:00
$ ( '.results' ) . html ( ` <b> ${ numbersValue } </b> s'écrit <b> ${ formatNumberResult ( result ) } </b> en chiffres arabes. ` ) ;
2019-10-06 21:03:50 +02:00
}
2019-09-22 10:09:25 +02:00
}
}
2019-09-21 19:45:54 +02:00
else {
$ ( '.results' ) . html ( messageError ) ;
}
} ) ;
2019-10-11 19:08:28 +02:00
$ ( "#numberToTest" ) . bind ( "keyup change" , function ( )
2019-09-21 22:40:16 +02:00
{
let numbersValue = $ ( '#numberToTest' ) . val ( ) ;
2019-10-11 19:08:28 +02:00
if ( ! isNaN ( parseInt ( numbersValue ) ) ) {
2019-09-21 22:40:16 +02:00
let result = armstrongNumber ( parseFloat ( numbersValue . replace ( /\s/g , '' ) ) ) ;
$ ( '.results' ) . html ( result ) ;
}
else {
$ ( '.results' ) . html ( messageError ) ;
}
} ) ;
2019-10-11 21:30:05 +02:00
$ ( "#submitHeapAlgorithm" ) . click ( function ( )
{
let value = $ ( '#value' ) . val ( ) ;
2019-09-13 15:58:51 +02:00
2019-10-11 21:30:05 +02:00
if ( isEmptyValue ( value ) )
{
$ ( '.results' ) . html ( emptyMessageError ) ;
}
else
{
let stringPermutationsResult = stringPermutations ( value ) ;
let result = "" ;
for ( element in stringPermutationsResult ) {
result = result + stringPermutationsResult [ element ] + "<br>" ;
}
$ ( '.results' ) . html ( ` Il y a ${ formatNumberResult ( stringPermutationsResult . length ) } possibilités d'anagramme pour le mot " ${ value } " qui contient ${ value . length } caractères, la liste : <br><br> ${ result } ` ) ;
}
} ) ;
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
} )