From 1739942c619003cc75c6f7e5a391cfb813427e01 Mon Sep 17 00:00:00 2001 From: Divlo Date: Mon, 16 Sep 2019 18:17:02 +0200 Subject: [PATCH] Removed Switch toDo sur weatherRequest --- scripts/fonctions.js | 39 ++++++++++++++------------------------- scripts/main.js | 2 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/scripts/fonctions.js b/scripts/fonctions.js index bdddd20..4807d9e 100644 --- a/scripts/fonctions.js +++ b/scripts/fonctions.js @@ -2,37 +2,26 @@ /* Fonctions Principales */ // Requête à l'API openweathermap.org -function weatherRequest(url,toDo) { +function weatherRequest(url) { $.ajax({ url : url, dataType : "json", success: function (json) { let city = json.name; let showDateTimeValue = timeZone(json); - switch (toDo) { - case 'time': - $('.results').html("La date et l'heure de " + city + " : " + showDateTimeValue); - $("#cityName, #submitWeatherRequest").click(function() { - document.location.replace("../../views/function-views/weatherRequest.php"); - }); - break; - case 'weather': - if(city === 'Moscou') - { - $('.results').html(`🌎 Position : ${city}, RU
⏰ Date et heure : ${showDateTimeValue}
☁️ Météo : ${capitalize(json.weather[0].description)}
🌡️ Température : ${json.main.temp} °C
💧 Humidité : ${json.main.humidity}%
`); - $("#cityName, #submitWeatherRequest").click(function() { - document.location.replace("../../views/function-views/weatherRequest.php"); - }); - } - else - { - $('.results').html(`🌎 Position : ${city}, ${json.sys.country}
⏰ Date et heure : ${showDateTimeValue}
☁️ Météo : ${capitalize(json.weather[0].description)}
🌡️ Température : ${json.main.temp} °C
💧 Humidité : ${json.main.humidity}%
`); - $("#cityName, #submitWeatherRequest").click(function() { - document.location.replace("../../views/function-views/weatherRequest.php"); - }); - } - break; - default: + if(city === 'Moscou') + { + $('.results').html(`🌎 Position : ${city}, RU
⏰ Date et heure : ${showDateTimeValue}
☁️ Météo : ${capitalize(json.weather[0].description)}
🌡️ Température : ${json.main.temp} °C
💧 Humidité : ${json.main.humidity}%
`); + $("#cityName, #submitWeatherRequest").click(function() { + document.location.replace("../../views/function-views/weatherRequest.php"); + }); + } + else + { + $('.results').html(`🌎 Position : ${city}, ${json.sys.country}
⏰ Date et heure : ${showDateTimeValue}
☁️ Météo : ${capitalize(json.weather[0].description)}
🌡️ Température : ${json.main.temp} °C
💧 Humidité : ${json.main.humidity}%
`); + $("#cityName, #submitWeatherRequest").click(function() { + document.location.replace("../../views/function-views/weatherRequest.php"); + }); } }, statusCode: { diff --git a/scripts/main.js b/scripts/main.js index 254c416..795a9d4 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -22,7 +22,7 @@ $(function () { else { let url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=fr&units=metric&appid=" + config.APIkeyWeather + ""; - weatherRequest(url, 'weather'); + weatherRequest(url); } });