Skip to content

Commit

Permalink
Updated to typeahead 0.10.4
Browse files Browse the repository at this point in the history
Updated from 0.9.3 to 0.10.4
API has changed quite a bit. Part of the functionality (prefetch etc)
has been taken out from the core lib, and merged into a new lib called
Bloodhound.
Bloodhound still has to be ts-ed.
  • Loading branch information
gjunge committed Jul 16, 2014
1 parent d8ecb4d commit 2cc58f1
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 255 deletions.
99 changes: 17 additions & 82 deletions typeahead/typeahead-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,6 @@
//
declare var Hogan: string;

// Countries
// Prefetches data, stores it in localStorage, and searches it on the client
$('.example-countries .typeahead').typeahead(null, {
name: 'countries',
prefetch: '../data/countries.json',
limit: 10
});

// Open Source Projects by Twitter
// Defines a custom template and template engine for rendering suggestions
$('.example-twitter-oss .typeahead').typeahead(null, {
name: 'twitter-oss',
prefetch: '../data/repos.json',
template: [
'<p class="repo-language">{{language}}</p>',
'<p class="repo-name">{{name}}</p>',
'<p class="repo-description">{{description}}</p>'
].join(''),
engine: Hogan
});

// Arabic Phrases
// Hardcoded list showing Right - To - Left(RTL) support
$('.example-arabic .typeahead').typeahead(null, {
name: 'arabic',
local: [
"الإنجليزية",
"نعم",
"لا",
"مرحبا",
"کيف الحال؟",
"أهلا",
"مع السلامة",
"لا أتكلم العربية",
"لا أفهم",
"أنا جائع"
]
});

// NBA and NHL Teams
// Two datasets that are prefetched, stored, and searched on the client
$('.example-sports .typeahead').typeahead(null, [
{
name: 'nba-teams',
prefetch: '../data/nba.json',
header: '<h3 class="league-name">NBA Teams</h3>'
},
{
name: 'nhl-teams',
prefetch: '../data/nhl.json',
header: '<h3 class="league-name">NHL Teams</h3>'
}
]);

// Best Picture Winners
// Prefetches some data then relies on remote requests for suggestions when prefetched data is insufficient
$('.example-films .typeahead').typeahead(null, [
{
name: 'best-picture-winners',
remote: '../data/films/queries/%QUERY.json',
prefetch: '../data/films/post_1960.json',
template: '<p><strong>{{value}}</strong> – {{year}}</p>',
engine: Hogan
}
]);

// Countries - Modified the first test here to add options
// Specifies options to display hint with a highlight and adds a minimum length restriction for search
// Prefetches data, stores it in localStorage, and searches it on the client
$('.example-countries .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'countries',
prefetch: '../data/countries.json',
limit: 10
});


var substringMatcher = function (strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
Expand Down Expand Up @@ -131,4 +50,20 @@ $('#the-basics .typeahead').typeahead({
name: 'states',
displayKey: 'value',
source: substringMatcher(states)
});
});


// custom templates
$('#custom-templates .typeahead').typeahead(null, {
name: 'best-pictures',
displayKey: 'value',
source: bestPictures.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'unable to find any Best Picture winners that match the current query',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><strong>{{value}}</strong> – {{year}}</p>')
}
});
Loading

0 comments on commit 2cc58f1

Please sign in to comment.