1 | declare namespace FomanticUI {
|
2 | interface API {
|
3 | settings: APISettings;
|
4 |
|
5 | |
6 |
|
7 |
|
8 | (behavior: 'query'): JQuery;
|
9 |
|
10 | |
11 |
|
12 |
|
13 | (behavior: 'add url data', url: string, data: any): JQuery;
|
14 |
|
15 | |
16 |
|
17 |
|
18 | (behavior: 'get request'): JQuery;
|
19 |
|
20 | |
21 |
|
22 |
|
23 | (behavior: 'abort'): JQuery;
|
24 |
|
25 | |
26 |
|
27 |
|
28 | (behavior: 'was cancelled'): boolean;
|
29 |
|
30 | |
31 |
|
32 |
|
33 | (behavior: 'was failure'): boolean;
|
34 |
|
35 | |
36 |
|
37 |
|
38 | (behavior: 'was successful'): boolean;
|
39 |
|
40 | |
41 |
|
42 |
|
43 | (behavior: 'was complete'): boolean;
|
44 |
|
45 | |
46 |
|
47 |
|
48 | (behavior: 'is disabled'): boolean;
|
49 |
|
50 | |
51 |
|
52 |
|
53 | (behavior: 'is mocked'): boolean;
|
54 |
|
55 | |
56 |
|
57 |
|
58 | (behavior: 'is loading'): boolean;
|
59 |
|
60 | |
61 |
|
62 |
|
63 | (behavior: 'set loading'): void;
|
64 |
|
65 | |
66 |
|
67 |
|
68 | (behavior: 'set error'): void;
|
69 |
|
70 | |
71 |
|
72 |
|
73 | (behavior: 'remove loading'): void;
|
74 |
|
75 | |
76 |
|
77 |
|
78 | (behavior: 'remove error'): void;
|
79 |
|
80 | |
81 |
|
82 |
|
83 | (behavior: 'get event'): string;
|
84 |
|
85 | |
86 |
|
87 |
|
88 | (behavior: 'get url encoded value', value: any): string;
|
89 |
|
90 | |
91 |
|
92 |
|
93 | (behavior: 'read cached response', url: string): any;
|
94 |
|
95 | |
96 |
|
97 |
|
98 | (behavior: 'write cached response', url: string, response: any): void;
|
99 |
|
100 | |
101 |
|
102 |
|
103 | (behavior: 'create cache'): void;
|
104 |
|
105 | |
106 |
|
107 |
|
108 | (behavior: 'destroy'): JQuery;
|
109 |
|
110 | <K extends keyof APISettings | JQueryAjaxSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<APISettings, keyof APISettings>> | Partial<Pick<JQueryAjaxSettings, keyof JQueryAjaxSettings>>;
|
111 | <K extends keyof APISettings>(behavior: 'setting', name: K, value: APISettings[K]): JQuery;
|
112 | (behavior: 'setting', value: Partial<Pick<APISettings, keyof APISettings>> | Partial<Pick<JQueryAjaxSettings, keyof JQueryAjaxSettings>>): JQuery;
|
113 | (settings?: Partial<Pick<APISettings, keyof APISettings>> | Partial<Pick<JQueryAjaxSettings, keyof JQueryAjaxSettings>>): JQuery;
|
114 | }
|
115 |
|
116 | |
117 |
|
118 |
|
119 | interface APISettings {
|
120 |
|
121 |
|
122 | |
123 |
|
124 |
|
125 |
|
126 | on: string;
|
127 |
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | cache: boolean | 'local';
|
135 |
|
136 | |
137 |
|
138 |
|
139 |
|
140 | stateContext: false | JQuery;
|
141 |
|
142 | |
143 |
|
144 |
|
145 |
|
146 | encodeParameters: boolean;
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 | defaultData: boolean;
|
153 |
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | serializeForm: boolean;
|
161 |
|
162 | |
163 |
|
164 |
|
165 |
|
166 | throttle: number;
|
167 |
|
168 | |
169 |
|
170 |
|
171 |
|
172 | throttleFirstRequest: boolean;
|
173 |
|
174 | |
175 |
|
176 |
|
177 |
|
178 | interruptRequests: boolean;
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 | loadingDuration: number;
|
185 |
|
186 | |
187 |
|
188 |
|
189 |
|
190 | hideError: 'auto' | boolean;
|
191 |
|
192 | |
193 |
|
194 |
|
195 |
|
196 | errorDuration: true | number;
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 | action: string | false;
|
207 |
|
208 | |
209 |
|
210 |
|
211 |
|
212 | url: string | false;
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 | base: string;
|
219 |
|
220 | |
221 |
|
222 |
|
223 |
|
224 | urlData: any;
|
225 |
|
226 | |
227 |
|
228 |
|
229 |
|
230 | response: any;
|
231 |
|
232 | |
233 |
|
234 |
|
235 |
|
236 |
|
237 | responseAsync: ((settings: APISettings, callback: (response: any) => void) => void) | false;
|
238 |
|
239 | /**
|
240 | * Alias of 'response'.
|
241 | * @default false
|
242 | */
|
243 | mockResponse: any;
|
244 |
|
245 | /**
|
246 | * Alias of 'responseAsync'.
|
247 | * @default false
|
248 | */
|
249 | mockResponseAsync: ((settings: APISettings, callback: (response: any) => void) => void) | false;
|
250 |
|
251 | /**
|
252 | * If set, the onResponse event handler is able to handle an raw Array Object, which is probably returned by the requested source.
|
253 | * Even if the datatype is json, it won't be force converted into an object anymore then.
|
254 | * @default true
|
255 | */
|
256 | rawResponse: boolean;
|
257 |
|
258 | /**
|
259 | * Method for transmitting request to server.
|
260 | * @default 'get'
|
261 | */
|
262 | method: 'get' | 'post' | 'put' | 'delete' | 'head' | 'options' | 'patch';
|
263 |
|
264 | /**
|
265 | * Expected data type of response.
|
266 | * @default 'json'
|
267 | */
|
268 | dataType: 'xml' | 'json' | 'jsonp' | 'script' | 'html' | 'text';
|
269 |
|
270 | /**
|
271 | * Expected data type of response.
|
272 | * @default {}
|
273 | */
|
274 | data: any;
|
275 |
|
276 | // endregion
|
277 |
|
278 | // region Callbacks
|
279 |
|
280 | /**
|
281 | * Allows modifying settings before request, or cancelling request.
|
282 | */
|
283 | beforeSend(settings: APISettings): any;
|
284 |
|
285 | /**
|
286 | * Allows modifying XHR object for request.
|
287 | */
|
288 | beforeXHR(xhrObject: JQuery.jqXHR): any;
|
289 |
|
290 | /**
|
291 | * Callback that occurs when request is made. Receives both the API success promise and the XHR request promise.
|
292 | */
|
293 | onRequest(promise: JQuery.Deferred<any>, xhr: JQuery.jqXHR): void;
|
294 |
|
295 | /**
|
296 | * Allows modifying the server's response before parsed by other callbacks to determine API event success.
|
297 | */
|
298 | onResponse(response: any): void;
|
299 |
|
300 | /**
|
301 | * Determines whether completed JSON response should be treated as successful.
|
302 | *
|
303 | * @see {@link http://fomantic-ui.com/behaviors/api.html#determining-json-success}
|
304 | */
|
305 | successTest(response: any): boolean;
|
306 |
|
307 | /**
|
308 | * Callback after successful response, JSON response must pass 'successTest'.
|
309 | */
|
310 | onSuccess(response: any, element: JQuery, xhr: JQuery.jqXHR): void;
|
311 |
|
312 | /**
|
313 | * Callback on request complete regardless of conditions.
|
314 | */
|
315 | onComplete(response: any, element: JQuery, xhr: JQuery.jqXHR): void;
|
316 |
|
317 | /**
|
318 | * Callback on failed response, or JSON response that fails 'successTest'.
|
319 | */
|
320 | onFailure(response: any, element: JQuery): void;
|
321 |
|
322 | /**
|
323 | * Callback on server error from returned status code, or XHR failure.
|
324 | */
|
325 | onError(errorMessage: string, element: JQuery, xhr: JQuery.jqXHR): void;
|
326 |
|
327 | /**
|
328 | * Callback on abort caused by user clicking a link or manually cancelling request.
|
329 | */
|
330 | onAbort(errorMessage: string, element: JQuery, xhr: JQuery.jqXHR): void;
|
331 |
|
332 | // endregion
|
333 |
|
334 | // region DOM Settings
|
335 |
|
336 | /**
|
337 | * Selectors used to find parts of a module.
|
338 | */
|
339 | selector: API.SelectorSettings;
|
340 |
|
341 | /**
|
342 | * Class names used to determine element state.
|
343 | */
|
344 | className: API.ClassNameSettings;
|
345 |
|
346 | /**
|
347 | * Regular expressions used for template matching.
|
348 | */
|
349 | regExp: API.RegExpSettings;
|
350 |
|
351 | /**
|
352 | * Metadata used to store XHR and response promise.
|
353 | */
|
354 | metadata: API.MetadataSettings;
|
355 |
|
356 | // endregion
|
357 |
|
358 | // region Debug Settings
|
359 |
|
360 | /**
|
361 | * Name used in log statements.
|
362 | * @default 'API'
|
363 | */
|
364 | name: string;
|
365 |
|
366 | /**
|
367 | * Event namespace. Makes sure module teardown does not effect other events attached to an element.
|
368 | * @default 'api'
|
369 | */
|
370 | namespace: string;
|
371 |
|
372 | /**
|
373 | * Silences all console output including error messages, regardless of other debug settings.
|
374 | * @default false
|
375 | */
|
376 | silent: boolean;
|
377 |
|
378 | /**
|
379 | * Debug output to console.
|
380 | * @default false
|
381 | */
|
382 | debug: boolean;
|
383 |
|
384 | /**
|
385 | * Show 'console.table' output with performance metrics.
|
386 | * @default true
|
387 | */
|
388 | performance: boolean;
|
389 |
|
390 | /**
|
391 | * Debug output includes all internal behaviors.
|
392 | * @default false
|
393 | */
|
394 | verbose: boolean;
|
395 |
|
396 | errors: API.ErrorSettings;
|
397 |
|
398 | // endregion
|
399 | }
|
400 |
|
401 | namespace API {
|
402 | type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
|
403 | type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
|
404 | type RegExpSettings = Partial<Pick<Settings.RegExps, keyof Settings.RegExps>>;
|
405 | type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
|
406 | type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
|
407 |
|
408 | namespace Settings {
|
409 | interface Selectors {
|
410 | /**
|
411 | * @default '.disabled'
|
412 | */
|
413 | disabled: string;
|
414 |
|
415 | /**
|
416 | * @default 'form'
|
417 | */
|
418 | form: string;
|
419 | }
|
420 |
|
421 | interface ClassNames {
|
422 | /**
|
423 | * @default 'loading'
|
424 | */
|
425 | loading: string;
|
426 |
|
427 | /**
|
428 | * @default 'error'
|
429 | */
|
430 | error: string;
|
431 | }
|
432 |
|
433 | interface RegExps {
|
434 | /**
|
435 | * @default /{\$*[\da-z]+}/gi
|
436 | */
|
437 | required: RegExp;
|
438 |
|
439 | /**
|
440 | * @default /{\/\$*[\da-z]+}/gi
|
441 | */
|
442 | optional: RegExp;
|
443 |
|
444 | /**
|
445 | * @default /^[_a-z][\w-]*(?:\[[\w-]*])*$/i
|
446 | */
|
447 | validate: RegExp;
|
448 |
|
449 | /**
|
450 | * /[\w-]+|(?=\[])/gi
|
451 | */
|
452 | key: RegExp;
|
453 |
|
454 | /**
|
455 | * @default /^$/
|
456 | */
|
457 | push: RegExp;
|
458 |
|
459 | /**
|
460 | * @default /^\d+$/
|
461 | */
|
462 | fixed: RegExp;
|
463 |
|
464 | /**
|
465 | * @default /^[\w-]+$/i
|
466 | */
|
467 | named: RegExp;
|
468 | }
|
469 |
|
470 | interface Metadatas {
|
471 | /**
|
472 | * @default 'action'
|
473 | */
|
474 | action: string;
|
475 |
|
476 | /**
|
477 | * @default 'url'
|
478 | */
|
479 | url: string;
|
480 | }
|
481 |
|
482 | interface Errors {
|
483 | /**
|
484 | * @default 'The before send function has aborted the request.'
|
485 | */
|
486 | beforeSend: string;
|
487 |
|
488 | /**
|
489 | * @default 'There was an error with your request.'
|
490 | */
|
491 | error: string;
|
492 |
|
493 | /**
|
494 | * @default 'API Request Aborted. Exit conditions met.'
|
495 | */
|
496 | exitConditions: string;
|
497 |
|
498 | /**
|
499 | * @default 'JSON could not be parsed during error handling.'
|
500 | */
|
501 | JSONParse: string;
|
502 |
|
503 | /**
|
504 | * @default 'You are using legacy API success callback names.'
|
505 | */
|
506 | legacyParameters: string;
|
507 |
|
508 | /**
|
509 | * @default 'The method you called is not defined.'
|
510 | */
|
511 | method: string;
|
512 |
|
513 | /**
|
514 | * @default 'API action used but no url was defined.'
|
515 | */
|
516 | missingAction: string;
|
517 |
|
518 | /**
|
519 | * @default 'No URL specified for API event.'
|
520 | */
|
521 | missingURL: string;
|
522 |
|
523 | /**
|
524 | * @default 'The beforeSend callback must return a settings object, beforeSend ignored.'
|
525 | */
|
526 | noReturnedValue: string;
|
527 |
|
528 | /**
|
529 | * @default 'There was an error with your request.'
|
530 | */
|
531 | parseError: string;
|
532 |
|
533 | /**
|
534 | * @default 'Caching responses locally requires session storage.'
|
535 | */
|
536 | noStorage: string;
|
537 |
|
538 | /**
|
539 | * @default 'Missing a required URL parameter: '
|
540 | */
|
541 | requiredParameter: string;
|
542 |
|
543 | /**
|
544 | * @default 'Server gave an error: '
|
545 | */
|
546 | statusMessage: string;
|
547 |
|
548 | /**
|
549 | * @default 'Your request timed out.'
|
550 | */
|
551 | timeout: string;
|
552 | }
|
553 | }
|
554 | }
|
555 | }
|
556 |
|
\ | No newline at end of file |