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">
  <h1> Wikipedia Viewer </h1>
  
 
  <button id="random" type="button">Random Article</button>
  <input id="search" type="text" name="search" placeholder="Search - Type & Press Enter">
  <br>
  <div id="content">
    
    
  </div>
  

  
</div> 
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Yrsa');

body{
  background-color: #ed6753;
}

h1{
  font-family: 'Yrsa',serif;
  color: white;
  text-align: center;
}
#random{
  display: block;
  margin: 20vh auto 0;
  border-radius: 6px;
  font-family: 'Yrsa',serif;
  font-size: 25px;
  color: white;
}

input[type="text"]{
  margin: 2vh auto 0;
  background-image: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-128.png'); 
  background-position: 96% 5px; 
  background-repeat: no-repeat;
  padding: 0px 40px 0px 10px;
  background-size: 25px 25px;
  width: 300px;
  border-radius: 6px;
  transition: width 1s;
  transition: transform 1s;
}

input[type="text"]:focus{
  width: 500px;
  transition: width 1s;
  transition: transform 1s;
  
}

.moveup{
  transform: translate(0,-20vh);
  transition: transform 1s;
  
  
}

.gray{
  width:95%;
  height:150px;
  background-color:#ffffff;
  margin: 0 auto;
  padding: 20px;
  color: #4c4c4c;
  border-radius: 5px;
}

            
          
!
            
              $("#random").click(function() {
  window.open("https://en.wikipedia.org/wiki/Special:Random");;
}) // Random Article Page Button


//Detects if the Enter Key is Pressed, Most likely pressed when typed something in search box

$(document).keypress(function(e) {
  if (e.which == 13 && document.getElementById("search").value.length != 0) { // checks if the key pressed is enter
    $("#search").addClass("moveup"); //moveup class adds a smooth transition effect
    $("#random").addClass("moveup");
    content = document.getElementById("search").value; //Sets the content variable to what is inside search box

    var url = "https://en.wikipedia.org/w/api.php?callback=?&action=opensearch&search=" + content + "&format=json" // URL for JSON API

    $.getJSON(url).done(function(data) { // Gets JSON data from wikipedia API

      var contenthtml = ""; // For Adding the boxes
      for (var i = 0; i < data[1].length; i++) { // For loop for adding boxes, more convinient than typing divs for all the result boxes
        var title = data[1][i];
        var abstract = data[2][i];

        contenthtml += "<br><div class=gray><h5><b><a href='https://en.wikipedia.org/wiki/" + title + "' target = _blank>" + title + "</a></b></h5><br><p> " + abstract + "</p></div><br>";
        

      }

      $('#content').html(contenthtml); // Sets the content Html to id content 

      if (data[1].length === 0) { // Length is 0, when user types in something invalid, as the API returns nothing
        $('#content').html("<div class='gray'><h5 style='text-align:center;'> You typed in something Invalid. <h5></div>"); // Box for telling user that it's an error

      }

    }).fail(function() {
      console.log("<div class='gray'><h5 style='text-align:center;'> Error retrieving data from server, Try Again Later <h5></div>"); //Incase there's an error with the server 
    });

  }
});
            
          
!
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