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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <h1>Wikipedia Viewer</h1>
  <a href="http://en.wikipedia.org/wiki/Special:Random" id="random-article" target="_blank">Go to a random article</a> <br>
  
  <input type="text" id="search-bar" placeholder="enter your query here..."/> <br>
  <button style="background: none; border: none; outline: none" id="search-click"><img src="http://www.annarborcil.org/wp-content/themes/aacil/img/widgets/search_widget_icon.png" alt="Search Icon" id="search-icon" /></button> <br>
  
  <div id="possible-results">
  </div>
  
</body>
              
            
!

CSS

              
                
body {
  background: #0A2A2E;
  margin-top: 2%;
  text-align: center;
}

h1 {
  color: #F0F7BB;
  font-family: "Courier New", sans-serif;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#search-bar {
  width: 80%;
  margin: 1% 5px;
  padding: 5px 5px;
  border: solid 4px #ADCF10;
  background: #11464C;
  color: #fffafa;
  font-family: "Courier New", serif;
  font-weight: bold;
  font-size: 18px;
  outline: none;
}

#search-icon {
  width: 20px;
  margin: 10px 0;
}

#search-icon:hover {
 opacity: 0.8; 
 filter: alpha(opacity=80);
}

#search-icon:active {
  opacity: 0.7;
}

#random-article {
  text-decoration: none;
  color: #DEDDD8;
  text-transform: uppercase;
  display: inline-block;
  margin-top: 16%;
  font-size: 18px;
  margin-right:
}

#random-article:hover {
  color: #F0F7BB;
}

.search-entries {
  overflow: hidden;
  background: #11464C;
  border: solid 4px #BFB60E;
  margin: 20px 10px;
  width: 80%;
  height: 80px;
  display: inline-block;
  text-align: center; 
  overflow-y: auto;
}

.search-entries a {
  text-transform: uppercase;
  color: #FFFAFA;
  font-family: "Georgia", serif;
}

.search-entries a:hover {
  color: #eee;
}

.search-entries p {
  color: #fffafa;
  font-family: "Courier New", sans-serif;
  font-size: 15px;
  letter-spacing: 0.1px;
}

.search-entries p:before, .search-entries p:after {
  content: '"';
}
              
            
!

JS

              
                $(document).ready(function(){
  
  $("#search-click").on("click", wikiData); 
  
  // Search if "enter" is pressed
  $("#search-bar").keyup(function(event){
    if(event.keyCode == 13){
        $("#search-click").click();
    }
  });
  // /Search if "enter" is pressed
  
  // Get the Wikipedia API
  function wikiData(){
    var userText = $("#search-bar").val().replace(/\s+/g, "%20");
    var wikiUrl = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + userText + "&callback=?";
    
    $.getJSON(wikiUrl)
    
    .done(generate)
    .fail(error)
  }
  // /Get the Wikipedia API
  
  // Main function (run if url is valid)
  function generate(json){
    
   /* clear div */ 
   $("#possible-results").html('');
    
   /* check to see if text was entered in search bar */ 
   if ($("#search-bar").val().length > 0 ) {
    /* if no results were found, append this div */ 
    if(json[1].length === 0 || json[3].length === 0) {
      $("#possible-results").append("<div class='search-entries' style='line-height: 70px'><a> Your search turned no results. Sorry about that! </a> </div> <br>")
   } else {
     /* go through every name and link in the json object and append them to html */
     for (i = 0; i < json[1].length; i++) {
        /* if the sample text is too small center the title in the div and don't add the text */       
        if(json[2][i].length < 40 ) {
          $("#possible-results").append("<div class='search-entries' style='line-height: 70px'><a href='" + json[3][i] + "' target='_blank'>" + json[1][i] + "</a> </div> <br>")
      } else {        
        /* add the sample text from the json */
          $("#possible-results").append("<div class='search-entries'><a href='" + json[3][i] + "' target='_blank'>" + json[1][i] + "</a>" + "<p>" + json[2][i] + "</p> </div> <br>");
    }
   }  
  } 
  } else {
       /* if the button was pressed but search-bar was empty alert error message */
       
       alert("Unable to search Wikipedia Database. Please enter at least one character in the input field."); 
   }   
  } 
  // /Main function (run if url is valid)
  
  // Secondary function (run if url is not valid)
  function error(){
    alert("Unable to pull information from Wikipedia. Sorry about that!");
  } 
  // /Secondary function (run if url is not valid)
  
})
              
            
!
999px

Console