123

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.

            
              <section id="main-container">
  <div id="text-and-button">
    <div id="headers-only">
      <h1>Random Quotes Rewritten</h1>
    <p id="intro">These are some quotes from the forismatic api. You can keep clicking for new quotes.   I hope you enjoy them!</p>
    </div>
    <button id="quote-button">New Quote</button>
  </div>
  <div id="quote-container">
    <p id="quote-container-quote">Hello</p>
    <p id="quote-container-author">Franklin</p>
    <a id="twitter-link" href="#"><button id="twitter-button">Share on Twitter  <i class="fa fa-twitter"></i></button></a>
  </div>
</section>
            
          
!
            
              body {
  /*background-image: url("http://jordanholt.me/images/airport.jpg"); */
  font-size: 18px;
  background-color: #27ae60;
}

a {
  text-decoration: none;
}

#text-and-button {
  background-color: rgba(255,255,255,.8);
  border: 2px solid #49b9de;
  border-radius: 60px;
  padding-left: 10px;
  padding-right: 10px;
  max-width: 50%;
  margin-left: auto;
  margin-right: auto;
}

#main-container {
  
}

#quote-button {
  margin-top: 40px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 40px;
  display: block;
  min-width: 250px;
  min-height: 65px;
  border-radius: 45px;
  box-shadow: -5px 4px 2px rgba(25,25,25,.5);
  font-family: serif;
  font-size: 25px;
  background-color: rgb(225,225,225);
}

#quote-button:hover {
  box-shadow: -5px 4px 2px rgba(0,0,0,.8);
  border: 2px solid rgb(225,225,225,.9); 
}

#twitter-button {
  margin-top: 30px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 30px;
  display: block;
  min-width: 150px;
  min-height: 50px;
  border-radius: 45px;
  box-shadow: -5px 4px 2px rgba(25,25,25,.5);
  font-family: serif;
  font-size: 20px;
  background-color: rgb(225,225,225);
}

#twitter-button:hover {
  box-shadow: -5px 4px 2px rgba(0,0,0,.8);
  border: 2px solid rgb(225,225,225,.9); 
}

#intro {
  text-align: center;
}

h1 {
  text-align: center;
}

#quote-container {
  max-width: 65%;
  border: 2px solid rgba(222,110,73,.8);
  border-radius: 45px;
  background-color: rgba(255,255,255,.8);
  padding-left: 10px;
  padding-right: 10px;
  margin-left: auto;
  margin-right: auto;
  margin-top: 40px;
  display: none;
  font-family: sans-serif;
  text-align: center;
}

.quote-container-quote {
  font-size: 30px;
}

@media screen and (max-width: 700px) {
  #text-and-button {
    max-width: 80%;
  }
  
  #quote-button {
    max-width: 250px;
  }
}
            
          
!
            
              function addQuote(data){              //Callback function from the script
  var quote = "";                     //Appends the JSONP data to the page
  quote += '<p class="quote-string" id="quote-container-quote">"';
  quote += data["quoteText"];
  quote += '"</p>';
  
  var author = "";
  if (data["quoteAuthor"] != "") {          //Some of the quotes don't have authors.
    author += '<p class="quote-author" id="quote-container-author">"';  //This block prevents empty quotes showing.
    author += data["quoteAuthor"];
    author += '"</p>';
  } else {
    author = '<p class="quote-author" id="quote-container-author"></p>';
  }
  $("#quote-container-quote").replaceWith(quote);
  $("#quote-container-author").replaceWith(author);
  var plainQuote = data["quoteText"];
  var convertQuote = encodeURIComponent(plainQuote);
  var convertAuthor = encodeURIComponent(data["quoteAuthor"]);
  var tweet = "https://twitter.com/intent/tweet/?text=" + convertQuote + "&via=" + convertAuthor; 
  $("#twitter-link").attr("href", tweet);
  $("#twitter-link").attr("target", "_blank")
}

function requestJSONP(url) {
  var script = document.createElement('script');
  script.src = url;
  document.getElementsByTagName('head')[0].appendChild(script);
  script.onload = function() {
    this.remove();
  }
}

$("#quote-button").click(function() {
  $("#quote-container").hide("slow");
  var url = "https://api.forismatic.com/api/1.0/?method=getQuote&key=&format=jsonp&lang=en&jsonp=addQuote&nocache=" + (new Date()).getTime();
  requestJSONP(url);
  $("#quote-container").show("slow");
  
  //alert (url);
}); 

/*$("#quote-button").click(function() {
  $.ajax({
    url: "https://api.forismatic.com/api/1.0/",
    jsonp: "jsonp",
    dataType: "jsonp",
    data: {
      method: "getQuote",
      lang: "en",
      format: "jsonp"
    },
    success: addQuote(data);
  });
});
  */

            
          
!
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.

Console