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

HTML

              
                <head>
</head>
<body>
  <p class="disappear"> <i id="glass" class="fa fa-search fa-5x" aria-hidden="true"></i></p>
  <p class="disappear"> Click above to search Wikipedia! </p>
  
  <input id="searchBox"type=text placeholder="search Wikipedia!"></input>
<br></br>
<button id="random"> RANDOM!</button>
<h3> Results:</h3>
<div id='resultamount'>
  <!--  # of Search results land in here --> 
</div>
<div id='results'><!--individual results land in here--> </div>
</body>
              
            
!

CSS

              
                body {
  text-align:center;
  background-color:#b3d9ff;
    
}
.disappear{
  
  visibility:visible;
}
#searchBox{
  visibility:Hidden;
}

/*use bootstrap to pretty up the  button*/
Button {
  
}
/* make a pretty format for results - div children of the results div.*/
#results div{
  
}
.item{
  background-color:#e6e6e6;
  text-align:center;
  width: 50%;
  padding:1%;
  margin-bottom:1%;
  margin-left:25%;
  border-color:transparent yellow yellow transparent;
  border-style:solid;
  
}
              
            
!

JS

              
                //1.Click event to swap the icon with the searchbox
$('.disappear').on('click', vanish);

function vanish(){
  $('.disappear').css("visibility","hidden");
  $('#searchBox').css("visibility","visible");
  $('#searchBox').focus();
};
//2. search events
$('#random').on('click', wikiRandom);

$('#searchBox').on('change', wikiSearch);

//3. Search function
function wikiSearch() {
  var searchTerm = $('#searchBox').val();
   $('#resultamount').empty();
   $('#results').empty();
  //3a. API call based on search term
  
  $.ajax({
    type:"GET",
    url:"https://en.wikipedia.org/w/api.php?action=opensearch&format=json&origin=*&search=%22"+searchTerm,
     //3b. success callback pushing results to console
    success:function(json){
      console.log("success");
      //console.log(json);
      //if json.error
      if(json.hasOwnProperty('error')){
        console.log("invalid");
      $('#results').html("<p> Invalid search!</p>")      
//deliver results
} else{
  var titles = json[1];
  var abstracts = json[2];
  var links = json[3];
  console.log(titles.length);
  $('#resultamount').html(
    "<p> You got "+titles.length+" results!</p>");
 for(i=0; i<titles.length; i++ ) {
    $('#results').append( "<div class='item'><a href="+links[i]+"><p class='resultTitle'>"+titles[i]+"</p></a><p class='resultAbstract'>"+abstracts[i]+"</p> </div>");
 }
 };
    },
     //3c. failure callback showing no results found
    error:function(error){
      console.log("fail");
      $('#results').html("<p> ERROR!</p>");
    },
    
  });

 
 
};
//4. random function
function wikiRandom(){
     $('#resultamount').empty();
     $('#results').empty();
     $.ajax({
        type:"GET",
        url:"https://en.wikipedia.org/w/api.php?action=query&format=json&origin=*&prop=info|extracts&inprop=url&generator=random&grnnamespace=0&grnlimit=10",
        success:function(json){
          console.log("success");
          var randomPages=json.query.pages;
          console.log(randomPages);
          var randomIDs=Object.keys(json.query.pages);
          var resultNumber=Object.keys(randomPages).length;
          var randomLinks= [];
          for (j=0;j<resultNumber;j++){
            var pusher=randomPages[randomIDs[j]].fullurl;
            randomLinks.push(pusher);
          };
          var randomTitles=[];
          for (j=0;j<resultNumber;j++){
            var pusher=randomPages[randomIDs[j]].title;
            randomTitles.push(pusher);
          };
          var randomExtracts=[];
          for (j=0;j<resultNumber;j++){
            var pusher=randomPages[randomIDs[j]].extract;
            randomExtracts.push(pusher);
          };
          
          for(k=0;k<resultNumber; k++ ){
            $('#results').append( "<div class='item'><a href="+randomLinks[k]+"><p class='resultTitle'>"+randomTitles[k]+"</p> </a></div>");
          }
            
         },
        });
  
      };
              
            
!
999px

Console