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.

              <html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Wikipedia Viewer</title>

  <!-- Google font import-->
  <link href="https://fonts.googleapis.com/css?family=Berkshire+Swash|Comfortaa|Patua+One" rel="stylesheet">
  <!-- Font Awesome Import -->
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />

  <!-- Website title display -->
  <div id="siteTitle" class = "text-center mx-auto my-5">
    <h1>Wikipedia Viewer</h1>
  <!-- User Interface -->
  <div id="userInput" class = "text-center m-auto">
    <input type="text" id = "searchVal" class="rounded">
    <button id = "search" class = "btn rounded-circle"><i class = "fa fa-search"></i></button>
    <a  href="https://en.wikipedia.org/wiki/Special:Random" target="_blank" id="randomSearch" > <button class = " btn">I'm feeling lucky</button></a>
  <!-- Results Display from Wikipedia Search -->
  <div id="resDisplay" class = "container text-justify mx-auto my-5 p-5" style="position:relative"></div>
  <!-- Information about the developer -->
  <div id="devInfo" class = "text-center m-auto">
    <p>coded by <a href="https://codepen.io/Graventh" target="_blank">Gerard</a></p>
              /* Loaded Bootstrap v.4  */

/* Body styling */
  background: linear-gradient(to right, #E9E9E9, #CDCDCD);

/* h1 element styling */
  font-family: "Berkshire Swash";
  /*  color: #5DADE2; */
  color: white;
  text-shadow: 2px 1px black,  0px 0px 20px black;
  font-size: 70px;

/* h2 element styling */
  font-family: "Patua One"

/* p element styling */
  font-family: "Comfortaa"

/* Anchor tag hyperlink styling */
  color: black;
  text-decoration: none; /* No underline */
  color: black;
  color: black;

/* Button styling */
  background: #99D3DF;
  box-shadow: 1px 2px 5px black;
  background: #88BBD6;
  border-style: solid;
  border-width: 2px;
  border-color: black;

/* Results link styling */

  background-color: #99d3df;
  border-style: solid;
  border-width: 1px;
  background-color: #88bbd6;
  box-shadow: 5px 5px 10px black, inset 0px 0px 3px 2px black;
  width: 105%;
  position: relative;
  left: -2.5%;   

              /* Coded by Gerard*/

Variable initialisation.

var searchVal = ""; // Define searchVal as a string.

searchWiki function:
This function performs an asynchronous request to the mediawiki.api to look for information in the wikipedia database.

function searchWiki() {
  searchVal = $("#searchVal").val(); // Get user's input search terms and load them to searchVal variable
    //Performs AJAX request
    type: "GET",
    url: "https://en.wikipedia.org/w/api.php",
    data: {
      action: "opensearch",
      search: searchVal,
      namespace: "0",
      limit: "10",
      format: "json"
    dataType: "jsonp",
    //jsonp: 'callback',
    success: function(data) {
      $("#resDisplay").empty(); //remove the contents of the display results div box
    .done(function() {
      // If AJAX request is successful outputs "success" to the console
    .fail(function() {
      //If AJAX request is UNsuccessful outputs "error" to the console
    .always(function() {
      //WHEN AJAX request has received a response, outputs "complete" to the console

resDisplay function:
this function will display the results from the mediawiki api search call for the user

function resDisplay(data) {
  var html = ""; //html variable will store the html text to add to the website upon receiving wikipedia search result
  for (var i = 0; i < data[1].length; i++) {
    html += "<a href ='" + data[3][i] + "' target='_blank'>"; //start anchor hyperlink element
    html += "<div class = 'divRes rounded mx-auto my-2 p-2'>"; //start new div box

    html += "<h2>" + data[1][i] + "</h2>"; //add wikipedia's article title

    html += "<p>" + data[2][i] + "</p>"; //Add wikipedia's article descritpion
    html += "</div>"; //close div box
    html += "</a>"; //close anchor hyperlink element

animResDis function:
This function will perform a series of animations on the results found from the wikipedia API call and call the searchWiki function.

function animResDis(){
    opacity: 0
    top: "100px"
  }); //make results display transparent and move it 100 px down *** Important to have the following styling on the element!!: position: relative. Otherwise position animations won't work
  searchWiki(); //perform call to wikipedia API
    opacity: 1,
    top: "0px"
    }, 500); //slowly turn on the opacity

Wikipedia Viewer code:
This piece of code calls the searchWiki function and performs the wikipedia search upon either pressing the enter key or clicking the search button.

$("#searchVal").hide().css("width", "0px");

$("document").ready(function() {
  //This function will only execute if the website has been loaded
  Hover user input code:  
  When the user hover the mouse over the user input area, the text input form will appear with an animation
    .animate({width: "300px"}, 500);
  Search button code:
  When the user clicks search performs wikipedia API call and returns the results from the search
  $("#search").on('click',function() {
  Enter key code:
  When the user presses the enter key search performs wikipedia API call and returns the results from the search
  $("#searchVal").on('keypress', function(evt){
    if(evt.keyCode === 13){

🕑 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.