-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
43 lines (38 loc) · 1.22 KB
/
client.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
32
33
34
35
36
37
38
39
40
41
42
43
var url = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=";
$(function() {
$.ajaxSetup({ cache: false });
tweetButtonInit();
getQuote();
$("#quotebutton").click(function() {
getQuote();
});
});
var getQuote = function() {
$.getJSON(url, function(data) {
$("#quotetext").html(data[0].content);
if (data[0].title === '') data[0].title = "Unknown";
$(".authortext").html('Author: ' + data[0].title);
changeTweet()
});
};
var changeTweet = function() {
var tweetText = $("#quotetext").text() + $(".authortext").text();
$("#tweet").html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="blank" data-size="large" data-text="' + tweetText + '" data-count="none">Tweet</a>');
twttr.widgets.load();
}
var tweetButtonInit = function() {
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
}