Guest User

Untitled

a guest
Apr 18th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   var mark = '<i class="fa fa-quote-left"></i>'
  2.  
  3.   function animate(quote, name) {
  4.     var cutQuote = quote.slice(1, -1);
  5.     var cutName = name.slice(1, -1);
  6.     $(".quote").animate({
  7.       opacity: 0
  8.     }, 500, function() {
  9.       $(this).animate({
  10.         opacity: 1
  11.       }, 500);
  12.       $(".quote").html(mark + " " + cutQuote);
  13.     });
  14.  
  15.     $(".name").animate({
  16.       opacity: 0
  17.     }, 500, function() {
  18.       $(this).animate({
  19.         opacity: 1
  20.       }, 500);
  21.       $(".name").html("- " + cutName);
  22.     });
  23.     $('#twitter-button').attr('href', 'https://twitter.com/intent/tweet?text=' + '"' + cutQuote + '%22' + '%20' + cutName);
  24.   }
  25.  
  26.   function getQuote() {
  27.     var selectQuote = Math.floor(Math.random() * 3) + 1;
  28.  
  29.     switch (selectQuote) {
  30.       case 1:
  31.         //Chuck Norris quote
  32.         $.getJSON("http://api.icndb.com/jokes/random", function(result) {
  33.           var quote = JSON.stringify(result.value.joke);
  34.           var name = '"Chuck Norris"';
  35.           animate(quote, name);
  36.         });
  37.         break;
  38.  
  39.       case 2:
  40.         //TheySaidSo Quote of the Day
  41.         $.getJSON("http://quotes.rest/qod.json", function(result) {
  42.           var quote = JSON.stringify(result.contents.quotes[0].quote);
  43.           var name = JSON.stringify(result.contents.quotes[0].author);
  44.           animate(quote, name);
  45.         });
  46.         break;
  47.  
  48.       case 3:
  49.         //Ron Swanson quote
  50.         $.getJSON("http://ron-swanson-quotes.herokuapp.com/v2/quotes", function(result) {
  51.           var quote = JSON.stringify(result[0]);
  52.           var name = '"Ron Swanson"';
  53.           animate(quote, name);
  54.         });
  55.         break;
  56.     }
  57.   }
  58.  
  59.   $(document).ready(function() {
  60.     getQuote();
  61.     $(".button").click(function() {
  62.       getQuote();
  63.     });
  64.   });
  65.  
  66.   /* Different API:s to try later
  67.   http://quotes.stormconsultancy.co.uk/random.json
  68.   https://favqs.com/api/qotd
  69.   */
Add Comment
Please, Sign In to add comment