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-fluid">

    <header>
      <h1>Search Wikipedia</h1>
    </header>

    <hr>

    <main>
      <p><input id="search" placeholder="Search Wikipedia"></p>
      <div class="row">
        <h2>Search Results</h2>
        <div id="results">
        </div>
      </div>

    </main>

    <hr>

    <footer>
      <div class="row row-eq-height">
        <div class="col-lg-12">
          <p>&copy; Se&aacute;n Behan 2015</p>
        </div>
      </div>
    </footer>
  </div>
            
          
!
            
              a {
  color: #333;
}

body {
  background-color: #f6f6f6;
  color: #252525;
  font-size: 16px;
  font-family: sans-serif;
}

h1, h2, h3 {
  text-align: center;
  color: #000000;
  text-shadow: 1px 1px #cccccc;
}

h1 {
  font-size: 1.8em;
  padding: 1.2em;
}

h2 {
  font-size: 1.5em;
  padding: 1em;
}

h3 {
  font-size: 1.2em;
  padding: .75em;
}

hr {
  border-top: 1px solid #aaaaaa;
}

#latest {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

p {
  font-size: .85em;
}

.result {
  border: 1px solid #aaa;
  margin-top: 10px;
}

#search {
  width: 50%;
  margin: 0 auto;
  display: block;
}

.ui-autocomplete-loading {
  background: white url("https://s3-eu-west-1.amazonaws.com/jjmax/images/ajax-loader.gif") right center no-repeat;
}

            
          
!
            
              $(function() {
  $("#search").autocomplete({
    source: function(request, response) {
      $.ajax({
        url: "http://en.wikipedia.org/w/api.php",
        dataType: "jsonp",
        data: {
          'action': 'opensearch',
          'format': 'json',
          'limit': 20,
          'search': request.term
        },
        success: function(data) {
          response(data[1].slice(1));
        }
      });
    },
    autoFocus: true,
    minLength: 3,
    select: function(event, ui) {
      getResults(ui.item.label);
    },
    open: function() {
      $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
    },
    close: function() {
      $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
    }
  });
});

function getResults(searchTerm) {
  $.ajax({
    url: "http://en.wikipedia.org/w/api.php",
    dataType: "jsonp",
    data: {
      'action': 'opensearch',
      'format': 'json',
      'limit': 100,
      'search': searchTerm
    },
    success: function(data) {
      data = data.slice(1);
      // http://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript
      var results = data[0].map(function(val, i) {
        return data.map(function(row) {
          return row[i];
        });
      });

      presentResults(results);
    }
  });
}

function presentResults(results) {
  var displayPack = '';
  results.forEach(function(result) {
    displayPack += '<a href="' + result[2] + '">';
    displayPack += '<div class="result col-xs-offset-3 col-xs-6">';
    displayPack += '<h3>' + result[0]  + '</h3>';
    displayPack += '<p class="hidden-xs">';
    if (result[1]) {
      displayPack += result[1];
    } else {
      displayPack += '<i>No description available</i>';
    }
    displayPack += '</p>';
    displayPack += '</div>';
    displayPack += '</a>';
  });
  $('#results').html(displayPack);
}

            
          
!
999px
Loading ..................

Console