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.

            
              <div id="background" class="container">
  <img id="imgTarget" class="img-fluid"/>
  <div id="posBox"><div class="row justify-content-around">
    <div id="lcol" class="col-xs-12">
      <div class="col-xs-12 col-xs-offset-5">
        <button type="button" id="quothMore" class="btn btn-secondary">Quoth More!</button><p id="tweetBtn"></p></div>
      </div>
    <div id="rcol" class="col-xs-12 col-md-6 col-lg-4">
    <div id="quoteBox">Welcome to JP's superduper advanced quote machine! Click the button for a new quote, and marvel at how each quote pulls a new image! Until the Google search API stops working because of my free account.</div>
  </div>
    </div>
  </div> <!-- posbox -->
</div>
            
          
!
            
              #background {
  position: relative;
  padding: 1rem;
  min-height: 400px;
  background-color: #DDD;
}
#imgTarget {
  z-index: 1;
}
#lcol {
}
#posBox {
  position:absolute;
  padding-top:1rem;
  top:2rem;
  left:1rem;
  right:1rem;
  z-index:100;
}
#rcol {
  margin-left:1rem;
}
#quoteBox {
  padding:1em;
  background-color:rgba(200,200,200,.5);
  border: 1px solid white;
  border-radius:8px;
}
#tweetBox {
  z-index:100;
}
            
          
!
            
              var testMode=0; // testMode=1 causes a placeholder image to be used instead of the google custom search
var twitterURL="";
function getImgURL(auth,tmode) {
  if (tmode) {
    return 'https://ptpimg.me/6mgw4w.jpg';
  } else {
  return 'https://www.googleapis.com/customsearch/v1?q='+(encodeURIComponent(auth))+'&num=1&imgType=face&safe=high&searchType=image&fields=items(link,snippet)&cx=016785142417644725210:ecuzg4lxswe&key=AIzaSyC2ntpD3H9RQuRcD2SyrN4GX38kI1IMcDI';
}
}

$(document).ready(function() {
  var auth="";
  $('#quothMore').on("click", function() {
    $.ajax({type:'GET',
            dataType:'json',
            url:'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
            success: function(json){
              var html="";
              var elips="";
              var longer=0;
              var twitMSG=(encodeURIComponent($(json[0].content).text()).slice(0,(Math.min(json[0].content.length),161)));
              console.log("twitMSGlen= "+twitMSG.length);
              if (twitMSG.length>=161) {
                twitMSG += "...";
              }
              //var twitMSG=$(encodeURIComponent(json[0].content.slice(0,(Math.min(json[0].content.length),139)))).text();
              auth = json[0].title;
              html += "<div class='quotes'>";
              html += json[0].content + "<p class='authorName'>-- " + auth + "</p>";
              twitterURL = 'https://twitter.com/intent/tweet?hashtags=freecodecamp&text='+twitMSG;
              console.log(twitterURL);
              html += "</div>";
              $("#quoteBox").html(html);
              $("#tweetBtn").html('<a href="'+twitterURL+'" target="_blank"><i class="fa fa-twitter-square fa-3x"></i></a> ');
              console.log("auth variable set to: "+auth);
              var myURL = getImgURL(auth,testMode);
              console.log('myURL: '+myURL);
              if (!testMode) {
              $.ajax({type:'GET',
                      dataType:'json',
                      url:myURL,
                      success: function(json2) {
                        // console.log(JSON.stringify(json2.items));
                        var snippet = json2.items[0].snippet;
                        var imgURL = json2.items[0].link;
                        console.log('Found URL to set as image: '+imgURL);
                        // console.log('snippet for image text: '+snippet);
                        $('#imgTarget').attr("src",imgURL);
            },
                      cache:false
                     });
              } else {
                
                console.log('Default URL to set as image: '+myURL);
                //$('#imgTarget').css('background-image','url("'+myURL+'")');
                $('#imgTarget').attr("src",myURL);
              }
            },
            cache: false
    });
    
    
    
    
  });
});
            
          
!
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