-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquote.js
More file actions
57 lines (46 loc) · 1.46 KB
/
quote.js
File metadata and controls
57 lines (46 loc) · 1.46 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function randomQuote() {
$.ajax({
url: "https://api.forismatic.com/api/1.0/",
jsonp: "jsonp",
dataType: "jsonp",
data: {
method: "getQuote",
lang: "en",
format: "jsonp"
},
success: function(quote) {
$('#Quote').html('“'+quote.quoteText+'”')
$('#author').html("-"+quote.quoteAuthor)
tweetQuote(quote.quoteText, quote.quoteAuthor, "quotes, hacktoberfest")
}
});
}
function tweetQuote (quote, author, hashtags){
// Build a twitterMessage
var twitterMessage = '"' + quote + '" - ' + author;
var elem = document.querySelector('.twitter-share-button');
// Remove the twitter share button, if it already exists
if (elem !== null) {
elem.parentNode.removeChild(elem);
}
// Build a new twitter link
var link = document.createElement('a');
link.setAttribute('href', 'https://twitter.com/intent/tweet');
link.setAttribute('class', 'twitter-share-button');
link.setAttribute('id', 'tweet');
link.setAttribute('data-text', twitterMessage);
link.setAttribute('data-size', 'large');
link.setAttribute('data-hashtags', hashtags);
// Append the new twitter link to the target
tweetDiv = document.getElementById('tweet')
tweetDiv.appendChild(link);
// Load it
twttr.widgets.load();
}
//Click on the button to generate another random quote
$(document).ready(function(){
randomQuote();
$('#random').on('click', function() {
randomQuote();
});
});