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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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" id="wrapper">
  <div id="content">
      <div class="title">Wikipedia Viewer
      </div>
      <div id="signature">by Laura Barluzzi</div>
    
      <div class="container-fluid">
        <div class="row">

          <div class="col-xs-6 separator">
            <div class="subtitle">Type a topic</div>
            
            
            <div class="input-group">
              <input type="text" id="search" class="form-control" placeholder="Search for...">
              <span class="input-group-btn">
                <button class="btn btn-default" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
              </span>
          </div><!-- /input-group -->
            
            
          </div> <!--col-left-->

          <div class="col-xs-6">
            <div class="subtitle">Click the button</div>
            <a class="no-style" id="random" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">random article</a>
          </div> <!--col-right-->
          
        </div> <!--row-->
      </div> <!--container-fluid-->
    
      <div id="search-results"></div>
     


  </div> <!--content-->
</div> <!--container-fluid-->
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lobster);

html, body {
  text-align: center;
  background-color: #00162B;
  color: white;
  padding: 30px;
}

#content {
  padding: 30px;
}

.title {
  font-size: 50px;
  font-family: Lobster;

}

#signature {
  font-style: italic;
  color: #EE8D00;
  padding: 20px;
  margin-bottom: 50px;
}

.separator {
  border-right-style: solid;
  border-right-color: white;
}

.subtitle {
  font-family: Lobster;
  font-size: 30px;
  margin-bottom: 20px;
}

.col-xs-6 {
  margin-bottom: 50px;
  padding-bottom:20px;
}

.input-group {
  margin: 0 auto;
  width: 60%;
  height: 20px;
  border: solid;
  border-color: white;
  border-radius: 5%;  
}

input[type="text"] {
  background-color: #00162B;
  border-color: white;
  font-size: 20px;
  color: white;
}

.btn {
  background-color: #6da5ff;
  border-color: #6da5ff;
}
.btn:hover {
  background-color: #EE8D00;
}

.btn:hover .fa-search {
  color: #00162B;
}

.fa-search {
  color: #00162B;
}

a.no-style {
  text-decoration: none;
}

#random {
  border-style: solid;
  border-color: white;
  border-radius: 5%;
  padding: 10px;
  color: white;
  font-size: 20px;
  ;
}

#random:hover {
  background-color: #EE8D00;
  border-color: #EE8D00;
  color: #00162B;
}

.box {
  background-color: #dce5f4;
  color: #333;
  margin: 10px;
  padding: 5px 20px 5px 20px;
  font-size: 24px;
  font-weight: 600;
}
.box:hover {
  border-left-style: solid;
  border-left-color: #EE8D00;
}

.text-box {
  font-size: 20px;
  color: #333;
}


            
          
!
            
              
function updatePage(wikiJsonData) {
  console.log("in WikiJsonData");
  console.log(wikiJsonData);
  //results its an object containing many pages info, each page has a id
  var results = wikiJsonData.query.pages;
  //work with results  
  $("#search-results").empty();
  
  for (var pageId in results) {
    if (results.hasOwnProperty(pageId)) {
      console.log(pageId);
      var pageData = results[pageId];
      console.log(pageData);
      var pageUrl = "https://en.wikipedia.org/?curid=" + pageId;
      $("#search-results").append(
        "<a class='no-style' href='" + pageUrl + "' target='_blank'>" +
        "<div class='box'> " + pageData.title + "<div class='text-box'>" + pageData.extract + 
        "</div> </div> </a>")
    }
  }
}

function ajaxError() {
   alert("Ajax call didn't succeed");
}

function getWikiArticles(url) {
  console.log("in getWikiApi")  
  $.ajax({
    url: url, 
    dataType: 'jsonp',
    headers: { 'Api-User-Agent': 'Example/1.0' },
    error: ajaxError,
    success: updatePage,
  });
}

function buildURL(title) {
  console.log("in buildURL");
  title = encodeURI(title);
  var urlApi = 'https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=' + title;
  getWikiArticles(urlApi)
}

function getTopic() {
  //console.log("in getTopic");
  var searchTitle = $("#search").val();
  console.log(searchTitle);
  if (searchTitle !== "") {
    buildURL(searchTitle);
  } else {
    $("#uploaded-page").text("You entered an empty string.")
  }
  
}

function main() {
  console.log("in main");
      
  $('.btn').on('click', function(){
      getTopic();
  })
  
  $(document).keypress(function(e) {
    //13 is enter on the keyboard.
    if(e.which == 13) {
        getTopic();
    }
  });
}

$(document).ready(main);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console