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

              
                <h1 id='title'>Wikipedia Search</h2>

<div class='query-container'>
  <button type='button' id='random'><i class="fa fa-random fa-2x"></i></button>
  <input id="wiki-query" type="text" name=""></input>
  <button id='submit-btn'><i class="fa fa-search fa-2x"></i></button>
<div class="auto-complete">  
</div>
</div>


<div id="entry-holder">  
</div>


              
            
!

CSS

              
                

body {
  background-color: #293132;
  font-family: 'Droid Sans', sans-serif;
}

#title {
  text-align: center;
  font-size: 4em;
  color:#50D8D7;
  text-shadow: 0px 0px 6px rgba(255,255,255,0.7);
}

.query-container {
  position: relative;
  width: 500px;
  margin: 0 auto;
  text-align: center;
  transition: all .5s ease;
}

#wiki-query {
  background-color: #3568B5;
  border: 2px solid #547AA5; 
  height: 35px;
  font-size: 25px;
  transition: all .5s ease;
  color: #50D8D7;
  
}

#wiki-query:focus {
  outline: 0;
  border-radius: 6px;
  border: 2px solid #50D8D7;  
}

.entries {
  width: 650px;
  height: 200px;
  margin: 0 auto;
  background-color: #3568B5;
  font-size: 1.3em;
  color: #50D8D7;

  transition: all 1s ease;
  box-shadow: 2px 2px 20px 2px;
}

.entries-title {
  padding-top: 20px;
}

.auto-complete { 
  position: absolute;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  width: 320px;
  font-size: 15px;
  z-index: 1; 
  background-color: white;
  padding-left: 2px;
  text-align: left;
  font-size: 20px;
  color: #50D8D7;
  background-color: black;
  
}

.auto-entries {
  height: 30px;  
  cursor: pointer;
}
.auto-entries:hover {
  background-color: #50D8D7;
  color: black;
}

button {
  background-color: #3568B5;
  border-color: #547AA5;
  color: #263B1C;
  transition: all .25s ease;
  cursor: pointer;
  padding: 5px;  
}
#random {
  margin-right: 20px;
}

#submit-btn {
  margin-left: 20px;
}

button:hover {
  border-radius: 8px;
  color: #50D8D7;
  border-color: #50D8D7;
}


#entry-holder {
  position: relative;
  width: 800px;
  margin: 30px auto 0 auto;
  text-align: center;
}

.error {
  font-size: 20px;
  color: #50D8D7;
}

a {
  text-decoration: none;
}
              
            
!

JS

              
                //Exercise utilizing Wikipedia's API + creating a filter search bar!

//First API call to generate a list on the actual search from the user: https://en.wikipedia.org/w/api.php?action=query&format=json&generator=allpages&gaplimit=4&gapfrom=SEARCH QUERY GOES HERE&prop=info

//make an array or something to capture all the titles from the JSON object

//then plug those titles into the bottom extract API

//API format to use: https://en.wikipedia.org//w/api.php?action=query&prop=extracts&format=json&exsentences=1&explaintext=&titles=QUERY GOES HERE

// https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=SEARCH%20GOES%20HERE&limit=10&namespace=0&format=jsonfm use this for autocomplete

$(document).ready(function(){
  //for the random wiki entry function
  var randomWikiAPI = 'https://en.wikipedia.org/w/api.php?action=query&list=random&format=json&rnnamespace=0&rnlimit=1&callback=?'
  var entryArr = [];
  var userQuery = '';
  //shows the auto-complete box when you are focused on it
  $('#wiki-query').on('focus', function(){
    $('.auto-complete').show();
  })
  
  //function to get the user's entry in the search bar and an autocomplete; sends that to the wikipedia api to get 5 entries for autocomplete, stores them in an array, appears below the search bar.
  $('#wiki-query').keyup(function() {    
     userQuery = document.getElementById("wiki-query").value
     $.getJSON('https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + userQuery + '&limit=5&namespace=0&callback=?', function(data){
       var autoCompleteArray = data[1];
       var autoCompleteHTML = [];
       for (j=0; j<autoCompleteArray.length; j++) {
         autoCompleteHTML.push('<p class="auto-entries">' + autoCompleteArray[j].substring(0,22) + '...</p>')
       }
       $('.auto-complete').html(autoCompleteHTML);
       //clickable auto complete entries to fill the search bar
       $('.auto-entries').click(function(){         
         userQuery = $(this).text();
         document.getElementById('wiki-query').value = userQuery.slice(0, -3);
         $('#wiki-query').focus();
         $('.auto-complete').hide();
    })
     });  
    
  });  
  //random entry
  $('#random').click(function(){
    $.getJSON(randomWikiAPI, function(data){
    var randomEntry = data.query.random[0].title
    document.getElementById('wiki-query').value = randomEntry;
      userQuery = randomEntry;
    })    
  });
  
  //clears data, gets some new data, displays data by then calling displayData (below)
  function clearAndGetData(){    
    $('#wiki-query').blur();
    $('.entries, .error').remove();
    $('.auto-complete').hide();
    if (userQuery === '') {
      $('#entry-holder').append('<h5 class="error animated rubberBand">Please try again!</h5>')
    }
    else {
      $.getJSON('https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=' + userQuery + '&callback=?', function(data){            
        displayData(data.query.search) 
        console.log(data.query.search)
      })  
    }
  };
  
  //displays the data on the page
  function displayData(data) { 
    if (data.length === 0) {
      $('#entry-holder').append('<h5 class="error animated rubberBand">Please try again!</h5>')
    }
    else {
        for (i=0; i<data.length; i++) {
          setTimeout(function(title, snippet) {
          $('#entry-holder').append('<a href="https://en.wikipedia.org/wiki/' + title + '"><div class="entries animated fadeIn"><h3 class="entries-title">' + title + '</h3><p class="snippet">' + snippet + '</p></div></a>')
          }, 300 * i, data[i].title, data[i].snippet );
        }      
    }
  }
  
  //executs search for pressing search button and for pressing enter
  $('#submit-btn').click(clearAndGetData);
  $('#wiki-query').bind('enterKey', function(){
    clearAndGetData();
  })  
  //enter key functionality
  $('#wiki-query').keyup(function(e){
    if (e.keyCode == 13) {
      $(this).trigger('enterKey');
    }
  })
    
  });  



              
            
!
999px

Console