Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>

  <div class="container text-center">
    <form id="form" class="form">
      <input name="input" class="form-control" id="term" type="search" required placeholder="Search Wikipedia...">
      <button type="submit" value="click">
        <span id="search-icon"><i class="fas fa-search"></i></span>
      </button>
      <span class="formbutton" id="clear">Clear</span>
      <!-- <a href="#" class="formbutton" id="clear">Clear</a> -->
      <a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank" class="formbutton"><i class="fas fa-random"></i> Random</a>
    </form>

    <div id="contents">
    </div>

  </div>

  <div class="container justify-content-center text-light text-center" id="footer" >
    Written and Coded By <a href="http://yingjiehu.com" target="_blank">Yingjie Hu</a> with <span style="color:red"><i class="fas fa-heart"></i></span><br>
    View <a href="https://github.com/huyingjie/wikipediaViewer" target="_blank">source code</a> at GitHub and latest <a href="http://wikipediaviewer.yingjiehu.com" target="_blank">updated website</a>
  </div>
</body>

              
            
!

CSS

              
                body {
  background-color: rgb(13, 38, 56) !important;
  color: silver !important;
  padding: 20px;
  font-size: 14px;
  margin: auto;
}

#search-icon {
  color: rgb(212, 99, 44);
  font-size: 2em;
  margin: 20px;
}

#footer {
  position:relative;
  bottom:20px !important;
  font-size: 14px;
  left: 0px;
  right: 0px;
  margin-top: 40px;
}

clear {
  cursor: pointer;
}

a {
  color: rgb(212, 99, 44) !important;
}
a, a:hover, a:active, a:visited{
  text-decoration: none !important;
}

*:focus {outline: none;}

.form {
  margin-top: 35%;
}
#form input{
  border: 0px;
  background-color: rgb(13, 38, 56);
  color: white;
  width: 300px;
  border: 5px solid;
  border-color: rgb(212, 99, 44);
  border-radius: 20px;
  display: inline-block;
  float: center;
}

#form button {
  color: rgb(212, 99, 44);
  background-color: rgb(13, 38, 56);
  border: 0px;
  display: inline-block;
  float: center;
}

.formbutton {
  border-radius: 20px;
  border: 2px solid rgb(212, 99, 44);
  padding: 6px;
  background-color: rgb(212, 99, 44);
  color: rgb(13, 38, 56) !important;
  font-weight: bold;
  margin-bottom: 20px;
}

#wiki {
  border: 1px solid rgb(212, 99, 44);
  border-radius: 10px;
  margin-top: 40px;
}
.search-url{
  cursor: pointer;
}

.search-block{
  background-color: #ffffff;
  margin: 20px 20px 20px 30px;
  padding: 20px;
  color: rgb(13, 38, 56);
  border-left: 10px solid transparent;
}

.search-block:hover {
  border-left: 10px solid rgb(212, 99, 44);
}

.search-title{
  text-align: left;
  font-weight: bold;
}

.search-result{
  text-align: left;
}

.searchmatch {
  color: rgb(212, 99, 44);
}

.no-result{
  padding: 20px;
  font-size: 20px;
}

.fa {
  display:inline !important;
}

              
            
!

JS

              
                var searchTerm;
$(document).ready(function() {
  $("#clear").click(function(){
    $("#wiki").hide("");
    $("form").addClass("form");
    $("#term").val("");
  });

  $("#form").submit(function(){
    $(this).removeClass("form");
    event.preventDefault();
    var term =  $('#term').val();
    //console.log("term is: " + term);
    var url = createURL(encodeURI(term));
    //window.open(url,'_blank');

    $.getJSON(url, function(json){
      var contents = json.query.search;
      //console.log(contents);
      var html = "<div id='wiki'>";
      if(contents.length == 0) {
        html += "<div class='no-result'>No results found. Try again ! <div style='font-size: 40px'><i class='far fa-smile'></i><div></div>";
      } else {
        for(var i = 0; i < contents.length; i++){
          //console.log("i=",i, ", title", contents[i].title);
          //console.log(contents[i].snippet);
          html += "<a class='search-url' href='https://en.wikipedia.org/?curid=" + contents[i].pageid + "' target='_blank'><div class='search-block'>"
          html += "<p class='search-title'>" + contents[i].title + "</p>";
          html += "<div class='search-result'>" + contents[i].snippet + "</div>";
          html += "</div></a>";
        }
      }
      html += "</div>";
      $("#contents").html(html);
    });

  });

  function createURL(term){
    return "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=" + term + "&origin=*";
  }

});

              
            
!
999px

Console