cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="container">
  <div class="row" id="header">
    <div class="col-xs-12">
      <h1>WikiSearch</h1>
      <p>
        <form action="#" onsubmit="enter()">
          <input type="search" id="search" placeholder="Search"></input>
          <i class="fa fa-search"></i>
        </form>
      </p>
      <button id="randomBtn">Random</button>
    </div>
  </div>
  <div class="row" id="results">

  </div>
</div>
            
          
!
            
              h1 {
  font-family: serif;
}
#header {
  text-align: center;
}
input {
  width: 120px;
}
button {
  margin-bottom: 20px;
}
i {
  cursor: pointer;
  margin-left: 5px;
}
.well h2, .well p {
  margin: 0 10px 0 10px;
}
h2 {
  font-size: 1.2em;
}
p {
  font-size: 1em;
}
            
          
!
            
              function wikiSearch() {
  var searchValue = document.getElementById("search").value;
  $.ajax({
    url: 'http://en.wikipedia.org/w/api.php',
    data: {
      action: 'query',
      list: 'search',
      srsearch: searchValue,
      format: 'json'
    },
    dataType: 'jsonp',
    success: function(json) {
      console.log(json);
      var html = '';
      json.query.search.map(function(val) {
        var keys = Object.keys(val);
        html += '<div class="col-xs-12 col-lg-6 col-lg-offset-3 item-container"><div class="well">';
        html += '<a href="' + val.link + '" target="_blank"><h2>' + val.title + '</h2></a><p>' + val.snippet + '...</p>';
        html += '</div></div>';

      });
      if (json.query.searchinfo.totalhits > 0) {
        html += '<div class="col-xs-12 col-lg-6 col-lg-offset-3 item-container"><div class="other"><p>There were ' + encodeURI(json.query.searchinfo.totalhits) + ' total hits, check them all out directly on <a href="https://en.wikipedia.org/w/index.php?search=' + searchValue + '">Wikipedia</a>.</p></div></div>';
      } else {
        html += '<div class="col-xs-12 col-lg-6 col-lg-offset-3 item-container"><div class="other"><p>There were no results, try something else.</p></div></div>';
      }
      $('#results').html(html);
      console.log('Search run with query: ' + searchValue);
    }
  });
}

function wikiRandom() {
  $.ajax({
    url: 'http://en.wikipedia.org/w/api.php',
    data: {
      action: 'query',
      list: 'random',
      rnnamespace: 0,
      rnlimit: 10,
      format: 'json'
    },
    dataType: 'jsonp',
    success: function(json) {
      console.log(json);
      var html = '';
      json.query.random.map(function(val) {
        var keys = Object.keys(val);
        html += '<div class="col-xs-12 col-lg-6 col-lg-offset-3 item-container"><div class="well">';
        html += '<a href="' + val.link + '" target="_blank"><h2>' + val.title + '</h2></a>';
        html += '</div></div>';

      });
      $('#results').html(html);
    }
  });
}

function enter() {
  wikiSearch();
  return false;
}

$(document).ready(function() {
  $('.fa-search').click(function() {
    wikiSearch();
  });
  $('#randomBtn').click(function() {
    wikiRandom();
  });
})
            
          
!
999px
Loading ..................

Console