css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container-fluid">
  <h1>Random Quote Lobster</h1>
  <p>v1.1 by James Payne</p>

  <a href="#" data-toggle="tooltip" data-placement="top" title="Click me for a new quote"> <img id="lobster" src="https://jamespayne.net/img/lobster.png" alt="lobster" /></a>
  <div id="quote">
  </div>
  <div id="social">
    <a id="twitter-share" data-toggle="tooltip" class="twitter-share-button" target="_blank" alt="tweet">
    <i class="fa fa-twitter fa-2x"></i>
  </a>
  </div>
</div>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Lobster');
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:700');

html {
  height: 100%;
}

body {
  height: 100%;
  background: #21786A;
  color: white;
  text-align: center;
  background: -webkit-radial-gradient(#21786A, black);
  background: -o-radial-gradient(#21786A, black);
  background: -moz-radial-gradient(#21786A, black);
  background: radial-gradient(#21786A, black);
  background-repeat: no-repeat;
  margin: 15px;
}

h1 {
  text-align: center;
  color: white;
  font-family: 'Lobster', cursive;
  font-size: 70px;
  text-shadow: 4px 4px #000000;
}

.tooltip-inner, .tooltip.top > .tooltip-arrow {
    margin-bottom: 40px;
}

#quote {
  height: 100%;
  color: white;
  font-size: 25px;
  font-family: 'Open Sans Condensed', sans-serif;
  margin-bottom: 30px;
}

#quote {
  margin-top: 30px;
}

#quote a {
  color: white;
}

#social {
  text-align: center;
}

#twitter-share {
  display: inline-block;
  width: 40px;
  height: 40px;
  color: white;
  background: blue;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px; 
  border-radius: 20px;
}

#twitter-share i{
  line-height: 40px;
}
            
          
!
            
              function getQuote() {

  var quotetext = "";
  var author = "";
  var quote = "";
  var wikiauthor = "";
  var quotelength;

  if (location.protocol === 'https:') {
    $("#lobster").attr('src', 'https://jamespayne.net/img/sad-lobster.png');
    $("#quote").html('<p>Sorry! This app only works with a http address not https. Please open this same location with http at the beginning of the url not https!</p>');

  } else {
    $.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?')
      .done(function(json) {
        quote += json.quoteText.trim();
        author += json.quoteAuthor; 
        wikiauthor = author.replace(/ /, '+');
        console.log(quote);

        if (author.length === 0) {
          author = 'Unknown';
          quotetext = '"' + quote + '" - ' + author;
          $("#quote").html('<p id="quote-text">' + quotetext + '</p>');
        } else {
          quotetext = '"' + quote + '" - ' + author;
          $("#quote").html('<p id="quote-text">' + quotetext + '</p>');
        }

        // Set up and display the twitter button if the quote is short enough to tweet.

        quotelength = quotetext.length + author.length + '- '.length;

        if (quotelength <= 140) {
          var twitterurl = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(quotetext);
          $('#twitter-share').attr("href", twitterurl);
          $('#social').show();
        }

        // Query wikipedia and see if there is an article about the author and provide a link if possible. This needs some error handling as there may not be a page or the author is unknown.

        $.getJSON('https://en.wikipedia.org//w/api.php?action=query&origin=*&format=json&prop=info&meta=&titles=' + wikiauthor + '&redirects=1&formatversion=latest&inprop=url', function(json) {
          
          // Check to see if there is an article and add an info icon to the end of the quote if there is.
          
          if (!json.query.pages[0].hasOwnProperty('missing')){
            $("#quote-text").append('  <span><a href="' + json.query.pages[0].fullurl + '" target="_blank">' + '<i class="fa fa-info-circle" aria-hidden="true"></i></a></span>');
          }

        });

      })
      .fail(function() {
        $("#lobster").attr('src', 'https://jamespayne.net/img/sad-lobster.png');
        $('#quote').html("Uh Ohhh... Something went wrong!");
      });
  }

}

$(document).ready(function() {
  
  $("#social").hide();
  $("#quote").html();
  
  $('[data-toggle="tooltip"]').tooltip();

  getQuote();

  // Click the lobster for another quote after the first quote has been loaded.

  $("#lobster").on("click", function() {
    getQuote();
  });

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console