css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <head>
  <title>WikiView App</title>
  <link href="https://fonts.googleapis.com/css?family=Anton|Crimson+Text" rel="stylesheet">
</head>
<body class='container'>
  <img src="https://upload.wikimedia.org/wikipedia/commons/1/15/Wikipedia_logo_bronce.png" alt="wikiView logo" />
  <h1>WikiView</h1>
  <input id='searchField' type='text' placeholder='Search' autocomplete="on"/>
  <button class='btn btn-success'>Go</button>
  <div id='output'><div id='output'><h5>Enter some text to search Wikipedia entries!</h5></div></div>
</body>
            
          
!
            
              /* Main Styles */
body {
  text-align: center;
  background: #4C3957;
  font-size: 1rem;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

a:link,
a:hover, 
a:active,
a:visited {
  text-decoration: none;
}

h1 {
  color: #fff;
  margin-top: 15px;
  font-size: 4rem;
}

h4 {
  font-size: 2.2rem;
}

h5 {
  color: #fff;
  font-family: 'Crimson Text', serif;
  font-size: 1.8rem;
}

input {
  border-radius: 5px;
  padding: 5px;
  margin-right: 8px;
  text-align: center;
  font-size: 1rem;
}

input:focus {
  outline: none;
  box-shadow: 0px 0px 5px  #4D90FE;
}

p {
  font-size: 1.5rem;
  font-family: 'Crimson Text', serif;
}

img {
  width: 120px;
  height: 120px;
  margin-top: 50px;
}

/* Classes, IDs */

#output {
  margin-top: 50px;
}


.output-card {
  margin: 30px 0;
  padding: 15px;
  border: 1px solid #ccc;
  background: #fff;
  box-sizing: border-box;
  border-radius: 4px;
}

.output-card:hover {
  border: 1px solid #006989;
  box-shadow: 0px 0px 2px  #4D90FE;
  
}

.output-card h4, p {
  text-align: left;
  margin-left: 12px;
}
            
          
!
            
              //Api docs link
//https://www.mediawiki.org/wiki/API:Query#Sample_query

//sample api GET request link https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json

//fetch request
//link + searchTerm
let wikiLink = `https://en.wikipedia.org/w/api.php?action=query&origin=*&format=json&list=search&srsearch=`;
let searchTerm = document.getElementById('searchField');
var output = document.getElementById('output');
let $outputButton = $('button');
//create new header and set it for request

//capitalize first letter of result 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

//output button
$outputButton.on('click', function (e) {
  //request to MediaWiki
  let url = wikiLink + searchTerm.value;
  //fetch data from MediaWiki
  fetch(url)
    .then(resp => resp.json())
    .then(function (data) {
      let html='';
      let activeLink = 'https://en.wikipedia.org/wiki/';
      //map over items and build out content
      data.query.search.map(function (item) {
        html += `<section class='output-card'>
                  <a href='${activeLink}${item.title}' target='_blank'>
                    <h4>${item.title}</h4>
                    <p>${capitalizeFirstLetter(item.snippet)}.</p>
                  </a>
                  </section>`;
        output.innerHTML = html;
      });
    });
  });

//event listener on inout field
searchTerm.addEventListener('keyup', function (event) {
    //request to MediaWiki
    let url = wikiLink + searchTerm.value;
    //fetch data from MediaWiki
    fetch(url)
    .then(resp => resp.json())
    .then(function (data) {
      let html='';
      let activeLink = 'https://en.wikipedia.org/wiki/';
      //map over items and build out content
      data.query.search.map(function (item) {
        html += `<section class='output-card'>
                  <a href='${activeLink}${item.title}' target='_blank'>
                    <h4>${item.title}</h4>
                    <p>${capitalizeFirstLetter(item.snippet)}.</p>
                  </a>
                  </section>`;
        output.innerHTML = html;
      });
    });
});


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console