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 class="container">
	<h1>GeoNames Search and Twitter’s typeahead.js</h1>
  <p>A combination of the GeoNames Search API, Twitter Bootstrap 3, and Twitter’s typeahead.js library</p>
  <h3>Demo Form</h3>
	<form action="#">
		<div class="form-group">
			<label for="location-1">Search for a location</label>
			<input id="location-1" type="text" class="form-control typeahead" placeholder="Cannes" data-provide="typeahead" autocomplete="off">
		</div>
	</form>
  <h3>Ressources</h3>
  <ul>
    <li><a href="">GeoNames Search Webservice</a> (API Documentation)</li>
    <li><a href="https://getbootstrap.com">Twitter Bootstrap</a></li>
    <li><a href="https://twitter.github.io/typeahead.js/">Twitter typeahead.js</a></li>
    <li><a href="https://twitter.github.io/hogan.js/">Twitter Hogan.js JavaScript templating</a></li>
  </ul>
</div>


              
            
!

CSS

              
                h3 {
  margin-top: 2em;
}

/**
 * Fix full width inputs
 */

.twitter-typeahead {
  display: block !important;
}


/**
 * Additional CSS for Twitter Bootstrap compatibility
 * by https://github.com/jharding/typeahead.js-bootstrap.css
 */

.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
  margin-bottom: 0;
}

.tt-dropdown-menu {
  min-width: 160px;
  margin-top: 2px;
  padding: 5px 0;
  background-color: #fff;
  border: 1px solid #ccc;
  border: 1px solid rgba(0,0,0,.2);
  *border-right-width: 2px;
  *border-bottom-width: 2px;
  -webkit-border-radius: 6px;
     -moz-border-radius: 6px;
          border-radius: 6px;
  -webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
     -moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
          box-shadow: 0 5px 10px rgba(0,0,0,.2);
  -webkit-background-clip: padding-box;
     -moz-background-clip: padding;
          background-clip: padding-box;
}

.tt-suggestion {
  display: block;
  padding: 3px 20px;
}

.tt-suggestion.tt-is-under-cursor {
  color: #fff;
  background-color: #0081c2;
  background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
  background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
  background-image: -o-linear-gradient(top, #0088cc, #0077b3);
  background-image: linear-gradient(to bottom, #0088cc, #0077b3);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0)
}

.tt-suggestion.tt-is-under-cursor a {
  color: #fff;
}

.tt-suggestion p {
  margin: 0;
}

              
            
!

JS

              
                var geoNamesUsername = 'uberboomtest';

/**
 * Initialize typeahead.js
 */
$('.typeahead').typeahead({
	name: $(this).attr('id'),
	remote: {
		// http://www.geonames.org/export/geonames-search.html
		url: 'http://api.geonames.org/searchJSON?q=%QUERY&maxRows=10&username=' + geoNamesUsername + '&lang=de&style=full',
		filter: function(parsedResponse) {
			var result = [];
			for (var i=0; i<parsedResponse.geonames.length; i++) {
				var geonameId = parsedResponse.geonames[i].geonameId;
				result.push({
					name: parsedResponse.geonames[i].name,
					value: parsedResponse.geonames[i].name,
					geonameId: geonameId,
					countryName: parsedResponse.geonames[i].countryName,
					lat: parsedResponse.geonames[i].lat,
					lng: parsedResponse.geonames[i].lng,
					bbox: parsedResponse.geonames[i].bbox,
				});
			}
			return result;
		}
	},
	template: [
		'<p class="geo-name">{{name}}</p>',
		'<p class="geo-country text-muted">{{countryName}}</p>'
	].join(''),
	engine: Hogan
});


/**
 * Fix tt hint
 */
$('.typeahead').on('typeahead:initialized', function(e, data) {
	// fix for using twitter bootstrap
	var hint = $(e.target).prev('.tt-hint');
	var small = $(e.target).is('.input-sm');
	var large = $(e.target).is('.input-lg');
	if (small) {
		hint.addClass('input-sm');
	} else if (large) {
		hint.addClass('input-lg');
	} else {
		hint.addClass('input');
	}
	hint.addClass('form-control');
});

              
            
!
999px

Console