cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <body>
  <div class="container">
    <h2 class="quoteText" id="quoteText"> Loading Quote...
  </h2>
    <p class="quoteAuthor">- Unknown</p>
    <button class="button" id="newQuote"> New Quote</button>
    <a href="" target="_blank" class="button twitter-share-button"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></a>
  </div>
  <div class="footer">Inspired by FCC, coded by Alexandre Robin</div>
</body>
            
          
!
            
              body{
  background-color:#0097A7;
  padding-top:10%;
}
.container{
  background-color:white;
  color:#0097A7;
  text-align:justify;
  margin:auto;
  padding:50px;
  width:50%;
  display:block;
  border:none;
  border-radius:5px;
}
.quoteAuthor{
  text-align:right;
  font-style:italic;
}
.twitter-share-button{
  float:right;
  color:#fff;
}
a {
  color:#fff;
}
a:hover {
  opacity:0.8;
  color:white;
}
.button {
      height:38px;
      border:none;
      border-radius:3px;
      color:#fff;
      background-color:#0097A7;
      outline:none;
      font-size:0.85em;
      padding: 8px 18px 6px 18px;
      margin-top:30px;
      opacity:1;
      cursor:pointer;
}
.button:hover{
  opacity:0.8;
}
.footer{
  text-align:center;
  font-size:0.8em;
  margin-top:10px;
  padding-bottom:10%;
  color:#006064;
}

            
          
!
            
              $(function() {

  // Event listener : onClick New Quote button
  $("#newQuote").click(function() {
    getNewQuote();
  });
  /*$(".twitter-share-button").click(function() {
    $(".twitter-share-button").html("<a href='https://twitter.com/' target='_blank'><a>");
  })*/

  // Main function  
  function getNewQuote() {

    //I had an issue with the cache and the API, so this is a workaround found on StackOverflow : I set a timestamp value with Date().getTime(). This allow me to have a new http request every time I launch getNewQuote(). A bit slower, but it works :) 
    var timestamp = new Date().getTime();
    var apiURL = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&timestamp=" + timestamp;

    // Get the JSON data from API with the url witch has been built before and push it to the HTML
    $.getJSON(apiURL, function(json) {
      var content = json[0].content.replace(/<\/?p[^>]*>/g, "");
      $(".quoteText").html(content);
      var author = json[0].title === "" ? "Unknown" : json[0].title;
      $(".quoteAuthor").html("- " + author);
      var textForLink = encodeURIComponent(content);
      var link = "https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=" + textForLink;
      $(".twitter-share-button").attr("href", link);

    });

  };
  getNewQuote();
});
            
          
!
999px
Loading ..................

Console