Wikipedia Viewer

In this example below you will see how to do a Wikipedia Viewer with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by BrianBrain, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright BrianBrain ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Wikipedia Viewer</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
  
  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class = "container">
  <h1 class = "text-center">Wikipedia API Search</h1>
  <a href = "https://en.wikipedia.org/wiki/Special:Random" target="_blank"><img src = "https://c2.staticflickr.com/6/5812/30812529576_6d7314a7db_o.png" id=wikiLogo></a>
<input class = "form-control" id="searchTerm">
  <button class="btn btn-primary" id="search" type="button">Submit</button>
  <ul id = "output">
  </ul>
</div>
<footer class = "text-center">Authored by Brian Kidd &#169 2016</footer>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/BrianBrain/wikipedia-viewer-aBOBqW */
body{
background-color:#0099cc ;
font-family:'Roboto', sans-serif;
font-size:2.5em;
color:white;
}
#wikiLogo{
  width:261px;
  height:320px;
  display:block;
  margin-left:auto;
  margin-right:auto;
}
.btn{
 background-color: #00394d;
}
a{
  color:black;
}

/*Downloaded from https://www.codeseek.co/BrianBrain/wikipedia-viewer-aBOBqW */
$(document).ready(function(){
  $('#search').click(function(){
    
       var searchTerm=$('#searchTerm').val();   
    
       var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="+ searchTerm + "&format=json&callback=?";
    
        $.ajax({
          type:"GET",
          url:url,
          async:false,
          dataType:"json",
          success: function(data){
          
            
         $('#output').html(' ');
            
         for(var i = 0; i<data[1].length;i++)
          {
      
         $('#output').prepend("<li><a href= "+data[3][i]+">"+data[1][i]+"</a><p>"+data[2][i]+"</p></li>");//prepend adds it a list
            
          }
            
          },
          
          error: function(errorMessage){
            alert("Error");
          }
          
          
        });          
   });
});

Comments