forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
select2.d.ts
189 lines (175 loc) · 7.66 KB
/
select2.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Type definitions for Select2 3.2
// Project: http://ivaynberg.github.com/select2/
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts"/>
interface Select2QueryOptions {
term?: string;
page?: number;
context?: any;
callback?: (result: { results: any; more?: boolean; context?: any; }) => void;
}
interface AjaxFunction {
(settings: JQueryAjaxSettings): JQueryXHR;
(url: string, settings?: JQueryAjaxSettings): JQueryXHR;
}
interface Select2AjaxOptions {
transport?: AjaxFunction;
/**
* Url to make request to, Can be string or a function returning a string.
*/
url?: any;
dataType?: string;
quietMillis?: number;
cache?: boolean;
data?: (term: string, page: number, context: any) => any;
results?: (term: any, page: number, context: any) => any;
}
interface IdTextPair {
id: any;
text: string;
}
interface Select2Options {
width?: string;
dropdownAutoWidth?: boolean;
minimumInputLength?: number;
minimumResultsForSearch?: number;
maximumSelectionSize?: number;
placeholder?: string;
separator?: string;
allowClear?: boolean;
multiple?: boolean;
closeOnSelect?: boolean;
openOnEnter?: boolean;
id?: (object: any) => string;
matcher?: (term: string, text: string, option: any) => boolean;
formatSelection?: (object: any, container: JQuery, escapeMarkup:(markup: string) => string) => string;
formatResult?: (object: any, container: JQuery, query: any, escapeMarkup: (markup: string) => string) => string;
formatResultCssClass?: (object: any) => string;
formatNoMatches?: (term: string) => string;
formatSearching?: () => string;
formatInputTooShort?: (term: string, minLength: number) => string;
formatSelectionTooBig?: (maxSize: number) => string;
formatLoadMore?: (pageNumber: number) => string;
createSearchChoice?: (term: string, data: any) => any;
initSelection?: (element: JQuery, callback: (data: any) => void ) => void;
tokenizer?: (input: string, selection: any[], selectCallback: () => void , options: Select2Options) => string;
tokenSeparators?: string[];
query?: (options: Select2QueryOptions) => void;
ajax?: Select2AjaxOptions;
data?: any;
tags?: any;
containerCss?: any;
containerCssClass?: any;
dropdownCss?: any;
dropdownCssClass?: any;
escapeMarkup?: (markup: string) => string;
theme?: string;
/**
* Template can return both plain string that will be HTML escaped and a jquery object that can render HTML
*/
templateSelection?: (object: Select2SelectionObject) => any;
templateResult?: (object: Select2SelectionObject) => any;
}
interface Select2JQueryEventObject extends JQueryEventObject {
val: any;
added: any;
removed: any;
choice: {
id: any;
text: string;
};
}
interface Select2SelectionObject {
disabled: boolean,
element: HTMLOptionElement,
id: string,
selected: boolean,
text: string,
title: string,
}
interface JQuery {
off(events?: "change", selector?: any, handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "change", selector?: string, data?: any, handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "change", selector?: string, handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "change", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-opening", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-open", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-close", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-highlight", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-selecting", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-removing", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-removed", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-loaded", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-focus", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-blur", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-opening", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-open", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-close", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-highlight", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-selecting", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-removing", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-removed", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-loaded", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-focus", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
on(events: "select2-blur", handler?: (eventObject: Select2JQueryEventObject) => any): JQuery;
select2(): JQuery;
select2(it: IdTextPair): JQuery;
/**
* Get the id value of the current selection
*/
select2(method: 'val'): any;
/**
* Set the id value of the current selection
* @params value Value to set the id to
* @params triggerChange Should a change event be triggered
*/
select2(method: 'val', value: any, triggerChange?: boolean): any;
/**
* Get the data object of the current selection
*/
select2(method: 'data'): any;
/**
* Set the data of the current selection
* @params value Object to set the data to
* @params triggerChange Should a change event be triggered
*/
select2(method: 'data', value: any, triggerChange?: boolean): any;
/**
* Reverts changes to DOM done by Select2. Any selection done via Select2 will be preserved.
*/
select2(method: 'destroy'): JQuery;
/**
* Opens the dropdown
*/
select2(method: 'open'): JQuery;
/**
* Closes the dropdown
*/
select2(method: 'close'): JQuery;
/**
* Enables or disables Select2 and its underlying form component
* @param value True if it should be enabled false if it should be disabled
*/
select2(method: 'enable', value: boolean): JQuery;
/**
* Toggles readonly mode on Select2 and its underlying form component
* @param value True if it should be readonly false if it should be read write
*/
select2(method: 'readonly', value: boolean): JQuery;
/**
* Retrieves the main container element that wraps all of DOM added by Select2
*/
select2(method: 'container'): JQuery;
/**
* Notifies Select2 that a drag and drop sorting operation has started
*/
select2(method: 'onSortStart'): JQuery;
/**
* Notifies Select2 that a drag and drop sorting operation has finished
*/
select2(method: 'onSortEnd'): JQuery;
select2(method: string): any;
select2(method: string, value: any, trigger?: boolean): any;
select2(options: Select2Options): JQuery;
}