myWikipedia

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

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

Technologies

  • HTML
  • CSS
  • JavaScript
    <html>
  <head>
    <title>My Wiki</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css" media="screen">
  </head>
  <body>
    <div class="container">
  		<div class="search-box">
        <h2> Wikipedia </h2><p>By Luke Gwan</p>
  			<div class="form-inline" role="form">
   				<div class="form-group">
      				<label><input class="form-control" id="input" placeholder="please enter something"/></label>
      				<button id="search" class="btn btn-default">Search</button>
      				<button id="lucky" class="btn btn-default">I'm feeling lucky</button>
    			</div>
  			</div>
  		</div>
  		<div class="search-content">
    		<div class="list-group">
    		</div>
  		</div>
	</div>
    <script src="https://code.jquery.com/jquery.js"></script>
    <script type="text/javascript" src="script/bootstrap.min.js"></script>
    <script type="text/javascript" src="script/script.js"></script>
  </body>
</html>

/*Downloaded from https://www.codeseek.co/Agp12010/mywikipedia-AXmjJN */
    body {
  background-image: url(http://www.wyzu.cn/uploadfile/2014/1023/20141023065040325.jpg);
}


/*Downloaded from https://www.codeseek.co/Agp12010/mywikipedia-AXmjJN */
    $(document).ready(function() {
  $("#search").click(function () {
    $(".list-group").empty();
     var input = document.getElementById('input').value;
     input = input.toString();
     console.log(input);
     var wikiUrl = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=" + input +"&utf8=1";
     console.log(wikiUrl);
     $.ajax({
      async: true,
      url: wikiUrl,
      dataType : "jsonp",
      success : function(data){
       for (var i = 0; i < data.query.search.length; i++) {
        var iStr = i.toString();
        $(".list-group").append("<a class='list-group-item' id=" + iStr +">" + "<h2>" + data.query.search[i].title + "</h2>" + "<p>" + data.query.search[i].snippet + "</p>" +  "</a>" );
        //$("a").attr('class', 'list-group-item');
        $("#"+iStr).attr('href', 'https://en.wikipedia.org/wiki/' + data.query.search[i].title);
        $("#"+iStr).attr('target', '_blank');
        console.log(iStr);

       }
      }
     })
  });
  $('#lucky').click(function(){
  window.open("https://en.wikipedia.org/wiki/Special:Random")
  });
});



Comments