-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (29 loc) · 1.08 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** refreshQuote does an ajax call of a Trump Quotes API
also callsback updateTweet to send the quote to twitter */
function refreshQuote() {
console.warn('Call refreshQuote.');
$.ajax({
url: 'https://api.whatdoestrumpthink.com/api/v1/quotes/random',
success: (a) => {
console.warn('API success');
$('#quote').hide().html(a.message).fadeIn(2000);
console.warn('update tweet by calling back updateTweet');
updateTweet();
},
cache: false,
});
}
/** Callback function for setting the quote to be tweeted */
function updateTweet() {
const quoteText = $('#quote').text();
const titleText = $('#title').text();
console.warn('Quote text: ', quoteText);
$('#tweet').attr('href', 'https://twitter.com/intent/tweet?text=' + quoteText + ' -- ' + titleText);
console.warn('Link was updated to: ', $('#tweet').attr('href'));
}
/** on document ready, call refreshQuote and set button to refreshQuote
on click */
$(document).ready(() => {
refreshQuote();
$('#getMessage').click(refreshQuote);
});