From cfdfeb142c3522b9538254062e7316f877699f9c Mon Sep 17 00:00:00 2001 From: Divlo Date: Sat, 28 Dec 2019 00:16:13 +0100 Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20de=20tweet=20la=20citation?= =?UTF-8?q?=20dans=20randomQuote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/executeFunction.js | 21 +++++++++++++-------- scripts/fonctions_principales.js | 8 +++----- views/function-views/randomQuote.php | 8 ++++++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/scripts/executeFunction.js b/scripts/executeFunction.js index 7aad6a6..b0bbdd8 100644 --- a/scripts/executeFunction.js +++ b/scripts/executeFunction.js @@ -85,16 +85,21 @@ $(function () { } }); - let randomQuoteClicked; - $("#submitRandomQuote").click(() => { - randomQuoteClicked = true; - $('.resultsRandomQuote').html(getRandomQuote()); - }); - // Affichage d'une citation au chargement de la page - if (randomQuoteClicked != true && chemin === '/views/function-views/randomQuote.php') { - $('.resultsRandomQuote').html(getRandomQuote()); + + function showQuote() { + const randomQuote = getRandomQuote(); + const quote = randomQuote.quote; + const source = randomQuote.source; + $('.resultsRandomQuote').html(`

" ${quote} "

- ${source}

`); + $('#twitterLink').attr('href', `https://twitter.com/intent/tweet?text="${quote}" - ${source}&via=Divlo_FR&hashtags=citation,FunctionProject&url=https://function.divlo.fr/views/function-views/randomQuote.php`); } + $("#submitRandomQuote").click(() => { + showQuote(); + }); + // Affichage d'une citation au chargement de la page + showQuote(); + $("#submitConvertCurrency").click(() => { let value = $('#value').val(); const currencyOfTheValue = $("#currencyOfTheValue option:selected").val(); diff --git a/scripts/fonctions_principales.js b/scripts/fonctions_principales.js index d9c47fe..751aec2 100644 --- a/scripts/fonctions_principales.js +++ b/scripts/fonctions_principales.js @@ -185,13 +185,11 @@ function filterStudents(filteredLetter, students) * @description Génère aléatoirement une citation ou un proverbe. * @requires {@link variables.js: quotes} * @requires {@link fonctions_principales.js: randomNumber} - * @returns {string} - une citation au hasard à partir de la constante 'quotes' dans variables.js - * @example getRandomQuote() → " Ne fais jamais rien contre ta conscience, même si l'Etat te le demande. "

- Albert Einstein + * @returns {object} - une citation au hasard à partir de la constante 'quotes' dans variables.js + * @example getRandomQuote() → { quote: "Ne fais jamais rien contre ta conscience, même si l'Etat te le demande.", source: "Albert Einstein" } */ function getRandomQuote() { - const randomNbr = randomNumber(0, (quotes.length - 1)); - const randomQuotes = quotes[randomNbr]; - return '" ' + randomQuotes["quote"] + ' "

- ' + randomQuotes["source"]; + return quotes[randomNumber(0, (quotes.length - 1))]; } /** diff --git a/views/function-views/randomQuote.php b/views/function-views/randomQuote.php index 67434fa..9a8453d 100644 --- a/views/function-views/randomQuote.php +++ b/views/function-views/randomQuote.php @@ -23,8 +23,12 @@ -

-

+
+

+
+
+ Twitter +