-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote.js
50 lines (42 loc) · 1.36 KB
/
quote.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
44
45
46
47
48
49
50
var currentQuote = " ";
var currentAuthor = " ";
function getQuote() {
$(".quotes").fadeOut(450);
$.get('/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1' ,function(data, status) {
currentQuote= data.message;
$('.quotes').fadeIn(450);
$("#quote-text").html(currentQuote);
});
}
$(document).ready(function() {
getQuote();
$("#new-quote").on('click', getQuote);
$('.button').mouseenter(function() {
$(this).fadeTo('fast', 0.25);
})
$('.button').mouseleave(function() {
$(this).fadeTo('fast', 1);
})
$("#tweet").on('click', function() {
window.open('https://twitter.com/intent/tweet?hashtags=randomquotes&text=' + currentQuote);
});
});
$('#new-quote').on('click', function(e) {
e.preventDefault();
$.ajax( {
url: '/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
success: function(data) {
var post = data.shift(); // The data is an array of posts. Grab the first one.
$('#quote-title').text(post.title);
$('#text').html(post.content);
// If the Source is available, use it. Otherwise hide it.
if (typeof post.custom_meta !== 'undefined' && typeof post.custom_meta.Source !== 'undefined') {
$('#author').html('Source:' + post.custom_meta.Source);
} else {
$('#author').text('');
}
},
cache: false
});
});
});