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

              
                <html >
<head>
  <meta charset="UTF-8">
  <title>WikiViewer</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="css/style.css">

    <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
<style>
  input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: searchfield-cancel-button;
  }
</style>
</head>

<body>
  <div class="container">
  <div class="mo-title mo-box text-center">
  <p>WikiViewer
        <button id="mo-random" class="btn btn-primary mo-button"> Random!
  </button></p>
  <div class="form-group">
    <input type="search" class="form-control" placeholder="Search" id="search" />
</div>
    </div>
<div class="mo-results">
  </div>
 <div class="mo-credit mo-box text-center">
  by <a href="https://codepen.io/pcblues">Mark Daniel Osborne</a>
</div>

<div class="mo-log">
</div>

</div>  
    <script src="js/index.js"></script>

</body>
</html>

              
            
!

CSS

              
                .mo-button
{
  background:#AABBCC;
}

.mo-box
{
  background: #66AAFF;
    border-radius: 8px;
    margin-top: 10px;
    margin-bottom: 10px;
    padding:0 15px 0 15px;

}
  
.mo-title 
  {
    font-family:  sans-serif;
    font-size: 50px;
    padding:10px 15px 10px 15px;

  }

  .mo-icon
  {
    background-size: 100px;
    background-repeat: no-repeat;
     background-position: center;
     min-height:100px

  }

  

.mo-credit
  {
    font-family:  sans-serif;
    font-size: 15px;

  }


#searchClear {
    position: absolute;
    right: 5px;
    top: 0;
    bottom: 0;
    height: 14px;
    margin: auto;
    font-size: 14px;
    cursor: pointer;
    color: #CCC;
}

.mo-results
{

}

.mo-result-box
{
    background:#AABBCC;
    border-radius: 8px;
    margin-top: 15px;
    padding:10px 15px 10px 15px;

}

.mo-result-title
{
    font-size: 25px;  
}
              
            
!

JS

              
                /*
TODO:
Button for random wikipedia entry
Search field
Show results

DONE:
Title

----------
Objective: Build a CodePen.io app that is functionally similar to this: https://codepen.io/FreeCodeCamp/full/wGqEga/.

Fulfill the below user stories. Use whichever libraries or APIs you need. Give it your own personal style.

User Story: I can search Wikipedia entries in a search box and see the resulting Wikipedia entries.

User Story: I can click a button to see a random Wikipedia entry.

Hint #1: Here's a URL you can use to get a random Wikipedia article: var popup = $window.open("about:blank", "_blank");https://en.wikipedia.org/wiki/Special:Random.

Hint #2: Here's an entry on using Wikipedia's API: https://www.mediawiki.org/wiki/API:Main_page.

Hint #3: Use this link to experiment with Wikipedia's API:
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=jsonfm

*/

var randomWiki = function () {
  var win = window.open('https://en.wikipedia.org/wiki/Special:Random', '_blank')
  if (win) {
      //Browser has allowed it to be opened
      win.focus()
  } else {
      //Browser has blocked it
      alert('Please allow popups for this website')
  }
  }
  
  var searchWiki = function(searchTerm) {
    addLog("Searching Wiki for "+searchTerm)
       // .getJSON(url,data,success)
   // jHXR .done, .fail, .always
   
  addLog("Running getJSON...");
  var CORS = "https://cors-anywhere.herokuapp.com/"
  var wikiURL = CORS+"http://en.wikipedia.org/w/api.php"
  
  addLog(wikiURL);
  $(".mo-results").html("")
  $.getJSON( wikiURL,{ action: 'query', list: 'search', srsearch: searchTerm, format: 'json' },
  function(result) 
     {
       addLog("Done 1...");  
       var search=result.query.search
       for (var result of search) {
         var resultLink = "http://en.wikipedia.org/wiki/"+result.title
         var resultBlock = "<a href=\""+resultLink+"\" target=\"_blank\">"
         resultBlock += "<div class=\"mo-result-box\"><p class = \"mo-result-title\"><b>"+result.title+"</b></p>"
         resultBlock += result.snippet

         resultBlock+="</div></a> "
       $(".mo-results").append(resultBlock) 
       }   
     })
   .done(
     //function() {addLog("Done 2...");}
   )
  .fail(
         function( jqXHR, textStatus, errorThrown )
         {
          var errText = "Fail...<BR>"+textStatus+"<BR>"+errorThrown+"<BR>"
           addLog(errText)
        } 
  )
  .always(     
    //function() {addLog("Always...");}
  )
}


$(document).ready(function() {
  addLog("Document Ready")

  document.getElementById("mo-random").addEventListener("click",randomWiki
  )// addeventlistener
  $("#search").keypress(function(e)
  {
    if ((e.keyCode || e.which) == 13) {
      searchWiki($(this).val())
    }
  })

})

var addLog = function(msg) {
  //$(".mo-log").append(msg+"<BR>")
  console.log(msg)
}


              
            
!
999px

Console