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.

            
              <head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <div class="container">
    <div id="quoteBox">
      <h1 id="quote"><i class="fa fa-refresh fa-lg fa-spin"></i></h1>
      <h4 class="text-right" id="author"></h4>
    </div>
    <div id="linksRow">
      <div class="row">
        <div class="col-sm-6" id="button">
          <div class="btn btn-block btn-secondary twitter" title="Twat this!">
            <i class="fa fa-twitter fa-lg"></i></div>
        </div>
        <div class="col-sm-6" id="button">
          <div class="btn btn-block btn-secondary generate" title="Get new quote!">
            <i class="fa fa-refresh fa-lg "></i></div>
        </div>
      </div>
    </div>
  </div>

  <p class="bottom text-center">Designed by Merryl using <a href="https://forismatic.com/en/api/" target="_blank">Forismatic</a></p>
</body>
            
          
!
            
              body {
  overflow: scroll;
  background-image: url("https://www.lifeofpix.com/wp-content/uploads/2015/11/Life-of-Pix-free-stock-photos-trees-frozen-snow-grzegorzmleczev.jpeg");
}


/*Quote Box Container*/

.container {
  /*position: fixed;*/
  background-color: white;
  width: 50%;
  left: 0;
  right: 0;
  margin: 150px auto auto auto;
  border: 8px solid black;
  padding: 3% 5% 3% 5%;
}


/*Quote*/

#quote {
  font-family: Bad Script;
  margin-bottom: 4%;
}


/*Author*/

#author {
  font-family: Lato;
  margin-bottom: 8%;
  font-weight: Bold;
  text-transform: uppercase;
}

#quoteBox {
  position: relative;
}

.twitter {
  color: white;
  background-color: #0084b4;
  border: solid #0084b4 3px;
}


/*Refresh Button*/

.generate {
  font-family: Montserrat;
  border: solid black 3px;
}

.highlighted {
  background-color: #B4B8B9;
}

/*Media Queries go here*/

@media (min-width:320px) and (max-width:374px) {
  /* smartphones, iPhone, portrait 480x320 phones */
  body{
      background-image:none
  }
 .container {
  /*position: fixed;*/
   width: 100%;
   margin: 0 auto auto auto;
  left: 0;
  right: 0;
}
  
 h1{
    font-size: 1.8em;
  }
  h4{font-size:1em;}
  
  .twitter{
    margin-bottom:10px;
  }
}
@media (min-width:375px) and (max-width:480px) {
  /* smartphones, iPhone, portrait 480x320 phones */
  body{
      background-image:none
  }
 .container {
  /*position: fixed;*/
   width: 100%;
   margin: 0 auto auto auto;
  left: 0;
  right: 0;
}
  
 h1{
    font-size: 2.1em;
  }
  h4{font-size:1.2em;}
  
  .twitter{
    margin-bottom:10px;
  }
}
@media (min-width:481px) and (max-width:640px) {
  /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
  .container {
   
  /*position: fixed;*/
   width: 100%;
   margin: 0 auto auto auto;
  left: 0;
  right: 0;
}
  
 h1{
    font-size: 2.8em;
  }
  h4{font-size:1.5em;}
  
  .twitter{
    margin-bottom:10px;
  }
}

.bottom{
  margin-top: 10px;
  bottom:0;
  left:0;
  right:0;
  font-family: Lato;
  
}
            
          
!
            
              $(function() {

  var quoteTexts;
  var quoteNoPunctuation;
  var authorName;
  var twitterExport;

  newQuote(); //runs function on page load

  //Function runs on clicking refresh
  $(".generate").on("click", function(event) {
    event.preventDefault();
    newQuote();
  });

  //Function calling API and assigning data
  function newQuote() {
    $.ajax({
      url: "https://api.forismatic.com/api/1.0/",
      //add jsonp on Access Control Allow Origin error
      jsonp: "jsonp",
      dataType: "jsonp",
      data: {
        method: "getQuote",
        format: "jsonp",
        lang: "en"
      }, //upon success, execute below
      success: function(quote) {
          //removes the fullstop
          quoteTexts = quote.quoteText;

          for (i = quoteTexts.length - 1; i > 0; i--) {
            if (quoteTexts.charAt(i) == ".") {
              quoteNoPunctuation = quoteTexts.substring(0, i);
              break;
            }
          }       
             

          $("#quote").text(quoteNoPunctuation);

          if (quote.quoteAuthor) {
            authorName = quote.quoteAuthor;
          } else {
            authorName = "Unknown";
          }
          $("#author").text(authorName);
          twitterExport = quoteNoPunctuation + " - " + authorName;

        } //success callback ends
    }); //ajax ends
  } //newQuote ends

  $(".twitter").on("click", function() {
if(twitterExport.length<=140){
  window.open('https://twitter.com/intent/tweet?text=' + twitterExport);
}else{
  window.open('https://twitter.com/intent/tweet?text=' + twitterExport.substring(0,137) + "...");
}
  })

  $(".generate").hover(function() {
    $(this).toggleClass('highlighted');
  });

});
            
          
!
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