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

              
                  <div class="container">
    	<div class="col-lg-12 text-center">
        <h1>Search Wikipedia</h1>
        <a target="_blank" href="https://en.wikipedia.org/wiki/Special:Random"><i class="glyphicon glyphicon-random" data-toggle="tooltip" title="Click for a random article!" data-placement="right"></i></a>
        <p class="deskHide"><br>Random Article</p>
        <div class="form">
        <input type="text" class="rounded" id="search" autocomplete="off">
        <i class="glyphicon glyphicon-remove" id="close"></i>
        <i class="glyphicon glyphicon-search" data-toggle="tooltip" title="Click to search!" data-placement="right" id="searchIcon"></i>
        <p class="deskHide searchMobile">Click to search</p>
      </div>
      <div id="father"></div>
    	</div>
    </div>
    <div class="footer">Created by <a href="https://codepen.io/BobbyMcwho" target="blank">Bobby McDonald</a></div>
              
            
!

CSS

              
                body {
    background-color: #607D8B;
    color:#ECEFF1;
    font-family: 'Raleway', sans-serif;
}
.container{
    margin-top:25vh;
    transition: margin-top 1s
}
.containerUp {
  margin-top:10vh;
}
.rounded{
  color:#ECEFF1;
  width:0;
  transition: width 1s;
  background: transparent;
  border:none;
  font-size: 1em;
  margin-bottom: 1em;
}
.rounded:focus {
  outline: none;
  border-bottom: 2px solid #ECEFF1;
}
.rounded-focus {
  width: 70%;
  border-bottom: 2px solid #ECEFF1;
  transition: width 1s;
}
i {
font-size:2em;
  color:#ECEFF1;

}
@media only screen and (min-width: 768px){
  .rounded{
    font-size: 3em;
  }
  .rounded-focus {
    width: 25vw;
    font-size: 3em;
}
.deskHide{
  display: none;
}
i {
font-size:3em;
}
}
i:hover {
  cursor: pointer;
}
h1{
  font-family: 'Raleway', sans-serif;
}
.glyphicon-remove  {
  display: none;
}
.son{
  background-color: #ECEFF1;
  color: #37474F;
  padding: 1em .5em 1em .5em;
  margin: 1em 0 1em 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.son:hover {
  box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}
.son .cardHead{
padding: 0;
margin: 0;
color:#BF360C;
font-weight: 700;
}
.son p {
  padding: 0;
  margin:0;
}
.footer{
  text-align: center;
  color: #ffffff;
  font-family: 'Raleway', sans-serif;
  padding-bottom:20px;
}
.footer a{
  color: #8BC34A;
  font-weight: 700;
}
.footer a:hover{
  color: #FF5722;
  font-weight: 700;
  text-decoration: none;

}
.footer a:focus{
  text-decoration: none;
}

.card:active, .card:visited, .card:hover,.card{
  text-decoration: none;
  color: #FF5722;
}
.deskHide {
  margin-top:-15px;
  font-family: 'Raleway', sans-serif;
}

              
            
!

JS

              
                $(document).ready(function() {
 //Set global variables
  var query = "";
  var queryResults = [];
//Query Wikipedia API for input value (as var query)
  function wikiSearch() {
    $.ajax({
      type: 'GET',
      crossDomain: true,
      dataType: 'json',
      url: ('https://en.wikipedia.org/w/api.php?action=opensearch&search=' + query + '&limit=10&namespace=0&format=json&callback=?'),
      success: (function(e) {
        queryResults = e;
      }),
      complete: function() {
        //Run our loop on the queryResults
        if (queryResults[1] == ""){$('#father').append('<a class="card" target="_blank">' + '<div class="son"><h2 class="cardHead">No results found.</h2>' + '<br>' + '<p>Try another search query!</p></div></a>');;}
        else loopResults(queryResults);
      }
    });
  }
//Define Loop that will append divs with query information 
  function loopResults(a) {
    var i = 0;
    for (i = 0; i < a[1].length;i++) {
      $('#father').append('<a class="card" target="_blank" href=' + a[3][i] + '>' + '<div class="son"><h2 class="cardHead">' + a[1][i] + '</h2>' + '<br>' + '<p>' + a[2][i] + '</p></div></a>');
    }
  }
  //On Search Icon click: 
  //1. Hide tooltip (important on mobile) 
  //2. Hide "Click to search" text (only shown on mobile)
  //3. Add Class "Rounded-focus to prompt animation
  //4. Fade out the Search Icon, and upon completion, fade in the Close icon
  $("#searchIcon").click(function() {
    $('[data-toggle="tooltip"]').tooltip('hide');
    $('.searchMobile').css("display", "none");
    $("#search").toggleClass("rounded-focus", "rounded:focus").focus();
    $("#searchIcon").fadeOut(200, function() {
      $("#close").fadeIn(200);
    });
  });
  //On Search field blur (don't need to define close icon on.click due to Text field losing blur when clicking it anyways: 
  //1. Show "Click to search" text (only shown on mobile)
  //2. Remove Class "Rounded-focus to prompt animation close
  //4. Fade out the Close Icon, and upon completion, fade in the Search icon
  $("#search").blur(function() {
    $("#search").removeClass("rounded-focus", "rounded:focus");
    $("#close").fadeOut(200, function() {
      $("#searchIcon").fadeIn(200);
      $('.searchMobile').css("display", "");
    });
  });
  //When text input is active, when enter is pressed:
  //1. Set value of text box to a variable, vall
  //2. Set our global query variable to the encodedURIcomponent of vall. 
  //3. Clear all existing children divs in the #father div. 
  //4. Run our wikiSearch function
  //5. Animate our main container div to have smaller margin-top
  $('#search').keypress(function(e) {
    if (e.keyCode == 13 && $('#search').val() !== "") {
      var vall = $('#search').val();
      query = encodeURIComponent(vall);
      $('#father').html("");
      wikiSearch();
      $(".container").addClass("containerUp");
    }
  });
  //Make our tooltips look nice
  $('[data-toggle="tooltip"]').tooltip();
});
              
            
!
999px

Console