mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-28 08:17:54 +08:00
Merge pull request #7631 from igochkov/master
Typeahead 0.11.1 definitions
This commit is contained in:
@@ -1,302 +1,469 @@
|
||||
/// <reference path="../jquery/jquery.d.ts"/>
|
||||
/// <reference path="typeahead.d.ts"/>
|
||||
|
||||
//
|
||||
// Examples from http://twitter.github.com/typeahead.js/examples
|
||||
//
|
||||
|
||||
var substringMatcher = function (strs: any) {
|
||||
return function findMatches(q: string, syncResults: (x: Array<any>) => void) {
|
||||
var matches: Array<{ value: string }> = [];
|
||||
// regex used to determine if a string contains the substring `q`
|
||||
var substrRegex = new RegExp(q, 'i');
|
||||
|
||||
// iterate through the pool of strings and for any string that
|
||||
// contains the substring `q`, add it to the `matches` array
|
||||
$.each(strs, function (i, str) {
|
||||
if (substrRegex.test(str)) {
|
||||
// the typeahead jQuery plugin expects suggestions to a
|
||||
// JavaScript object, refer to typeahead docs for more info
|
||||
matches.push({ value: str });
|
||||
}
|
||||
});
|
||||
|
||||
syncResults(matches);
|
||||
}
|
||||
}
|
||||
|
||||
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
|
||||
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
|
||||
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
|
||||
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
|
||||
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
|
||||
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
|
||||
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
|
||||
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
|
||||
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
|
||||
];
|
||||
|
||||
|
||||
function test_method_names() {
|
||||
$('#the-basics .typeahead').typeahead('destroy');
|
||||
$('#the-basics .typeahead').typeahead('open');
|
||||
$('#the-basics .typeahead').typeahead('close');
|
||||
$('#the-basics .typeahead').typeahead('val');
|
||||
$('#the-basics .typeahead').typeahead('val', 'test value');
|
||||
}
|
||||
|
||||
|
||||
function test_options() {
|
||||
|
||||
var dataSets: Twitter.Typeahead.Dataset[] = [];
|
||||
|
||||
function with_empty_options() {
|
||||
$('#the-basics .typeahead').typeahead({}, dataSets);
|
||||
}
|
||||
|
||||
function with_hint_option() {
|
||||
$('#the-basics .typeahead').typeahead({ hint: true }, dataSets);
|
||||
}
|
||||
|
||||
function with_highlight_option() {
|
||||
$('#the-basics .typeahead').typeahead({ highlight: true }, dataSets);
|
||||
}
|
||||
|
||||
function with_minLength_option() {
|
||||
$('#the-basics .typeahead').typeahead({ minLength: 1 }, dataSets);
|
||||
}
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead({
|
||||
hint: true,
|
||||
highlight: true,
|
||||
minLength: 1
|
||||
},
|
||||
dataSets
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function test_datasets_array() {
|
||||
|
||||
function test_typeahead() {
|
||||
var options: Twitter.Typeahead.Options = {};
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = { source: null };
|
||||
|
||||
function with_only_source() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
source: substringMatcher(states)
|
||||
}]);
|
||||
function test_typeahead_methods() {
|
||||
$('.typeahead').typeahead(options, dataset);
|
||||
$('.typeahead').typeahead(options, new Array(dataset));
|
||||
$('.typeahead').typeahead('val');
|
||||
$('.typeahead').typeahead('val', 'test value');
|
||||
$('.typeahead').typeahead('open');
|
||||
$('.typeahead').typeahead('close');
|
||||
$('.typeahead').typeahead('destroy');
|
||||
}
|
||||
|
||||
function with_name_option() {
|
||||
function test_typeahead_options() {
|
||||
function options_empty() {
|
||||
$('.typeahead').typeahead({}, dataset);
|
||||
}
|
||||
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
name: 'states',
|
||||
source: substringMatcher(states),
|
||||
}]);
|
||||
function test_typeahead_option_hint() {
|
||||
$('.typeahead').typeahead({ hint: true }, dataset);
|
||||
}
|
||||
|
||||
function test_typeahead_option_minLength() {
|
||||
$('.typeahead').typeahead({ minLength: 1 }, dataset);
|
||||
}
|
||||
|
||||
function test_typeahead_option_highlight() {
|
||||
$('.typeahead').typeahead({ highlight: true }, dataset);
|
||||
}
|
||||
|
||||
function test_typeahead_option_classNames() {
|
||||
$('.typeahead').typeahead({ classNames: { input: 'tt-input' } }, dataset);
|
||||
}
|
||||
|
||||
function test_typeahead_options_all() {
|
||||
$('.typeahead').typeahead({
|
||||
hint: true,
|
||||
minLength: 1,
|
||||
highlight: true,
|
||||
classNames: { input: 'tt-input' }
|
||||
}, dataset);
|
||||
}
|
||||
}
|
||||
|
||||
function with_displayKey_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
display: 'value',
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
function test_typeahead_classNames() {
|
||||
function test_typeahead_classNames_empty() {
|
||||
var className: Twitter.Typeahead.ClassNames = {};
|
||||
}
|
||||
|
||||
function test_typeahead_className_input() {
|
||||
var className: Twitter.Typeahead.ClassNames = { input: 'tt-input' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_hint() {
|
||||
var className: Twitter.Typeahead.ClassNames = { hint: 'tt-hint' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_menu() {
|
||||
var className: Twitter.Typeahead.ClassNames = { menu: 'tt-menu' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_dataset() {
|
||||
var className: Twitter.Typeahead.ClassNames = { dataset: 'tt-dataset' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_suggestion() {
|
||||
var className: Twitter.Typeahead.ClassNames = { suggestion: 'tt-suggestion' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_empty() {
|
||||
var className: Twitter.Typeahead.ClassNames = { empty: 'tt-empty' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_open() {
|
||||
var className: Twitter.Typeahead.ClassNames = { open: 'tt-open' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_cursor() {
|
||||
var className: Twitter.Typeahead.ClassNames = { cursor: 'tt-cursor' };
|
||||
}
|
||||
|
||||
function test_typeahead_className_highlight() {
|
||||
var className: Twitter.Typeahead.ClassNames = { highlight: 'tt-highlight' };
|
||||
}
|
||||
|
||||
function test_typeahead_classNames_all() {
|
||||
var className: Twitter.Typeahead.ClassNames = {
|
||||
input: 'tt-input',
|
||||
hint: 'tt-hint',
|
||||
menu: 'tt-menu',
|
||||
dataset: 'tt-dataset',
|
||||
suggestion: 'tt-suggestion',
|
||||
empty: 'tt-empty',
|
||||
open: 'tt-open',
|
||||
cursor: 'tt-cursor',
|
||||
highlight: 'tt-highlight'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function with_templates_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
function test_typeahead_datasets() {
|
||||
function test_typeahead_dataset_source_bloodhout() {
|
||||
var bo: Bloodhound.BloodhoundOptions<string> = { datumTokenizer: null, queryTokenizer: null };
|
||||
var engine: Bloodhound<string> = new Bloodhound<string>(bo);
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = { source: engine };
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_source_function() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = { source: (query: string, syncResults: (result: string[]) => void, asyncResults?: (result: string[]) => void) => { } };
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_async() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = {
|
||||
source: null,
|
||||
async: true
|
||||
};
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_name() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = {
|
||||
source: null,
|
||||
name: 'name'
|
||||
};
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_limit() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = {
|
||||
source: null,
|
||||
limit: 5
|
||||
};
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_display_string() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = {
|
||||
source: null,
|
||||
display: "key"
|
||||
};
|
||||
}
|
||||
|
||||
function test_typeahead_dataset_display_function() {
|
||||
var dataset: Twitter.Typeahead.Dataset<string> = {
|
||||
source: null,
|
||||
display: (obj: string) => { return 'key'; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
name: 'states',
|
||||
display: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
}
|
||||
function test_typeahead_templates() {
|
||||
function test_typeahead_templates_empty() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = {};
|
||||
}
|
||||
|
||||
function with_multiple_datasets() {
|
||||
$('#the-basics .typeahead').typeahead(options, [
|
||||
{
|
||||
name: 'states',
|
||||
display: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
},
|
||||
{
|
||||
name: 'states alternative',
|
||||
display: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}
|
||||
]);
|
||||
function dataset_template_notfound_string() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { notFound: 'not found' };
|
||||
}
|
||||
|
||||
function dataset_template_notfound_function() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { notFound: (query: string) => { return 'not found'; } };
|
||||
}
|
||||
|
||||
function dataset_template_pending_string() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { pending: 'pending' };
|
||||
}
|
||||
|
||||
function dataset_template_pending_function() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { pending: (query: string) => { return 'pending'; } };
|
||||
}
|
||||
|
||||
function dataset_template_header_string() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { header: 'header' };
|
||||
}
|
||||
|
||||
function dataset_template_header_function() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { header: (query: string) => { return 'header'; } };
|
||||
}
|
||||
|
||||
function dataset_template_footer_string() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { footer: 'footer' };
|
||||
}
|
||||
|
||||
function dataset_template_footer_function() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { footer: (query: string) => { return 'footer'; } };
|
||||
}
|
||||
|
||||
function dataset_template_suggestion() {
|
||||
var templates: Twitter.Typeahead.Templates<string> = { suggestion: (suggestion: string) => { return 'suggestion'; } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_bloodhout() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = { datumTokenizer: null, queryTokenizer: null };
|
||||
var engine: Bloodhound<string> = new Bloodhound<string>(options);
|
||||
|
||||
function test_datasets_objects() {
|
||||
|
||||
var options: Twitter.Typeahead.Options = {};
|
||||
|
||||
function with_only_source() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states)
|
||||
});
|
||||
function test_bloodhout_static() {
|
||||
var old: Bloodhound<any> = Bloodhound.noConflict();
|
||||
var tokenizers: Bloodhound.Tokenizers = Bloodhound.tokenizers;
|
||||
}
|
||||
|
||||
function with_name_option() {
|
||||
function test_bloodhout_methods() {
|
||||
// initialize
|
||||
var promise1: JQueryPromise<string> = engine.initialize();
|
||||
var promise2: JQueryPromise<string> = engine.initialize();
|
||||
var promise3: JQueryPromise<string> = engine.initialize(true);
|
||||
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
name: 'states',
|
||||
source: substringMatcher(states),
|
||||
});
|
||||
// add
|
||||
engine.add(new Array<string>());
|
||||
|
||||
// get
|
||||
var data1: string[] = engine.get(new Array<number>());
|
||||
|
||||
// search
|
||||
var sync: (datums: string[]) => {};
|
||||
var async: (datums: string[]) => {};
|
||||
var data2: string[] = engine.search("query", sync, async);
|
||||
|
||||
// all
|
||||
var data3: string[] = engine.all();
|
||||
|
||||
// clear
|
||||
var engine1: Bloodhound<string> = engine.clear();
|
||||
|
||||
// clearPrefetchCache
|
||||
var engine2: Bloodhound<string> = engine.clearPrefetchCache();
|
||||
|
||||
// clearRemoteCache
|
||||
var engine3: Bloodhound<string> = engine.clearRemoteCache();
|
||||
}
|
||||
|
||||
function with_displayKey_option() {
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
{
|
||||
display: 'value',
|
||||
source: substringMatcher(states)
|
||||
function test_bloodhout_options() {
|
||||
function test_bloodhout_options_datumTokenizer() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: (datum: string) => { return new Array<string>(); },
|
||||
queryTokenizer: null
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_queryTokenizer() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: (query: string) => { return new Array<string>(); }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_initialize() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
initialize: true
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_sufficient() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
sufficient: 5
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_sorter() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
sorter: (a: string, b: string) => { return 0 }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_local_array() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
local: new Array<string>()
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_local_function() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
local: () => { return new Array<string>() }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_prefetch_string() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
prefetch: 'url'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_prefetch_object() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
prefetch: { url: 'url' }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_remote_string() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
remote: 'url'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_remote_object() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: null,
|
||||
queryTokenizer: null,
|
||||
remote: { url: 'url' }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_options_all() {
|
||||
var options: Bloodhound.BloodhoundOptions<string> = {
|
||||
datumTokenizer: (datum: string) => { return new Array<string>(); },
|
||||
queryTokenizer: (query: string) => { return new Array<string>(); },
|
||||
initialize: true,
|
||||
sufficient: 5,
|
||||
sorter: (a: string, b: string) => { return 0 },
|
||||
local: () => { return new Array<string>() },
|
||||
prefetch: { url: 'url' },
|
||||
remote: { url: 'url' }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options() {
|
||||
function test_bloodhout_prefetch_options_url() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_cache() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
cache: true
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_ttl() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
ttl: 86400000 // 1 day
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_cacheKey() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
cacheKey: 'url'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_thumbprint() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
thumbprint: 'thumbprint'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_prepare() {
|
||||
var ajaxSettings: JQueryAjaxSettings = { url: 'url' };
|
||||
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
prepare: (settings: JQueryAjaxSettings) => { return ajaxSettings; }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_transform() {
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
transform: (response: string[]) => { return new Array<string>(); }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_prefetch_options_all() {
|
||||
var ajaxSettings: JQueryAjaxSettings = { url: 'url' };
|
||||
|
||||
var options: Bloodhound.PrefetchOptions<string> = {
|
||||
url: 'url',
|
||||
cache: true,
|
||||
ttl: 86400000,
|
||||
cacheKey: 'url',
|
||||
thumbprint: 'thumbprint',
|
||||
prepare: (settings: JQueryAjaxSettings) => { return ajaxSettings; },
|
||||
transform: (response: string[]) => { return new Array<string>(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options() {
|
||||
function test_bloodhout_remote_options_url() {
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_prepare() {
|
||||
var ajaxSettings: JQueryAjaxSettings = { url: 'url' };
|
||||
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
prepare: (query: string, settings: JQueryAjaxSettings) => { return ajaxSettings; }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_wildcard() {
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
wildcard: '%QUERY'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_rateLimitby() {
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
rateLimitby: 'debounce'
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_rateLimitWait() {
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
rateLimitWait: 300
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_transform() {
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
transform: (response: string[]) => { return new Array<string>(); }
|
||||
};
|
||||
}
|
||||
|
||||
function test_bloodhout_remote_options_all() {
|
||||
var ajaxSettings: JQueryAjaxSettings = { url: 'url' };
|
||||
|
||||
var options: Bloodhound.RemoteOptions<string> = {
|
||||
url: 'url',
|
||||
prepare: (query: string, settings: JQueryAjaxSettings) => { return ajaxSettings; },
|
||||
wildcard: '%QUERY',
|
||||
rateLimitby: 'debounce',
|
||||
rateLimitWait: 300,
|
||||
transform: (response: string[]) => { return new Array<string>(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function test_bloodhout_tokenizers() {
|
||||
var tokenizers: Bloodhound.Tokenizers = {
|
||||
whitespace: (str: string) => { return new Array<string>(); },
|
||||
nonword: (str: string) => { return new Array<string>(); },
|
||||
obj: {
|
||||
whitespace: (str: string) => { return new Array<string>(); },
|
||||
nonword: (str: string) => { return new Array<string>(); }
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function with_templates_option() {
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
{
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
{
|
||||
name: 'states',
|
||||
display: x => x.value,
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function with_multiple_objects() {
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
{
|
||||
name: 'states',
|
||||
display: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
},
|
||||
{
|
||||
name: 'states alternative',
|
||||
display: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function test_dataset_templates() {
|
||||
|
||||
var options: Twitter.Typeahead.Options = {};
|
||||
|
||||
function with_no_options() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {}
|
||||
});
|
||||
}
|
||||
|
||||
function with_empty_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: { empty: 'no results' }
|
||||
});
|
||||
}
|
||||
|
||||
function with_empty_option_as_a_function() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
empty: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function with_footer_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: { footer: 'custom footer' }
|
||||
});
|
||||
}
|
||||
|
||||
function with_footer_option_as_a_function() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
footer: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function with_header_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: { header: 'custom header' }
|
||||
});
|
||||
}
|
||||
|
||||
function with_header_option_as_a_function() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
header: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function with_suggestion_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
suggestion: function (context) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
empty: 'no results',
|
||||
footer: 'custom footer',
|
||||
header: 'custom header',
|
||||
suggestion: function (context) {
|
||||
return context.name;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function test_value() {
|
||||
var value: string = $('foo').typeahead('val');
|
||||
$('foo').typeahead('val', value);
|
||||
}
|
||||
1711
typeahead/typeahead.d.ts
vendored
1711
typeahead/typeahead.d.ts
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user