Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mark = '<i class="fa fa-quote-left"></i>'
- function animate(quote, name) {
- var cutQuote = quote.slice(1, -1);
- var cutName = name.slice(1, -1);
- $(".quote").animate({
- opacity: 0
- }, 500, function() {
- $(this).animate({
- opacity: 1
- }, 500);
- $(".quote").html(mark + " " + cutQuote);
- });
- $(".name").animate({
- opacity: 0
- }, 500, function() {
- $(this).animate({
- opacity: 1
- }, 500);
- $(".name").html("- " + cutName);
- });
- $('#twitter-button').attr('href', 'https://twitter.com/intent/tweet?text=' + '"' + cutQuote + '%22' + '%20' + cutName);
- }
- function getQuote() {
- var selectQuote = Math.floor(Math.random() * 3) + 1;
- switch (selectQuote) {
- case 1:
- //Chuck Norris quote
- $.getJSON("http://api.icndb.com/jokes/random", function(result) {
- var quote = JSON.stringify(result.value.joke);
- var name = '"Chuck Norris"';
- animate(quote, name);
- });
- break;
- case 2:
- //TheySaidSo Quote of the Day
- $.getJSON("http://quotes.rest/qod.json", function(result) {
- var quote = JSON.stringify(result.contents.quotes[0].quote);
- var name = JSON.stringify(result.contents.quotes[0].author);
- animate(quote, name);
- });
- break;
- case 3:
- //Ron Swanson quote
- $.getJSON("http://ron-swanson-quotes.herokuapp.com/v2/quotes", function(result) {
- var quote = JSON.stringify(result[0]);
- var name = '"Ron Swanson"';
- animate(quote, name);
- });
- break;
- }
- }
- $(document).ready(function() {
- getQuote();
- $(".button").click(function() {
- getQuote();
- });
- });
- /* Different API:s to try later
- http://quotes.stormconsultancy.co.uk/random.json
- https://favqs.com/api/qotd
- */
Add Comment
Please, Sign In to add comment