Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
      ****       ***         ***       ***         ***        ****
      *  Copyright (C) 2016 Tyler Moeller. All rights reserved.  *
      *  All trademarks, product names, and logos on this site   *
      *  are the property of their respective owners.            *
      ****       ***         ***       ***         ***        ****

    Assignment Details:
      - Developed for the freeCodeCamp zipline project: Zipline: Build a Random Quote Machine
      - Details: http://freecodecamp.com/challenges/zipline-build-a-random-quote-machine

    Requirements for this assignment:
      - Build a random quote machine that emulates this: http://codepen.io/AdventureBear/full/vEoVMw.
      - Don't look at the source code of the project you are emulating
      - Users are able to click a button to get a new random quote
      - Bonus: Users are able to click a button to tweet the quote

    Assignment Completed. v1.0 9/24/2015:
      - Responsive deisgn using JavaScript, jQuery, HTML5, with Materialize + FontAwesome CSS libraries.
      - Random quote given on page load
      - Button to get a new random quote in the navbar and main page
      - Button to tweet quote with transition effects and tooltips to help show it's a button
          - twitter js widget to present modal dialog instead of separate tab/page in browser
          - Quotes are filtered so they can all fit whithin 140-char tweet limit
          - Classes, ids, and icons named carefully to prevent adblock issues
      - Button to view author on Wikipedia with transition effects and tooltips to help show it's a button
    -->
<main>
  <div class="container center">
    <div class="row">
      <h3 class="title">Random Quote Machine</h3>
    </div>
    <div class="row main-content center">
      <div class="col s4 offset-s4">
        <div class="preloader-wrapper big active spinner" id="spinner">
          <div class="spinner-layer spinner-blue-only">
            <div class="circle-clipper left">
              <div class="circle"></div>
            </div>
            <div class="gap-patch">
              <div class="circle"></div>
            </div>
            <div class="circle-clipper right">
              <div class="circle"></div>
            </div>
          </div>
        </div>
      </div>
      <div class="col s8 offset-s2" id="content">
        <div class="flow-text">
          <p id="quote"></p>
          <p><i id="author"></i></p>
        </div>
        <div class="row">
          <div class="tooltipped col s3 offset-s3" data-position="bottom" data-tooltip="View the author on Wikipedia!">
            <a id="wikiLink" target="_blank" rel="noopener noreferrer">
              <img class="authorWiki" src="https://tylermoeller.github.io/fccfe/random-quote-machine/img/logo-wiki.png">
            </a>
          </div>
          <div class="tooltipped col s3" data-position="bottom" data-tooltip="Tweet this quote!">
            <a id="tweetLink" target="_blank" rel="noopener noreferrer">
              <img class="shareQuote" src="https://tylermoeller.github.io/fccfe/random-quote-machine/img/logo-twit.png">
            </a>
          </div>
        </div>
      </div>
    </div>
    <a class="new-quote-btn btn blue-grey lighten-5 black-text" onclick="getQuote()">Generate another quote!</a>
  </div>
</main>
<footer class="page-footer grey darken-4">
  <div class="container center">
    <div class="row grey-text">
      <p class="footer-text">Copyright &copy;
        <script>
          document.write(new Date().getFullYear());
        </script>
        Tyler Moeller. All rights reserved. Quotes retrieved from
        <a href="http://forismatic.com/en/api/" target="_blank" rel="noopener noreferrer">Forismatic</a>. Developed for the freeCodeCamp Front-end Development Challenge:
        <a href="http://www.freecodecamp.com/challenges/build-a-random-quote-machine" target="_blank" rel="noopener noreferrer">
              Build a Random Quote Machine</a>.
      </p>
    </div>
    <div class="footer-logos row">
      <a href="https://twitter.com/Tyler_Moeller" target="_blank" rel="noopener noreferrer"><i class="fa fa-twitter"></i></a>
      <a href="https://www.linkedin.com/in/tylermoeller" target="_blank" rel="noopener noreferrer"><i class="fa fa-linkedin"></i></a>
      <a href="https://github.com/TylerMoeller" target="_blank" rel="noopener noreferrer"><i class="fa fa-github"></i></a>
      <a href="http://freecodecamp.com/tylermoeller" target="_blank" rel="noopener noreferrer"><i class="fa fa-fire"></i></a>
      <a href="http://codepen.io/TylerMoeller/" target="_blank" rel="noopener noreferrer"><i class="fa fa-codepen"></i></a>
      <a href="https://tylermoeller.net" target="_blank" rel="noopener noreferrer"><i class="fa fa-wordpress"></i></a>
    </div>
  </div>
