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 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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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 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
🕑 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