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

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

              
                									<div id="search_wrap">
	<h1>Wikipedia Search</h1>
	<div class="search">
		<input id="search" autocomplete="off" placeholder="Search for entry"></input>
		<span id="search_icon_line"></span>
	</div>
	<p><a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">Random Wikipedia entry</a></p>
</div>
<div class="results"></div>
              
            
!

CSS

              
                body,
html {
	width: 100%;
	height: 100%;
	margin: 0;
	background: #1c4a4a;
	font-family: Tahoma, arial;
}

#search_wrap {
	padding-top: 20vh;
	margin-bottom: 2em;
	text-align: center;
	-webkit-transition: margin-top 0.8s ease-in-out;
	transition: padding-top 0.8s ease-in-out;
}

#search_wrap.top {
	padding-top: 2em;
}

#search_wrap h1 {
	font-size: 2.4em;
}
.search {
	position: relative;
	width: 20em;
	height: 4em;
	margin: 0 auto;
}
#search_icon_line {
	position: absolute;
	left: calc(10em - 0.2em);
	top: 3.6em;
	height: 1.4em;
	width: 0.4em;
	background-color: white;
	-webkit-transform: rotateZ(-0.1turn);
	transform: rotateZ(-0.1turn);
	-webkit-transform-origin: 0 -1.8em;
	transform-origin: 0 -1.8em;
	-webkit-transition: all 0.4s 0.5s;
	transition: all 0.4s 0.5s;
}

#search:focus + #search_icon_line {
	-webkit-transform: rotateZ(0turn);
	transform: rotateZ(0turn);
	-webkit-transition-delay: 0s;
	transition-delay: 0s;
	opacity: 0;
}

.result_list > a > div {
	max-width: 100%;
	width: 60em;
	min-height: 8em;
	margin: 0em auto;
	padding: 0 1em;
	box-sizing: border-box;
	border-left: 0.2em solid rgba(0, 0, 0, 0);
}

.result_list > a > div:hover {
	-webkit-transition: border 0.2s linear;
	transition: border 0.2s linear;
	border-left-color: rgba(0, 0, 0, 1);
}

.result_list > a > div h4 {
	font-size: 1.2em;
	text-indent: 10%;
	margin: 0;
}

.result_list > a >div p {
	color: white;
}

a {
	text-decoration: none;
	font-size: 1.1em;
	color: #6bc7c7;
}

a:hover {
	color: #318181;
}

input {
	border: 0.3em solid white;
	border-radius: 2em;
	height: 1em;
	width: 1em;
	padding: 0.8em;
	color: rgba(0, 0, 0, 0);
	font-size: 1.2em;
	background: rgba(255, 255, 255, 0.5);
	box-shadow: inset 0 0 0.5em rgba(0, 0, 0, 0.1), 0 0 1em rgba(0, 0, 0, 0.4);
	cursor: pointer;
	-webkit-transition: width 0.6s ease-in-out;
	-webkit-transition: width 0.6s ease-in-out, color 0.6s 0.2s;
	transition: width 0.6s ease-in-out, color 0.6s 0.2s;
}

input:focus {
	width: 14em;
	color: #153737;
	-webkit-transition-delay: 0.4s;
	transition-delay: 0.4s;
	cursor: auto;
}
              
            
!

JS

              
                var nr_results = 10;
var preview_length = 200;

$(document).ready(function() {

	// Search
	$('#search').keypress(function(e) {
		if (e.which == 13) {
			// Move Searchfield to top
			$('#search_wrap').addClass("top");
			// Search
			searchWikiEntries($(this).val());
		}
	});

	// Clear input when moving out
	$('#search').focusout(function() {
		setTimeout(function() {
			$('#search').val('');
		}, 600);
	});

});

// Search Wikipedia for the title
function searchWikiEntries(title) {
	if (title === "")
		title = "Stupidedia";
	var lang = "en";
	
	var url = "http://" + lang + ".wikipedia.org/w/api.php?format=json&action=opensearch&search=" + title + "&limit=" + nr_results + "&prop=revisions&rvprop=content&callback=?";
	console.log(url);
	// Get data from wikipedia-api
	$.getJSON(url)
		.done(function(response) {
			alert("done");
			showResponse(response);
		})
		.fail(console.error);
}

// Insert the response
function showResponse(response) {
	alert("showResponse")
	var old_res = '.results .result_list:first-child';
	var new_res = '.results .result_list:last-child';

	$(old_res).fadeOut(200).queue(function() {
		$(this).remove();
	});

	$('.results').append('<div class="result_list"></div>');
	$(new_res).hide();

	var result = '';
	
	// Error?
	if (typeof response === "undefined" || response[1].length === 0) {
		result = '<a href="#"><div><h4>No result found</h4></div></a>';
	}
	// If no errors found
	else {
		for (var i = 0; i < response[1].length; i++) {
			// Get data
			var title = response[1][i];
			var preview = response[2][i];
			if (preview.length > preview_length)
				preview = preview.substr(0, preview_length - 3) + '...';
			var link = response[3][i];
			// Append to result
			result += '<a href="' + link + '" target="_blank"><div><h4>' + title + '</h4><p>' + preview + '</p></div></a>'
		}
	}
	$(new_res).append(result);
	$(new_res).delay(200).fadeIn();

}
              
            
!
999px

Console