Skip to content

Instantly share code, notes, and snippets.

@donaldallen
Created October 7, 2015 21:15
Show Gist options
  • Save donaldallen/cad8960efeb900db5728 to your computer and use it in GitHub Desktop.
Save donaldallen/cad8960efeb900db5728 to your computer and use it in GitHub Desktop.
var communities = new Bloodhound({
datumTokenizer: function(datum) {
return Bloodhound.tokenizers.whitespace(datum.title);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
cache: false,
url: '/wp-json/wp/v2/communities',
filter: function(response) {
return $.map(response, function(community) {
return {
link: community.link,
title: community.title.rendered
}
});
}
}
});
var community_areas = new Bloodhound({
datumTokenizer: function(datum) {
return Bloodhound.tokenizers.whitespace(datum.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
cache: false,
url: '/wp-json/wp/v2/terms/community_area',
filter: function(response) {
return $.map(response, function(area) {
return {
name: area.name,
link: area.link
}
});
}
}
});
$('.typeahead.commercial-properties').typeahead({
hint: false,
highlight: true,
minLength: 1
}, {
name: 'communities',
display: 'title',
source: communities,
templates: {
header: '<h4 class="communities">Communities</h4>',
suggestion: Handlebars.compile('<div><strong>{{title}}</strong></div>')
}
}, {
name: 'community_areas',
display: 'name',
source: community_areas,
templates: {
header: '<h4 class="areas">Areas</h4>',
suggestion: Handlebars.compile('<div><strong>{{name}}</strong></div>')
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment