Initial version

Work is still in progress!
This commit is contained in:
Ivaylo Gochkov
2013-12-18 00:03:12 +01:00
parent 718eff7763
commit 46a54d3216
3 changed files with 203 additions and 1 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
DefinitelyTyped [![Build Status](https://travis-ci.org/borisyankov/DefinitelyTyped.png?branch=master)](https://travis-ci.org/borisyankov/DefinitelyTyped)
DefinitelyTyped [![Build Status](https://travis-ci.org/borisyankov/DefinitelyTyped.png?branch=master)](https://travis-ci.org/borisyankov/DefinitelyTyped)
===============
The repository for *high quality* TypeScript type definitions.
@@ -231,6 +231,7 @@ List of Definitions
* [TweenJS](http://www.createjs.com/#!/TweenJS) (by [Pedro Ferreira](https://bitbucket.org/drk4))
* [tween.js](https://github.com/sole/tween.js/) (by [Adam R. Smith](https://github.com/sunetos))
* [twitter-bootstrap-wizard](https://github.com/VinceG/twitter-bootstrap-wizard) (by [Blake Niemyjski](https://github.com/niemyjski))
* [Typeahead.js](http://twitter.github.io/typeahead.js) (by [Ivaylo Gochkov](https://github.com/igochkov))
* [Ubuntu Unity Web API](https://launchpad.net/libunity-webapps) (by [John Vrbanac](https://github.com/jmvrbanac))
* [Underscore.js](http://underscorejs.org/) (by [Boris Yankov](https://github.com/borisyankov))
* [Underscore.js (Typed)](http://underscorejs.org/) (by [Josh Baldwin](https://github.com/jbaldwin/))
+72
View File
@@ -0,0 +1,72 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="typeahead.d.ts"/>
//
// Examples from http://twitter.github.com/typeahead.js/examples
//
// Countries
// Prefetches data, stores it in localStorage, and searches it on the client
$('.example-countries .typeahead').typeahead({
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({
// 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({
name: 'arabic',
local: [
"الإنجليزية",
"نعم",
"لا",
"مرحبا",
"کيف الحال؟",
"أهلا",
"مع السلامة",
"لا أتكلم العربية",
"لا أفهم",
"أنا جائع"
]
});
// NBA and NHL Teams
// Two datasets that are prefetched, stored, and searched on the client
$('.example-sports .typeahead').typeahead([
{
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([
// {
// 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
// }
//]);
+129
View File
@@ -0,0 +1,129 @@
// Type definitions for Twitter's typeahead.js 0.9.3
// Project: http://twitter.github.io/typeahead.js/
// Definitions by: Ivaylo Gochkov <https://github.com/igochkov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts"/>
declare module Twitter.Typeahead {
/**
* A dataset is an object that defines a set of data that hydrates
* suggestions. Typeaheads can be backed by multiple datasets.
* Given a query, a typeahead instance will inspect its backing
* datasets and display relevant suggestions to the end-user.
*/
interface Dataset {
/**
* The string used to identify the dataset. Used by typeahead.js
* to cache intelligently.
*/
name: string;
/**
* The key used to access the value of the datum in the datum object.
* Defaults to value.
*/
valueKey?: string;
/**
* The max number of suggestions from the dataset to display
* for a given query. Defaults to 5.
*/
limit?: number;
/**
* The template used to render suggestions. Can be a string or
* a precompiled template. If not provided, suggestions will render
* as their value contained in a <p> element (i.e. <p>value</p>).
*/
template?: any;
/**
* The template engine used to compile/render template if it is a
* string. Any engine can use used as long as it adheres to the
* expected API. Required if template is a string.
*/
engine?: string;
/**
* The header rendered before suggestions in the dropdown menu.
* Can be either a DOM element or HTML.
*/
header?: any;
/**
* The footer rendered after suggestions in the dropdown menu.
* Can be either a DOM element or HTML.
*/
footer?: any;
/**
* An array of {Twitter.Typeahead.Datum}.
*/
local?: any[];
/**
* Can be a URL to a JSON file containing an array of datums or,
* if more configurability is needed, a prefetch options object
* {Twitter.Typeahead.PrefetchOptions}.
*/
prefetch?: any;
/**
* Can be a URL to fetch suggestions from when the data provided by
* local and prefetch is insufficient or, if more configurability is
* needed, a remote options object {Twitter.Typeahead.RemoteOptions}.
*/
remote?: any;
}
interface PrefetchOptions {
url: string;
ttl?: number;
filter?: (parsedResponse: any) => Datum[];
}
interface RemoteOptions {
url: string;
dataType?: string;
cache?: boolean;
timeout?: number;
wildcard?: string;
replace?: (url: string, uriEncodedQuery: string) => string;
rateLimitFn?: any; // debounce or trottle
rateLimitWait?: number;
maxParallelRequests?: number;
beforeSend?: (jqXhr: JQueryXHR, settings: JQueryAjaxSettings) => void;
filter?: (parsedResponse: any) => Datum[];
}
interface Datum {
value: string;
tokens: string[];
}
interface TypeaheadStatic {
VERSION: string;
utils: TypeaheadUtils;
}
interface TypeaheadUtils {
debounce: (func: any, wait: number, immediate: boolean) => any;
throttle: (func: any, wait: number) => any;
}
}
interface JQuery {
/**
* Turns an input[type="text"] element into a typeahead.
*
* @constructor
* @param dataset Single dataset
*/
typeahead(dataset: Twitter.Typeahead.Dataset): JQuery;
/**
* Turns an input[type="text"] element into a typeahead.
*
* @constructor
* @param dataset Array of datasets
*/
typeahead(datasets: Twitter.Typeahead.Dataset[]): JQuery;
typeahead(methodName: string): JQuery;
typeahead(methodName: 'destroy'): JQuery;
typeahead(methodName: 'setQuery'): JQuery;
}
declare var typeahead: Twitter.Typeahead.TypeaheadStatic;