mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-11 11:50:54 +08:00
Typeahead: added missing options, and missing parameters, normalized some comments and code style
This commit is contained in:
@@ -6,14 +6,10 @@
|
||||
//
|
||||
|
||||
var substringMatcher = function (strs: any) {
|
||||
return function findMatches(q: any, cb: any) {
|
||||
var matches: any, substrRegex: any;
|
||||
|
||||
// an array that will be populated with substring matches
|
||||
matches = [];
|
||||
|
||||
return function findMatches(q: string, syncResults: (x: any) => void) {
|
||||
var matches: Array<{ value: string }> = [];
|
||||
// regex used to determine if a string contains the substring `q`
|
||||
substrRegex = new RegExp(q, 'i');
|
||||
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
|
||||
@@ -25,7 +21,7 @@ var substringMatcher = function (strs: any) {
|
||||
}
|
||||
});
|
||||
|
||||
cb(matches);
|
||||
syncResults(matches);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,14 +42,14 @@ function test_method_names() {
|
||||
$('#the-basics .typeahead').typeahead('open');
|
||||
$('#the-basics .typeahead').typeahead('close');
|
||||
$('#the-basics .typeahead').typeahead('val');
|
||||
$('#the-basics .typeahead').typeahead('val', 'test value');
|
||||
$('#the-basics .typeahead').typeahead('val', 'test value');
|
||||
}
|
||||
|
||||
|
||||
function test_options() {
|
||||
|
||||
var dataSets: Twitter.Typeahead.Dataset[] = [];
|
||||
|
||||
|
||||
function with_empty_options() {
|
||||
$('#the-basics .typeahead').typeahead({}, dataSets);
|
||||
}
|
||||
@@ -72,10 +68,10 @@ function test_options() {
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead({
|
||||
hint: true,
|
||||
highlight: true,
|
||||
minLength: 1
|
||||
},
|
||||
hint: true,
|
||||
highlight: true,
|
||||
minLength: 1
|
||||
},
|
||||
dataSets
|
||||
);
|
||||
}
|
||||
@@ -101,33 +97,33 @@ function test_datasets_array() {
|
||||
|
||||
function with_displayKey_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
displayKey: 'value',
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
displayKey: 'value',
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
function with_templates_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
function with_all_options() {
|
||||
$('#the-basics .typeahead').typeahead(options, [{
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
templates: {},
|
||||
source: substringMatcher(states)
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
function with_multiple_datasets() {
|
||||
$('#the-basics .typeahead').typeahead(options, [
|
||||
{
|
||||
{
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
templates: {},
|
||||
@@ -192,7 +188,7 @@ function test_datasets_objects() {
|
||||
}
|
||||
|
||||
function with_multiple_objects() {
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
$('#the-basics .typeahead').typeahead(options,
|
||||
{
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
@@ -231,7 +227,7 @@ function test_dataset_templates() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
empty: function(context: any) {
|
||||
empty: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +245,7 @@ function test_dataset_templates() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
footer: function(context: any) {
|
||||
footer: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
@@ -267,7 +263,7 @@ function test_dataset_templates() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
header: function(context: any) {
|
||||
header: function (context: any) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
@@ -277,8 +273,8 @@ function test_dataset_templates() {
|
||||
function with_suggestion_option() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
suggestion: function(context) {
|
||||
templates: {
|
||||
suggestion: function (context) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
@@ -289,10 +285,10 @@ function test_dataset_templates() {
|
||||
$('#the-basics .typeahead').typeahead(options, {
|
||||
source: substringMatcher(states),
|
||||
templates: {
|
||||
empty: 'no results',
|
||||
empty: 'no results',
|
||||
footer: 'custom footer',
|
||||
header: 'custom header',
|
||||
suggestion: function(context) {
|
||||
suggestion: function (context) {
|
||||
return context.name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user