cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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 lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

	<title>Wikipedia Viewer</title>

	<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
</head>

<body>

<div class="flexbox-container full-height" id="container">
	<div id="search">
		<input placeholder="Search ..." type="text" value="" name="search" id="searchQuery">
		<button id="searchButton"><i class="fa fa-search"></i></button>
		<button onclick="location.href='https://en.wikipedia.org/wiki/Special:Random'"><i class="fa fa-random"></i></button>
	</div>
</div>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/index.js"></script>

</body>
</html>
            
          
!
            
              /********** GLOBAL STYLES **********/

html, body {
	height: 100%;
	margin: 0;
}

body {
	background-image: url("https://raw.githubusercontent.com/WesDowney/freeCodeCamp/d9f9fc5d96432bf19b902a02d7788b9db8365a68/front-end-development-certification/Intermediate-Front-End-Development-Projects/Build-a-Wikipedia-Viewer/img/background.jpg");
    background-repeat: repeat;

	-webkit-font-smoothing: antialiased;
	text-rendering: optimizelegibility; 
}

a {
	text-decoration: none;
}

p {
	color: black;
}

/********** SEARCH BOX SECTION **********/

.flexbox-container {
	display: flex;
	display: -ms-flexbox;
	display: -webkit-flex;
  display: -moz-box;

	flex-direction: column;
	align-items: center;
	-ms-flex-align: center;
	-webkit-align-items: center;
	-webkit-box-align: center;
	justify-content: center;
}

.vert-align-top {
	align-items: flex-start; 
	-ms-flex-align: flex-start;
	-webkit-align-items: flex-start;
	-webkit-box-align: flex-start;
}

.full-height {
	height: 100%;
}

#search {
	background: white;
	text-align: center;
	padding: 10px;
	border: 2px solid black;
	border-radius: 10px;
	box-shadow: 3px 3px 3px black;
	-moz-box-shadow: 3px 3px 3px black;
  -webkit-box-shadow: 3px 3px 3px black;
	font-family: 'Open Sans', sans-serif;
	margin: 10px auto 10px;
}

#searchQuery {
	display: none; /* Hide it until the button is pressed */
	width: 350px;
	height: 75px;
	font-size: 50px;
}

button {
	font-size: 50px;
}

button {
	background: rgb(86, 117, 154); /* dark blue */
	color: white;
	border-radius: 10px;
	width: 75px;
	height: 75px;
}

button:hover {
	background: rgb(203,213,224); /* light blue */
	cursor: pointer;
	color: black;
}

/********** SEARCH RESULTS SECTION **********/

.article {
	background: white;
	width: 70%;
	padding: 10px;
	border: 2px solid black;
	border-radius: 10px;
	box-shadow: 3px 3px 3px black;
	-moz-box-shadow: 3px 3px 3px black;
    -webkit-box-shadow: 3px 3px 3px black;
	font-family: 'Open Sans', sans-serif;
	margin: 10px auto 10px;

	/* Enable hardware acceleration to fix laggy transitions */
	-webkit-transform: translateZ(0);
	-moz-transform: translateZ(0);
	-ms-transform: translateZ(0);
	-o-transform: translateZ(0);
	transform: translateZ(0);

	transition: all 150ms ease;
}

.article:hover {
	width: 73%;
}
            
          
!
            
              var searchButton = document.getElementById('searchButton');


function searchWikipedia() {
	
	var searchTerm = document.getElementById("searchQuery").value;
	var remoteUrlWithOrigin = 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + searchTerm;

	// Query the Wikipedia API
	$.ajax( {
	    url: remoteUrlWithOrigin,
	    dataType: 'jsonp', // jsonp helps with cross origin error
	    type: 'GET',
	    headers: { 'FCC Wikipedia Viewer App': 'v.1' }, // Wikipedia API requires custom user agent
	    success: function(data) {
	    	// alert(JSON.stringify(data, null, 4)); // Shows the whole returned object nicely formatted for debugging 
	    	/* 
	    		API Data Response:
			    	data[1] are titles
			    	data[2] are descriptions
			    	data[3] are links
		    */ 

	    	// Change the search box to align to vertically align top
	    	var container = document.getElementById("container");
			container.className = "flexbox-container vert-align-top";

			// Create the new div that will hold the search results
			var searchResults = document.createElement('div');
			searchResults.id = 'searchResults';
			// searchResults.className = "flexbox-container vert-align-top";

			// Append the search results div to body below the search box
			document.getElementsByTagName('body')[0].appendChild(searchResults);

			// Create an inner divs for each article
			for (var i = 0; i < data[1].length; i++) {
				var article = document.createElement('div');
				article.className = 'article';

				// Add the title, description and link
				article.innerHTML = '<a href="' + data[3][i] +'"><h2>' + data[1][i] + '</h2>\
									<p>' + data[2][i] + '</p></a>';

				// Append the article to the search results div
				searchResults.appendChild(article);
			}
	    }
	} );

}

$(document).ready(function(){
	var searchBoxOpen = false;

	$("#search").fadeIn( 800 );

    $("#searchButton").click(function(){
    	if (searchBoxOpen == false) {
    		$("#searchQuery").animate({
            	width: 'toggle'
        	});

        	// When the search box is opened, set the cursor there for typing
        	$('#searchQuery').focus();
        	searchBoxOpen = true;
    	} else if (document.getElementById("searchQuery").value.length == 0) {
    		// The search box is open but the value is empty. Close the search box.
    		$("#searchQuery").animate({
            	width: 'toggle'
        	});
        	searchBoxOpen = false;
    	} else {
    		$( ".article" ).remove();
    		searchWikipedia();
    	}
    });

    // If the user presses the enter button while typing in the search box, submit the search button
    $("#searchQuery").keyup(function(event){
	    if(event.keyCode == 13){
	        $("#searchButton").click();
	    }
	});
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console