</footer>
<script src="//tylermoeller.github.io/fccfe/random-quote-machine/js/jquery-2.2.1.min.js"></script>
<script src="//tylermoeller.github.io/fccfe/random-quote-machine/js/materialize.min.js"></script>
<script src="//tylermoeller.github.io/fccfe/random-quote-machine/js/widgets.js"></script>
              
            
!

CSS

              
                body {
  background-image: url(https://tylermoeller.github.io/fccfe/random-quote-machine/img/wenge.jpg);
  color: white;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: 'Roboto', sans-serif;
}

.container {
  max-width: 768px;
  min-width: 270px;
}

.title {
  margin-top: 5%;
}

@media (max-width: 600px) {
  .title {
    margin-top: .5em;
  }
}

.main-content {
  font-size: 1.6em;
  min-height: 14em;
}

#spinner {
  margin: 2em auto;
  display: none;
}

.authorWiki, .shareQuote {
  border-radius: 12.5%;
  font-size: .6em;
  height: 3em;
  margin-top: 1em;
}

.authorWiki:hover, .shareQuote:hover {
  opacity: .8;
  box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.new-quote-btn, .new-quote-btn:hover {
  border: 1px solid #bdbdbd;
  box-shadow: 0 5px 0 #bdbdbd;
  font-weight: 500;
  margin-bottom: 5em;
  padding: 0 1em;
  user-select: none;
}

.new-quote-btn:active, .new-quote-btn:focus {
  border-style: none;
  box-shadow: 0 0 0 1px #bdbdbd inset,
    0 0 0 1px rgba(255, 255, 255, 0.15) inset,
    0 1px 3px 1px rgba(0, 0, 0, .1);
  position: relative;
  top: 4px;
}

/* footer formatting */
main {
  flex: 1 0 auto;
}

.footer-text {
  font-size: 1em;
  margin: 0;
}

.footer-logos i {
  border: 1px solid #646464;
  border: 1px solid rgba(100, 100, 100, .3);
  border-radius: 25%;
  color: #646464;
  font-size: 1.1em;
  margin-right: .25em;
  padding: .4em;
}
              
            
!

JS

              
                const toggleSpinner = () => $("#content, #spinner").toggle();

function quoteHandler(data) {
  const quoteText = data.quoteText.trim(),
    quoteAuthor = `~ ${data.quoteAuthor.trim() || "Anonymous"}`,
    quoteMachineUrl = document.referrer.split("?")[0],
    tweetText = encodeURIComponent(`${quoteText} ${quoteAuthor} ${quoteMachineUrl}`),
    tweetUrl = `https://\ttwitter.com/intent/tweet?text=${tweetText}`, // '\t' bypasses adblock
    wikiUrl = `https://en.wikipedia.org/wiki/${quoteAuthor.replace(/\s/g, "_").replace("~", "")}`;

  // 280 character text limit, twitter shortens urls to 23 characters
  // if quote + url is longer than allowed, get a new quote
  const tweetLength = (tweetText.length - quoteMachineUrl.length) + 23;
  if (tweetLength > 280) {
    getQuote();
    return;
  }

  // Populate the HTML. setTimeout throttles requests to one quote per second
  setTimeout(() => {
    $("#quote").text(quoteText);
    $("#author").text(quoteAuthor);
    $("#tweetLink").attr("href", tweetUrl);
    $("#wikiLink").attr("href", wikiUrl);
    $(".tooltipped")
      .tooltip({ delay: 50 })
      .click(() => $(".tooltipped").blur());
    toggleSpinner();
  }, 1000);
}

function error(err) {
  $("#author").html("~ Random Quote Machine");
  $("#quote").html(`Error: ${err.status} (${err.statusText}). Please try again later.`);
  toggleSpinner();
}

// Get a quote from the Forismatic API
function getQuote() {
  toggleSpinner();

  $.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?")
    .done(quoteHandler)
    .fail(error);

  $(".new-quote-btn").blur();
}

$(getQuote);

              
            
!
999px

Console