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

              
                <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>

<div class="container">
    <div class= "text-center">
      <div class = "heading">
          <h1>Wikipedia Viewer</h1>
          <h2>FreeCodeCamp - Front End Developement</h2>
      </div>
  </div>
  <div class="row">
  <input id="search" type="search" placeholder="Search Wikipedia..." class="form-control">
      <button id="searchTerm" type="button" class ="btn btn-primary">Wiki Search</button> 
    </div>
      <div class="row">
          <button class="button btn btn-success" href="http://en.wikipedia.org/wiki/Special:Random" target="_blank">Random Article!</button>
        </div>
  <!-- <div id ="results"></div> -->
  <article class="results">
  </article>
</div>
              
            
!

CSS

              
                
body {
  background: url("https://d3g00f3t09yzqp.cloudfront.net/2017/02/170131-Wiki.png") no-repeat center top; 
  font-family: 'Raleway', sans-serif;
  text-align: center; 
}

a:hover,
a:visited,
a:active,
a:link {
  text-decoration: none;
}

.heading{
  font-family: 'Raleway', sans-serif;
  background-color: #0000FF;
  color: white;
  border-radius:15px;
  margin:2%;
  padding:2%;
  display:inline-block;
}

p{
  padding-bottom: 1%;
  padding-left:1%;
  font-size:17px;
  color:white;
  text-align: left;
  font-family: 'Raleway', sans-serif;
}
div{
  border-radius:15px;
}

button{
margin:1%;
}

/*
#results{
 margin-top:1%;
 border-radius:25px;
 font-family: 'Raleway', sans-serif;
 background-color: #0000FF;
}
*/
h3{
  font-family: 'Raleway', sans-serif;
  color:white;
  padding-left:1%;
  padding-top:1%;
  text-align: left;
}

.well {
  margin-right: 100px;
  margin-left: 100px;
  background-color: #0000FF;
}
  
.results {
  margin-top: 1%;
  color: white;
  margin-top:1%;
  border-radius:15px;
  font-family: 'Raleway', sans-serif;
}
  

              
            
!

JS

              
                window.onload = function() {
 document.getElementById("searchTerm").focus();
};

/*
//Run jQuery
$(document).ready(function(){
  //On click run code
  $("#searchTerm").click(function(){
    //Get value of input field
 var search = $('#search').val();
    //Run ajax and get return in data type JSON
    var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="+ search +"&format=json&callback=?";
      $.ajax({
        type: "GET",
        url: url,
        contentType: "application/json; charset=utf-8",
        async: false,
        dataType: "json",
        success: function (data, textStatus, jqXHR) {
          $('#results').html('');
          for(var i=0;i<data[1].length;i++){
            $('#results').prepend("<div><div><a href="+data[3][i]+"><h3><strong>" + data[1][i]+ "</strong></h3>" + "<p>" + data[2][i] + "</p></a></div></div>" );        
          }    
   $("#search").val('');
        },
        error: function (errorMessage) {
         console.log(errorMessage);
        }
    });
    

  });
      $("#search").keypress(function(e){
      if(e.which==13){
        $("#searchTerm").click();
      }
    });
  
});

*/

var arrResults = [];
var html = '';

// Create structure for the data
function Result(title, snippet) {
  this.title = title;
  this.snippet = snippet;
}

function search() {
  // Use Ajax to handle API
  $.ajax({
    url: 'https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=' + $('#search').val(),
    dataType: 'jsonp',
    type: 'POST',
    headers: {
      'Api-User-Agent': 'Example/1.0'
    },
    success: function(data) {

      // First we clear the children from our class to make sure no previous results are showing.
      $('.results').empty();

      // Then we also clear the array with the results before providing new information.
      arrResults.length = 0;
      var resArr = data.query.search;

      //For each result, generate the html data.
      for (var result in resArr) {
        arrResults.push(new Result(resArr[result].title, resArr[result].snippet));
        html = '<div id="articles" class="well"><a href="https://en.wikipedia.org/wiki/' + resArr[result].title + '"target="_blank"><h3>' + resArr[result].title + '</h3></a><p>' + resArr[result].snippet + '</p></div>';

        // Displays the elements to the page
        $('.results').append(html);
      }
    }
  });

 // This will handle when to display results based on the search bar.
  if ($('#search').val().length > 0) {
    $('.articles').css('display', 'none');

  } else if ($('#search').val().length < 1) {
    // display everything again
    $('.articles').css('display', 'block');
  }

  // This make thigns complex with each key stroke
  $('#search').unbind('keyup');
  $('#search').keyup(function() {
    search();
  });
}
$('#search').keyup(function() {
  search();
});

              
            
!
999px

Console