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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <head>
  <link href="https://fonts.googleapis.com/css?family=Raleway:300i,500" rel="stylesheet">
	<title>Random Quote Generator</title>
</head>
<body>
  <div class="container">
   
    <div id="changeQuote" class="container">
  <!--     <div class=""> -->
  <!--       <div class=""> -->
          <div id="quoteSpace"></div>
  <!--       </div> -->
  <!--     </div>     -->
    </div>
  
<!-- 	<button class="btn" id="changeQuote">New Quote</button> -->
  <div class="container">
      <a id="tweet" class="btn btn-social-icon btn-twitter tweet pull-right">
        <span class="fa fa-twitter fa-3x"></span>
      </a>
  </div>
 </div>
  
	

  
</body>

              
            
!

CSS

              
                body{
  font-family: 'Raleway', sans-serif;
}

#changeQuote {
  background:  #f0f0f5;
  color: #4d4d4d;
  transition: background 0.2s ease, color 0.2s ease;
  margin-top: 5%;
}

#changeQuote:hover {
  background: #b3b3cc;
  color: black;
}

              
            
!

JS

              
                var quoteData;

window.onLoad = newQuote();

document.getElementById("changeQuote").addEventListener("click", newQuote, false);
document.getElementById("tweet").addEventListener("click", tweetIt, false);



function tweetIt(){
  if(quoteData == undefined){
    //do nothing, no quote to tweet
  } else {
    var tweetURL = "https://twitter.com/share?text="  + quoteData.quoteText + '  --' + quoteData.quoteAuthor + "." + "&url=" + "https://codepen.io/quadrumane/pen/XjrKOZ";
    window.open(tweetURL);
  }
}


function cacheBuster(){
  return String(Math.random() * 10000)
}

function newQuote(){
  //cache buster workaround to not get cached response from crossorigin.me and generate new responses each time.
  var url = 'https://crossorigin.me/https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en&cache=' + cacheBuster();
  var request = new XMLHttpRequest();

  request.open('GET', url , true);

  request.onload = function() {
    if (request.status >= 200 && request.status < 400) {
      //Successful GET
      quoteData = JSON.parse(request.responseText);
      document.getElementById("quoteSpace").innerHTML = "<h1>" + quoteData.quoteText + "</h1><h3><em>    — " + quoteData.quoteAuthor + "</em></h3>";
    } else {
      //Target Server reached, but error returned
      console.log("Target server reached, but error returned")
    }
  };


  request.onerror = function() {
    //There was a connection error of some sort
    console.log("Some kind of connection error");
  };

  request.send();
};
              
            
!
999px

Console