2019-08-16 12:05:56 +02:00
$ ( function ( ) {
/* ÉXECUTION DES FONCTONS */
2019-10-24 21:01:03 +02:00
// Touche entrer génère un clique sur les classes .btn à part sur la page convertEncoding
2019-10-23 12:21:21 +02:00
$ ( "body" ) . keydown ( function ( e ) {
2019-10-24 21:01:03 +02:00
if ( e . which === 13 && chemin !== '/views/function-views/convertEncoding.php' ) {
2019-10-23 12:21:21 +02:00
$ ( ".btn" ) . click ( ) ;
}
} ) ;
$ ( "#submitWeatherRequest" ) . click ( ( ) => {
2019-10-18 09:55:35 +02:00
const city = $ ( '#cityName' ) . val ( ) ;
const cityName = city . split ( ' ' ) . join ( '+' ) ;
2019-10-23 09:33:36 +02:00
if ( isEmptyValue ( cityName ) ) {
2019-08-29 12:50:17 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-10-23 09:33:36 +02:00
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
2019-10-23 09:33:36 +02:00
$ ( "#submitRandomNumber" ) . click ( ( ) => {
2019-10-18 09:55:35 +02:00
const minEntered = $ ( '#minValue' ) . val ( ) ;
const maxEntered = $ ( '#maxValue' ) . val ( ) ;
2019-10-23 09:33:36 +02:00
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-23 09:33:36 +02:00
else {
2019-10-18 09:55:35 +02:00
const 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-23 09:33:36 +02:00
$ ( "#birthDateValue" ) . bind ( "keyup change" , ( ) =>
2019-08-16 12:05:56 +02:00
{
2019-10-24 18:57:39 +02:00
$ ( '.results' ) . html ( calculateAge ( $ ( '#birthDateValue' ) . val ( ) ) ) ;
2019-08-16 12:05:56 +02:00
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitConvertTemperature" ) . click ( ( ) =>
2019-08-16 12:05:56 +02:00
{
2019-10-18 09:55:35 +02:00
const temperatureValue = $ ( '#temperatureValue' ) . val ( ) ;
const degree = parseFloat ( temperatureValue . slice ( 0 , temperatureValue . length - 2 ) ) ;
const unit = temperatureValue . slice ( temperatureValue . length - 2 ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( temperatureValue ) ) {
2019-08-18 20:06:06 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
2019-08-16 12:05:56 +02:00
}
2019-10-18 20:35:03 +02:00
else {
$ ( '.results' ) . html ( convertTemperature ( degree , unit ) ) ;
2019-08-16 12:05:56 +02:00
}
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitConvertDistance" ) . click ( ( ) =>
2019-08-16 12:05:56 +02:00
{
2019-08-29 23:35:40 +02:00
let firstValue = $ ( '#firstValue' ) . val ( ) ;
2019-10-18 09:55:35 +02:00
const unitFirstValue = $ ( "#firstValueUnit option:selected" ) . text ( ) ;
const secondValue = $ ( "#secondValue option:selected" ) . text ( ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( firstValue ) || isEmptyValue ( secondValue ) ) {
2019-08-18 20:06:06 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
2019-08-16 12:05:56 +02:00
}
2019-10-18 20:35:03 +02:00
else {
2019-09-15 09:45:20 +02:00
firstValue = parseFloat ( firstValue . replace ( /\s/g , '' ) ) ;
2019-10-18 20:35:03 +02:00
$ ( '.results' ) . html ( convertDistance ( firstValue , unitFirstValue , secondValue ) ) ;
2019-08-16 12:05:56 +02:00
}
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitFilterStudents" ) . click ( ( ) =>
2019-08-29 14:53:15 +02:00
{
2019-10-18 09:55:35 +02:00
const nameEntered = $ ( '#nameEntered' ) . val ( ) ;
2019-08-29 14:53:15 +02:00
let filteredLetter = $ ( "#filteredLetter" ) . val ( ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( nameEntered ) || isEmptyValue ( filteredLetter ) ) {
2019-08-29 14:53:15 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-10-18 20:35:03 +02:00
else if ( filteredLetter . length === 1 ) {
2019-10-18 09:55:35 +02:00
const students = nameEntered . split ( ', ' ) ;
2019-08-29 14:53:15 +02:00
filteredLetter = capitalize ( filteredLetter ) ;
2019-10-18 20:35:03 +02:00
$ ( '.results' ) . html ( filterStudents ( filteredLetter , students ) ) ;
2019-08-29 14:53:15 +02:00
}
else {
$ ( '.results' ) . html ( messageError ) ;
}
} ) ;
2019-09-13 14:39:29 +02:00
let randomQuoteClicked ;
2019-10-23 09:33:36 +02:00
$ ( "#submitRandomQuote" ) . click ( ( ) => {
2019-09-13 14:39:29 +02:00
randomQuoteClicked = true ;
$ ( '.resultsRandomQuote' ) . html ( getRandomQuote ( ) ) ;
} ) ;
// Affichage d'une citation au chargement de la page
2019-10-24 21:01:03 +02:00
if ( randomQuoteClicked != true && chemin === '/views/function-views/randomQuote.php' ) {
2019-09-13 14:39:29 +02:00
$ ( '.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-24 18:57:39 +02:00
$ ( ".quote-list" ) . append ( resultat ) ;
2019-09-13 15:58:51 +02:00
}
2019-10-23 09:33:36 +02:00
$ ( "#submitConvertCurrency" ) . click ( ( ) => {
2019-09-16 20:39:30 +02:00
let value = $ ( '#value' ) . val ( ) ;
2019-10-18 09:55:35 +02:00
const currencyOfTheValue = $ ( "#currencyOfTheValue option:selected" ) . val ( ) ;
const currencyAfter = $ ( "#currencyAfter option:selected" ) . val ( ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( value ) || isNaN ( parseFloat ( value ) ) ) {
2019-09-13 21:56:36 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-10-18 20:35:03 +02:00
else {
const url = 'https://api.exchangeratesapi.io/latest?base=' + currencyOfTheValue ;
2019-09-16 20:39:30 +02:00
value = parseFloat ( value ) ;
convertCurrency ( value , currencyAfter , url ) ;
2019-09-13 21:56:36 +02:00
}
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitConvertEncoding" ) . click ( ( ) => {
2019-10-18 09:55:35 +02:00
const value = $ ( '#value' ) . val ( ) ;
const option = $ ( "#option option:selected" ) . val ( ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( value ) ) {
2019-10-05 17:00:37 +02:00
$ ( '.results' ) . html ( messageError ) ;
2019-09-14 17:38:30 +02:00
}
2019-10-23 09:33:36 +02:00
else {
2019-10-24 18:57:39 +02:00
// Objet qui recense toutes les fonctions de convertEncoding
const convertEncoding = { decimalToBinary , binaryToDecimal , decimalToHexadecimal , hexadecimalToDecimal , binaryToHexadecimal , hexadecimalToBinary , textToNumberUnicode , numberUnicodeToText , textToBinary , binaryToText , textToHexadecimal , hexadecimalToText } ;
try {
function executionFunction ( option , value ) {
2019-11-04 16:36:04 +01:00
return convertEncoding [ option ] ( value )
2019-10-24 18:57:39 +02:00
}
$ ( '.results' ) . html ( executionFunction ( option , value ) ) ;
} catch ( error ) {
$ ( '.results' ) . html ( messageError ) ;
}
2019-09-14 17:38:30 +02:00
}
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitConvertRomanArabicNumbers" ) . click ( ( ) => {
2019-09-21 19:45:54 +02:00
let numbersValue = $ ( '#numbersArabic' ) . val ( ) ;
2019-10-18 20:35:03 +02:00
numbersValue = numbersValue . replace ( /\s/g , '' ) ;
2019-10-18 09:55:35 +02:00
const convertNumberType = $ ( "#convertNumberType option:selected" ) . text ( ) ;
2019-09-21 19:45:54 +02:00
if ( isEmptyValue ( numbersValue ) ) {
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-11-16 10:17:28 +01:00
else if ( ! isNaN ( Number ( numbersValue ) ) ) {
if ( convertNumberType === "Nombre Romain" ) {
const result = convertArabicToRoman ( parseInt ( numbersValue ) ) ;
let numbersValueFormat = formatNumberResult ( numbersValue ) ;
if ( result === messageError || isFloat ( numbersValue ) ) {
$ ( '.results' ) . html ( messageError ) ;
} else {
$ ( '.results' ) . html ( ` <b> ${ numbersValueFormat } </b> s'écrit <b> ${ result } </b> en chiffres romains. ` ) ;
}
2019-10-06 21:03:50 +02:00
} else {
2019-11-16 10:17:28 +01:00
$ ( '.results' ) . html ( ` <b> ${ numbersValue } </b> est déjà en chiffres arabes. ` ) ;
2019-10-06 21:03:50 +02:00
}
2019-11-16 10:17:28 +01:00
2019-09-21 19:45:54 +02:00
}
2019-09-22 10:09:25 +02:00
else if ( convertNumberType === "Nombre Arabe" ) {
2019-11-16 10:17:28 +01:00
const result = convertRomanToArabic ( numbersValue . toUpperCase ( ) ) ;
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-23 09:33:36 +02:00
$ ( "#numberToTest" ) . bind ( "keyup change" , ( ) => {
2019-09-21 22:40:16 +02:00
let numbersValue = $ ( '#numberToTest' ) . val ( ) ;
2019-10-13 20:58:13 +02:00
numbersValue = parseInt ( numbersValue . replace ( /\s/g , '' ) ) ;
2019-10-18 20:35:03 +02:00
if ( ! isNaN ( numbersValue ) && numbersValue >= 0 ) {
$ ( '.results' ) . html ( armstrongNumber ( numbersValue ) ) ;
2019-09-21 22:40:16 +02:00
}
else {
$ ( '.results' ) . html ( messageError ) ;
}
} ) ;
2019-10-23 09:33:36 +02:00
$ ( "#submitHeapAlgorithm" ) . click ( ( ) => {
2019-10-18 09:55:35 +02:00
const value = $ ( '#value' ) . val ( ) ;
2019-10-18 20:35:03 +02:00
if ( isEmptyValue ( value ) ) {
2019-10-11 21:30:05 +02:00
$ ( '.results' ) . html ( emptyMessageError ) ;
}
2019-10-18 20:35:03 +02:00
else {
2019-11-16 10:17:28 +01:00
const start = new Date ( ) ;
2019-10-18 09:55:35 +02:00
const stringPermutationsResult = stringPermutations ( value ) ;
2019-10-11 21:30:05 +02:00
let result = "" ;
for ( element in stringPermutationsResult ) {
result = result + stringPermutationsResult [ element ] + "<br>" ;
}
2019-11-16 10:17:28 +01:00
const end = new Date ( ) ;
$ ( '.results' ) . html ( ` Temps d'éxecution du script : ${ end - start } ms. <br>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-10-11 21:30:05 +02:00
}
} ) ;
2019-10-24 18:57:39 +02:00
2019-11-16 15:21:21 +01:00
if ( chemin === "/views/function-views/convertMarkdown.php" && localStorage . getItem ( 'convertedHTML' ) && localStorage . getItem ( 'texteMarkdown' ) ) {
$ ( '.results' ) . html ( localStorage . getItem ( 'convertedHTML' ) ) ;
$ ( '#texteMarkdown' ) . val ( localStorage . getItem ( 'texteMarkdown' ) ) ;
}
$ ( "#texteMarkdown" ) . bind ( "keyup change" , ( ) => {
const textMarkdown = $ ( '#texteMarkdown' ) . val ( ) ;
const convertedHTML = marked ( textMarkdown ) ;
localStorage . setItem ( "convertedHTML" , convertedHTML ) ;
localStorage . setItem ( "texteMarkdown" , textMarkdown ) ;
$ ( '.results' ) . html ( convertedHTML ) ;
} ) ;
2019-10-24 18:57:39 +02:00
/* Changement du texte accueil (exemples de fonction) */
if ( chemin === "/" || chemin === '/index.php' ) {
let index = - 1 ;
function change ( ) {
if ( index === texteFonctionChange . length - 1 ) {
index = 0 ;
}
else {
index ++ ;
}
document . getElementById ( "change" ) . innerHTML = texteFonctionChange [ index ] ;
}
setInterval ( change , 10000 ) ;
}
2019-10-11 21:30:05 +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-10-18 09:55:35 +02:00
const $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' ] = {
2019-10-18 09:55:35 +02:00
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"
2019-08-29 22:33:07 +02:00
} ;
$ ( '.datepicker' ) . datepicker ( {
2019-10-18 09:55:35 +02:00
language : 'fr' ,
2019-10-18 20:35:03 +02:00
autoclose : false ,
2019-10-18 09:55:35 +02:00
todayHighlight : true
2019-10-24 18:57:39 +02:00
} ) ;
2019-10-23 11:41:22 +02:00
2019-10-24 18:57:39 +02:00
} ) ;