css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
                <div class="container-fluid header">
      <header>
        <h1><i class="fa fa-newspaper-o fa-2x"></i> Wikipedia Viewer</h1>
      </header>
    </div>

    <div class="container-fluid main-content">
      <form class="form-inline form-like">
        <div class="input-group text-center">
          <label class="sr-only" for="search-input">Search field</label>
          <div class="input-group">
            <span class="input-group-addon"><i class="fa fa-search fa-fw" aria-hidden="true"></i></span>
            <input type="text" class="form-control" name="search" id="search-input" placeholder="Search..." />
          </div>
        </div>
        <button class="btn btn-default" type="button" id="submit"><i class="fa fa-search" aria-hidden="true"></i> Search</button>
        <a class="btn btn-default" type="button" id="luck" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank"
        title="link to random Wikipedia article" aria-hidden="true">I'm feeling lucky!</a>
      </form>

      <div class="result-field list-group"> <!-- Where the articles will be listed -->

      </div>

    </div>


    <footer>
      <div class="container-fluid">
        <div class="row">
          <div class="col-xs-2 left"><p>Wood, R.</p></div>
          <div class="col-xs-2 right"><p>Powered by: <a href="#" target="_blank">Wikipedia</a></p></div>
        </div>
      </div>
    </footer>


            
          
!
            
              /* GENERAL STYLES */

* {
  box-sizing: border-box;
  font-family: 'Source Code Pro', monospace;
}

body {
  background-color: #FFFACD;
}


/* SPECIFIC STYLES */

h1 {
  font-weight: 700;
  font-size: 60px;
}




/* HEADER STYLES */

.header {
  text-align: center;
  margin-bottom: 30px;
  margin-top: 50px;
}



/* MAIN CONTENT STYLES */

.main-content {
  width: 90%;
  height: 1000px;
}

.form-like {
  margin: 50px auto;
}

#search-input {
  width: 400px;
  -webkit-transition: width 0.4s ease-in-out;
  transition: width 0.4s ease-in-out;
  background-color: transparent;
}

#search-input:hover {
  border: 1px solid blue;
}

#search-input:focus {
  width: 1100px;
}

.input-group {
  padding: 5px;
}

.input-group-addon,
.btn {
  background-color: #aaa;
}

#search-input,
.btn {
  font-size: 18px;
}

.btn {
  padding: 5px 15px;
  float: right;
  margin: 3px 5px 3px 10px;
}

.btn:hover {
  border: 1px solid blue;
}

.btn:active {
  padding: 12px 17px;
}

.list-group-item {
  padding: 30px 10px;
  margin: 10px auto;
  border: 2px solid black;
}

.list-group-item:hover {
  border: 2px solid blue;
}

#luck {
  background-color: lightblue;
}



/* FOOTER STYLES */

footer {
  background-color: #aaa;
  width: 100%;
  height: 50px;
  text-align: center;
  padding: 10px 0;
}

footer p {
  color: #fff;
}

.left {
  margin-left: -10px;
}

.right {
  float: right;
  margin-right: 45px;
}

            
          
!
            
              $(document).ready(function() {

  function getValue() {
    var search = $('#search-input').val();
    var wikipURL = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=&list=search&srsearch=";
    wikipURL += search + "&srlimit=8&callback=?";
    return wikipURL;
  }

  function showArticle(title, snippet) {
    var $article = $("<a href='https://en.wikipedia.org/wiki/" + title
      + "' class='list-group-item' target='_blank'><i class='fa fa-newspaper-o'></i><strong> " + title + "</strong>: "
      + snippet + "</a>");
    $('.result-field').append($article);
  }

  function getData(url) {
    $.getJSON(url).done(function(data) {
      var title, snippet;
      for (var i = 0; i < 8; i++) {
        title = data.query.search[i].title;
        snippet = data.query.search[i].snippet;
        showArticle(title, snippet);
      }
    }).fail(function(err) {
      $('.result-field').append("<p>Something has gone wrong! " + err + "</p>");
    });
  }

  function doActions(e) {
    e.preventDefault();
    $('.result-field').empty();
    var url = getValue();
    getData(url);
  }

  $('#submit').on('click', function(e) {
    doActions(e);
  });

  $('#search-input').keydown(function(e) {
    if (e.which == 13) {
      doActions(e);
    }
  });



});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console