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 main text-center">
  <div id="random">
    <p><a target='_blank' href="https://en.wikipedia.org/wiki/Special:Random">Click for a Random Article</a></p>
  </div>
  <div class='search-icon'><i class="fa fa-search fa-2x" aria-hidden="true"></i></div>
  <div class="search-input"><input type="text" name="search-q" value=""></input>
  <span class="close">X</span></div>
  <div id="instructions">Click the icon to search</div>
</div>


<div class="container">
  <div class="response"></div>
</div>
            
          
!
            
              body {
  background-color: #4a5e82; 
  font-size: 2.2em;
  color: #333;
}

#random a{
  text-decoration: none;
  color: #333;
}


.main {
  width: 500px;
  display: block;
  margin: 150px auto 50px auto;
}
.search-icon {
  display: inline;
  color: #FF8C00;
  padding: 10px;
}

.search-input {
  display: none;
  padding: 10px;
  border-style: solid;
  border-radius: 30px;
  border-width: 2px;
  border-color: #FF8C00;

  
  
}

input {
  display: inline;
  //border-radius: 15px;
  width: 380px;
  height: 30px;
  margin: 0px;
  padding: 5px 10px;
  background-color: #4a5e82;
  border-style: none;
  //border-color: #333;
  transition: width 2s;
   text-align: right;
}

.close {
  display:inline-block; 
  vertical-align:middle;
  
   margin: 10px;
  
}


.article {
  background-color: #ddd;
  color: #333;
  margin: 10px auto;
  padding: 5px 10px;
  border-bottom: 2px #000 solid; 
  border-right: 2px #111 solid; 
 
  
}

.extract {
  font-size: .8em;
}
            
          
!
            
              $(document).ready(function() {

  $('.search-icon').click(function() {
    $(this).toggle();
    $('.search-input').toggle();
  });

  $('.search-input').click(function() {
    console.log('input box clicked');
    $('input').css('text-align', 'left');
    $('input').val("");
  });

  $('input').keypress(function(event) {

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if (keycode == '13') {
      console.log('You pressed a "enter" key in textbox');

      var value = $(this).val();
      // $('.response').text(value);
      console.log(value);
      searchWiki(value);
    }

   // event.stopPropagation();
  });
  
  $('.close').click(function(){
    $('.search-icon').toggle();
    $('.search-input').toggle();
  })

  function searchWiki(str) {
    var url = "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=" + str;

    
    
    console.log(url);

    $.get(url, function(data) {

      //console.log(data.query.pages);
     var myKeys = Object.keys(data.query.pages)
    //console.log(myKeys);
      
      myKeys.forEach(function(article){
        //console.log(article);
        var title = data.query.pages[article].title;
        var extract = data.query.pages[article].extract;
        var url = 'https://en.wikipedia.org/?curid=' + article;
       
        var html = '<div class="row article"><b><em class="title"><a href='+'https://en.wikipedia.org/?curid='+ article + '>'+ title + '</a></em></b><br>' +
            '<p class="extract">' + extract + '</p></div>';
        
        
        $('.response').append(html);
      });
      
    }, "jsonp" );

   
  }

});
            
          
!
999px
Loading ..................

Console