Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- hyperlinks: target="_blank" for codepen.io -->
  <div class="h-100 d-flex justify-content-center align-content-between flex-wrap">
    <div class="container text-center p-3">
      <h1>myWikipedia</h1>
      <span><em>An alternative Wikipedia landing page.</em></span>
      <p id="message" class="text-red"></p>
      <div class="row justify-content-center">
        <div class="col-12 col-sm-6 col-md-7 col-lg-8 py-0 py-sm-3 text-right">

          <div class="input-group">
            <input id="search-keywords" type="text" class="form-control" placeholder="Search for an article...">
            <span class="input-group-btn">
              <button id="search-btn" class="btn btn-warning">Go!</button>
            </span>
          </div>

        </div>
        <div class="col-12 col-sm-1 col-md-1 col-lg-1 py-1 align-self-center text-center">
          <span>or</span>
        </div>
        <div class="col-12 col-sm-5 col-md-4 col-lg-3 pt-0 pb-3 py-sm-3 text-center text-sm-left">
          <a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">
            <button type="button" class="btn btn-warning">Get a Random Entry!</button>
          </a>
        </div>
      </div>
    </div>

    <div class="container mx-2">
      <div id="search-results" class="list-group row">
      </div>
    </div>

    <div class="container p-3 w-100">
      <p class="text-center">Coded by <a class="text-danger" href="http://gregwong.me">Greg Wong</a></p>
    </div>
  </div>
              
            
!

CSS

              
                html, body {
  height: 100%;
  background-color: #FFE3B7;
}

.content-entry {
  background-color: #FFEFD6;
  padding-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgb(223,223,223);
  color: #603B01;
}

.content-entry:focus, .content-entry:hover {
  background-color: #FFD695;
  color: #A06200;
}

.text-red {
  color: red;
}

              
            
!

JS

              
                $('input#search-keywords').keypress(function (e) {
    var code = e.keyCode || e.which;
    $("p#message").text("");
    if (code === 13){
      e.preventDefault();
      searchStart();
    }
});

$('button#search-btn').click(function(){
  searchStart();
});

function searchStart(){
  $("p#message").text("Searching...");
  var keywords = $("input#search-keywords").val();
  if (keywords != ""){
    var url = "https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=1&explaintext=1&titles=&generator=search&gsrsearch="+keywords +"&callback=?";
    $.getJSON(url).done(searchDone).fail(function(){
      $("p#message").text("Search results failed to load. Try again later!").effect("shake");
    });
  }
  else {
    $("p#message").text("Search bar is empty!");
    $("input#search-keywords").parent().effect("shake");
  }
}

function searchDone(json){
    $("p#message").text("");
    var entries = "";
    var pages = json.query.pages;
    for (var pageid in pages){
      var href = "https://en.wikipedia.org/wiki?curid=" + pageid ;
      var title = pages[pageid].title;
      var extract = pages[pageid].extract;
      var entry = '<a href="' + href + '" class="list-group-item content-entry" target="_blank"><h5 class="w-100">' + title + '</h5><span>' + extract + '</span></a>';
      entries = entries.concat(entry);
    }
    $("div#search-results").empty().append(entries).hide().fadeIn("slow", function() { });
}

$('div#search-results').on('click', 'a.content-entry',function(){
  // without this, the selected entry stays highlighted
  $(this).blur();
});

              
            
!
999px

Console