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

              
                		<div class="container text-center searchBox">
			<h1>WikipediA Viewer</h1>
			<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3">
				<form class="form-inline" id="form-container" role="form">
					<div class="form-group">
						<input type="text" id="searchText" class="form-control" placeholder="search WikipediA" required>
						<button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-search"></i></button>
						<a href='https://en.wikipedia.org/wiki/Special:Random' target="_blank" class="btn btn-primary" role="button"><i class="glyphicon glyphicon-random"></i></a>
					</div>
				</form>
			</div>
		</div><!--container-->

		<div class="container">
			<div class="row">
				<div id="results"></div>
			</div>
		</div>
              
            
!

CSS

              
                .form-inline .form-group .form-control {
	width: auto;
	display: inline-block;
	border-radius: 0;
}

.searchBox {
	font-family: 'Linux Libertine','Hoefler Text',Georgia,'Times New Roman',Times,serif;
}

.btn {
	border-radius: 0;
}

.result {
	background-color: #e7e7e7;
	margin-top: 10px;
}

a {
	color: black;
}

h4 {
	color: #337ab7;
}

.result:hover {
	border-left: 5px solid #337ab7;
}

.searchmatch {
	font-weight: bold;
}
              
            
!

JS

              
                // Autocomplete adapted from https://codepen.io/edkahara/pen/ZpvXxB
$("#searchText").autocomplete({
	source: function(request, response) {
		$.ajax({
			type: "GET",
			url: "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + request.term + "&format=json&callback?",
			dataType: "jsonp",
			success: function(data) {
				response(data[1]);
			},
		});
	},
	// Submit on select credit http://stackoverflow.com/questions/2198539/jquery-autocomplete-submit-form-on-selection
	select: function(event, ui) { 
		$("#searchText").val(ui.item.value);
		$("#form-container").submit(); 
	}

});
// Close autocomplete dropdown on enter	http://stackoverflow.com/questions/9602395/jquery-ui-autocomplete-hide-list-after-hiting-enter
$("#searchText").keypress(function(e){ 
	if (!e) e = window.event;   
	if (e.keyCode == "13"){
		$("#searchText").autocomplete("close");
		$("#form-container").submit();
		return false;
	}
  });

// On submit, query the wikipedia api
$("#form-container").submit(function(event) {
	event.preventDefault();

	var searchTerm = $("#searchText").val();
	var wikiUrl = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" + searchTerm + "&format=json";

	$.ajax({
		type: "GET",
		url: wikiUrl,
		dataType: "jsonp",
		headers: {
			"Api-User-Agent": "Example/1.0"
		},
		success: function(response) {
			// Remove previous results
			$("#results").html("");
			// Check for errors
			if (response.hasOwnProperty("error")) {
				$("#results").append('<div class="text-center col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2 result"><h4>Error encountered. Please try again later!</h4></div>');
			// Check for no results
			} else if (response.query.search.length === 0) {
				$("#results").append('<div class="text-center col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2 result"><h4>No Results Found</h4></div>');
			} else {
				var result = response.query.search;
				// Loop through response array and append results
				for (var i = 0; i < result.length; i++) {
					var endUrl = result[i].title.replace(/ /g, "_");
					var title = result[i].title;
					var snippet = result[i].snippet;
					$("#results").append('<a href=http://en.wikipedia.org/wiki/' + endUrl + ' target="blank_"><div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2 result"><h4>' + title + '</h4><p class="description"><p>' + snippet + '<p></div></a>');
				}
			}
		},
		error: function() {
			$("results").html("Error encountered. Please try again later!");
		}  
	});
});
              
            
!
999px

Console