From a00413743e6fd6c95a574a3a30b8bd6697a26a36 Mon Sep 17 00:00:00 2001 From: maanasa Date: Mon, 24 Mar 2014 15:29:49 +0530 Subject: [PATCH 1/3] Update typeahead.d.ts added support for call typeahead(options, dataset) where options include hint, highlight and minLength all of which are optional. --- typeahead/typeahead.d.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/typeahead/typeahead.d.ts b/typeahead/typeahead.d.ts index 9ee948392..f6f387986 100644 --- a/typeahead/typeahead.d.ts +++ b/typeahead/typeahead.d.ts @@ -50,6 +50,16 @@ interface JQuery { * @param query The query to be set in case method 'setQuery' is used. */ typeahead(methodName: string, query: string): JQuery; + + /** + * Accomodates specifying options such as hint and highlight. + * This is in correspondence to the examples mentioned in http://twitter.github.io/typeahead.js/examples/ + * + * @constructor + * @param options ('hint' or 'highlight' or 'minLength' all of which are optional) + * @param dataset Array of datasets + */ + typeahead(options: Twitter.Typeahead.Options, dataset: Twitter.Typeahead.Dataset): JQuery; } declare module Twitter.Typeahead { @@ -243,4 +253,26 @@ declare module Twitter.Typeahead { */ tokens: string[]; } + + /** + * When initializing a typeahead, there are a number of options you can configure. + */ + interface Options { + /** + * highlight: If true, when suggestions are rendered, + * pattern matches for the current query in text nodes will be wrapped in a strong element. + * Defaults to false. + */ + highlight?: boolean; + + /** + * If false, the typeahead will not show a hint. Defaults to true. + */ + hint?: boolean; + + /** + * The minimum character length needed before suggestions start getting rendered. Defaults to 1. + */ + minLength?: number; + } } From 64bd6c8132f7daf0f306f156fd68127ea4eef3e7 Mon Sep 17 00:00:00 2001 From: maanasa Date: Wed, 26 Mar 2014 17:04:20 +0530 Subject: [PATCH 2/3] Update typeahead-tests.ts --- typeahead/typeahead-tests.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/typeahead/typeahead-tests.ts b/typeahead/typeahead-tests.ts index f93049a44..3a24fb152 100644 --- a/typeahead/typeahead-tests.ts +++ b/typeahead/typeahead-tests.ts @@ -71,3 +71,16 @@ $('.example-films .typeahead').typeahead([ engine: Hogan } ]); + +//Basic substring search +//Specifies options along with datasets. In this case the dataset uses a custom substring matcher function as its source +$('#the-basics .typeahead').typeahead({ + hint: true, + highlight: true, + minLength: 1 +}, +{ + name: 'states', + displayKey: 'value', + source: substringMatcher(states) +}); From ec0735af319299632e738be3d0d1fdeae9ed927e Mon Sep 17 00:00:00 2001 From: maanasa Date: Wed, 26 Mar 2014 17:45:30 +0530 Subject: [PATCH 3/3] Update typeahead-tests.ts Adding tests for including options --- typeahead/typeahead-tests.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/typeahead/typeahead-tests.ts b/typeahead/typeahead-tests.ts index 3a24fb152..67fc8d31a 100644 --- a/typeahead/typeahead-tests.ts +++ b/typeahead/typeahead-tests.ts @@ -72,15 +72,16 @@ $('.example-films .typeahead').typeahead([ } ]); -//Basic substring search -//Specifies options along with datasets. In this case the dataset uses a custom substring matcher function as its source -$('#the-basics .typeahead').typeahead({ +// 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: 1 + minLength: 2 }, { - name: 'states', - displayKey: 'value', - source: substringMatcher(states) + name: 'countries', + prefetch: '../data/countries.json', + limit: 10 });