JacobHsu
10/14/2016 - 1:29 AM

Random Quote Machine

Random Quote Machine

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
@import url(https://fonts.googleapis.com/css?family=Raleway:400,500);
* {
  margin: 0;
  padding: 0;
  list-style: none;
  vertical-align: baseline;
}
div {
  position:relative;
  z-index: 2;
}

body {
  background-color: #333;
  color: #333;
  font-family: 'Raleway', sans-serif;
  font-weight:400;
}
.footer {
  width:450px;
  text-align:center;
  display:block;
  margin:15px auto 30px auto;
  font-size:0.8em;
  color:#fff;
  a {
    font-weight:500;
    text-decoration:none;
    color:#fff;
  }
}
.quote-box {
  border-radius:3px;
  position:relative;
  margin:8% auto auto auto;
  width:450px;
  padding:40px 50px;
  display:table;
  background-color:#fff;
  .quote-text {
    i{
      font-size:1.0em;
      margin-right: 0.4em;
    }
    text-align:center;
    width:450px;
    height:auto;
    clear:both;
    font-weight:500;
    font-size:1.75em;
  }
  .quote-author {
    width:450px;
    height:auto;
    clear:both;
    padding-top:20px;
    font-size:1em; 
    text-align:right;
  }
  .buttons {
    width:450px;
    margin:auto;
    display:block;
    .button {
      height:38px;
      border:none;
      border-radius:3px;
      color:#fff;
      background-color:#333;
      outline:none;
      font-size:0.85em;
      padding: 8px 18px 6px 18px;
      margin-top:30px;
      opacity:1;
      cursor:pointer;
      &:hover {
        opacity:0.9;
      }
      &#tweet-quote, &#tumblr-quote {
        float:left;
        padding:0px;
        padding-top:8px;
        text-align:center;
        font-size:1.2em;
        margin-right:5px;
        height:30px;
        width:40px;
      }
      &#new-quote {
        float:right;
      }
    }
  }
  
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
/*
  Code by Gabriel Nunes
*/

function inIframe () { try { return window.self !== window.top; } catch (e) { return true; } }

var currentQuote = '', currentAuthor = '';
function openURL(url){
  window.open(url, 'Share', 'width=550, height=400, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=0');
}
function getQuote() {
  $.ajax({
    headers: {
      "X-Mashape-Key": "OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V",
      Accept: "application/json",
      "Content-Type": "application/x-www-form-urlencoded"
    },
    url: 'https://andruxnet-random-famous-quotes.p.mashape.com/cat=',
    success: function(response) {
      var r = JSON.parse(response);
      currentQuote = r.quote;
      currentAuthor = r.author;
      if(inIframe())
      {
        $('#tweet-quote').attr('href', 'https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + currentQuote + '" ' + currentAuthor));
        $('#tumblr-quote').attr('href', 'https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption='+encodeURIComponent(currentAuthor)+'&content=' + encodeURIComponent(currentQuote));
      }
      $(".quote-text").animate({
          opacity: 0
        }, 500,
        function() {
          $(this).animate({
            opacity: 1
          }, 500);
          $('#text').text(r.quote);
        });

      $(".quote-author").animate({
          opacity: 0
        }, 500,
        function() {
          $(this).animate({
            opacity: 1
          }, 500);
          $('#author').html(r.author);
        });

      var randomColor = '#'+Math.floor(Math.random()*16777215).toString(16);
      $("html body").animate({
        backgroundColor: randomColor,
        color: randomColor
      }, 1000);
      $(".button").animate({
        backgroundColor: randomColor
      }, 1000);
    }
  });
}
$(document).ready(function() {
  getQuote();
  $('#new-quote').on('click', getQuote);
  $('#tweet-quote').on('click', function() {
    if(!inIframe()) {
      openURL('https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + currentQuote + '" ' + currentAuthor));
    }
  });
  $('#tumblr-quote').on('click', function() {
    if(!inIframe()) {
      openURL('https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption='+encodeURIComponent(currentAuthor)+'&content=' + encodeURIComponent(currentQuote));
    }
  });
});

Random Quote Machine

Show random quotes using "Random Famous Quotes" API (https://www.mashape.com/andruxnet/random-famous-quotes)

Forked from Gabriel Nunes's Pen Random Quote Machine.

A Pen by JacobHsu on CodePen.

License.


<div class="quote-box">
  <div class="quote-text">
    <i class="fa fa-quote-left"> </i><span id="text"></span>
  </div>
  <div class="quote-author">
    - <span id="author"></span>
  </div>
  <div class="buttons">
    <a class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
      <i class="fa fa-twitter"></i>
    </a>
     <a class="button" id="tumblr-quote" title="Post this quote on tumblr!" target="_blank">
      <i class="fa fa-tumblr"></i>
    </a>
    <button class="button" id="new-quote">New quote</button>
  </div>
</div>