forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
durandal.d.ts
1799 lines (1563 loc) · 71.8 KB
/
durandal.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Durandal 2.1.0
// Project: http://durandaljs.com
// Definitions by: Blue Spire <https://github.com/BlueSpire>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* Durandal 2.1.0 Copyright (c) 2012 Blue Spire Consulting, Inc. All Rights Reserved.
* Available via the MIT license.
* see: http://durandaljs.com or https://github.com/BlueSpire/Durandal for details.
*/
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../knockout/knockout.d.ts" />
/**
* The system module encapsulates the most basic features used by other modules.
* @requires require
* @requires jquery
*/
declare module 'durandal/system' {
var theModule: DurandalSystemModule;
export = theModule;
}
interface DurandalSystemModule {
/**
* Durandal's version.
*/
version: string;
/**
* A noop function.
*/
noop: Function;
/**
* Gets the module id for the specified object.
* @param {object} obj The object whose module id you wish to determine.
* @returns {string} The module id.
*/
getModuleId(obj: any): string;
/**
* Sets the module id for the specified object.
* @param {object} obj The object whose module id you wish to set.
* @param {string} id The id to set for the specified object.
*/
setModuleId(obj, id: string): void;
/**
* Resolves the default object instance for a module. If the module is an object, the module is returned. If the module is a function, that function is called with `new` and it's result is returned.
* @param {object} module The module to use to get/create the default object for.
* @returns {object} The default object for the module.
*/
resolveObject(module: any): any;
/**
* Gets/Sets whether or not Durandal is in debug mode.
* @param {boolean} [enable] Turns on/off debugging.
* @returns {boolean} Whether or not Durandal is current debugging.
*/
debug(enable?: boolean): boolean;
/**
* Logs data to the console. Pass any number of parameters to be logged. Log output is not processed if the framework is not running in debug mode.
* @param {object} info* The objects to log.
*/
log(...msgs: any[]): void;
/**
* Logs an error.
* @param {string} obj The error to report.
*/
error(error: string): void;
/**
* Logs an error.
* @param {Error} obj The error to report.
*/
error(error: Error): void;
/**
* Asserts a condition by throwing an error if the condition fails.
* @param {boolean} condition The condition to check.
* @param {string} message The message to report in the error if the condition check fails.
*/
assert(condition: boolean, message: string): void;
/**
* Creates a deferred object which can be used to create a promise. Optionally pass a function action to perform which will be passed an object used in resolving the promise.
* @param {function} [action] The action to defer. You will be passed the deferred object as a paramter.
* @returns {JQueryDeferred} The deferred object.
*/
defer<T>(action?: (dfd: JQueryDeferred<T>) => void): JQueryDeferred<T>;
/**
* Creates a simple V4 UUID. This should not be used as a PK in your database. It can be used to generate internal, unique ids. For a more robust solution see [node-uuid](https://github.com/broofa/node-uuid).
* @returns {string} The guid.
*/
guid(): string;
/**
* Uses require.js to obtain a module. This function returns a promise which resolves with the module instance.
* @param {string} moduleId The id of the module to load.
* @returns {JQueryPromise} A promise for the loaded module.
*/
acquire(moduleId: string): JQueryPromise<any>;
/**
* Uses require.js to obtain an array of modules. This function returns a promise which resolves with the modules instances in an array.
* @param {string[]} moduleIds The ids of the modules to load.
* @returns {JQueryPromise} A promise for the loaded module.
*/
acquire(modules: string[]): JQueryPromise<any[]>;
/**
* Uses require.js to obtain multiple modules. This function returns a promise which resolves with the module instances in an array.
* @param {string} moduleIds* The ids of the modules to load.
* @returns {JQueryPromise} A promise for the loaded module.
*/
acquire(...moduleIds: string[]): JQueryPromise<any[]>;
/**
* Extends the first object with the properties of the following objects.
* @param {object} obj The target object to extend.
* @param {object} extension* Uses to extend the target object.
*/
extend(obj: any, ...extensions: any[]): any;
/**
* Uses a setTimeout to wait the specified milliseconds.
* @param {number} milliseconds The number of milliseconds to wait.
* @returns {JQueryPromise}
*/
wait(milliseconds: number): JQueryPromise<any>;
/**
* Gets all the owned keys of the specified object.
* @param {object} object The object whose owned keys should be returned.
* @returns {string[]} The keys.
*/
keys(obj: any): string[];
/**
* Determines if the specified object is an html element.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isElement(obj: any): boolean;
/**
* Determines if the specified object is an array.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isArray(obj: any): boolean;
/**
* Determines if the specified object is a boolean.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isObject(obj: any): boolean;
/**
* Determines if the specified object is a promise.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isPromise(obj: any): boolean;
/**
* Determines if the specified object is a function arguments object.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isArguments(obj: any): boolean;
/**
* Determines if the specified object is a function.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isFunction(obj: any): boolean;
/**
* Determines if the specified object is a string.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isString(obj: any): boolean;
/**
* Determines if the specified object is a number.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isNumber(obj: any): boolean;
/**
* Determines if the specified object is a date.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isDate(obj: any): boolean;
/**
* Determines if the specified object is a boolean.
* @param {object} object The object to check.
* @returns {boolean} True if matches the type, false otherwise.
*/
isBoolean(obj: any): boolean;
}
/**
* The viewEngine module provides information to the viewLocator module which is used to locate the view's source file. The viewEngine also transforms a view id into a view instance.
* @requires system
* @requires jquery
*/
declare module 'durandal/viewEngine' {
var theModule: DurandalViewEngineModule;
export = theModule;
}
interface DurandalViewEngineModule {
/**
* The file extension that view source files are expected to have.
* @default .html
*/
viewExtension: string;
/**
* The name of the RequireJS loader plugin used by the viewLocator to obtain the view source. (Use requirejs to map the plugin's full path).
* @default text
*/
viewPlugin: string;
/**
* Parameters passed to the RequireJS loader plugin used by the viewLocator to obtain the view source.
* @default The empty string by default.
*/
viewPluginParameters: string;
/**
* Determines if the url is a url for a view, according to the view engine.
* @param {string} url The potential view url.
* @returns {boolean} True if the url is a view url, false otherwise.
*/
isViewUrl(url: string): boolean;
/**
* Converts a view url into a view id.
* @param {string} url The url to convert.
* @returns {string} The view id.
*/
convertViewUrlToViewId(url: string): string;
/**
* Converts a view id into a full RequireJS path.
* @param {string} viewId The view id to convert.
* @returns {string} The require path.
*/
convertViewIdToRequirePath(viewId: string): string;
/**
* Parses the view engine recognized markup and returns DOM elements.
* @param {string} markup The markup to parse.
* @returns {HTMLElement[]} The elements.
*/
parseMarkup(markup: string): Node[];
/**
* Calls `parseMarkup` and then pipes the results through `ensureSingleElement`.
* @param {string} markup The markup to process.
* @returns {HTMLElement} The view.
*/
processMarkup(markup: string): HTMLElement;
/**
* Converts an array of elements into a single element. White space and comments are removed. If a single element does not remain, then the elements are wrapped.
* @param {HTMLElement[]} allElements The elements.
* @returns {HTMLElement} A single element.
*/
ensureSingleElement(allElements: Node[]): HTMLElement;
/**
* Gets the view associated with the id from the cache of parsed views.
* @param {string} id The view id to lookup in the cache.
* @return {DOMElement|null} The cached view or null if it's not in the cache.
*/
tryGetViewFromCache(id: string): HTMLElement;
/**
* Puts the view associated with the id into the cache of parsed views.
* @param {string} id The view id whose view should be cached.
* @param {DOMElement} view The view to cache.
*/
putViewInCache(id: string, view: HTMLElement);
/**
* Creates the view associated with the view id.
* @param {string} viewId The view id whose view should be created.
* @returns {JQueryPromise<HTMLElement>} A promise of the view.
*/
createView(viewId: string): JQueryPromise<HTMLElement>;
/**
* Called when a view cannot be found to provide the opportunity to locate or generate a fallback view. Mainly used to ease development.
* @param {string} viewId The view id whose view should be created.
* @param {string} requirePath The require path that was attempted.
* @param {Error} requirePath The error that was returned from the attempt to locate the default view.
* @returns {Promise} A promise for the fallback view.
*/
createFallbackView(viewId: string, requirePath: string, err: Error): JQueryPromise<HTMLElement>;
}
/**
* Durandal events originate from backbone.js but also combine some ideas from signals.js as well as some additional improvements.
* Events can be installed into any object and are installed into the `app` module by default for convenient app-wide eventing.
* @requires system
*/
declare module 'durandal/events' {
var theModule: DurandalEventModule;
export = theModule;
}
/**
* The binder joins an object instance and a DOM element tree by applying databinding and/or invoking binding lifecycle callbacks (binding and bindingComplete).
* @requires system
* @requires knockout
*/
declare module 'durandal/binder' {
interface BindingInstruction {
applyBindings: boolean;
}
/**
* Called before every binding operation. Does nothing by default.
* @param {object} data The data that is about to be bound.
* @param {DOMElement} view The view that is about to be bound.
* @param {object} instruction The object that carries the binding instructions.
*/
export var binding: (data: any, view: HTMLElement, instruction: BindingInstruction) => void;
/**
* Called after every binding operation. Does nothing by default.
* @param {object} data The data that has just been bound.
* @param {DOMElement} view The view that has just been bound.
* @param {object} instruction The object that carries the binding instructions.
*/
export var bindingComplete: (data: any, view: HTMLElement, instruction: BindingInstruction) => void;
/**
* Indicates whether or not the binding system should throw errors or not.
* @default false The binding system will not throw errors by default. Instead it will log them.
*/
export var throwOnErrors: boolean;
/**
* Gets the binding instruction that was associated with a view when it was bound.
* @param {DOMElement} view The view that was previously bound.
* @returns {object} The object that carries the binding instructions.
*/
export function getBindingInstruction(view: HTMLElement): BindingInstruction;
/**
* Binds the view, preserving the existing binding context. Optionally, a new context can be created, parented to the previous context.
* @param {KnockoutBindingContext} bindingContext The current binding context.
* @param {DOMElement} view The view to bind.
* @param {object} [obj] The data to bind to, causing the creation of a child binding context if present.
* @param {string} [dataAlias] An alias for $data if present.
*/
export function bindContext(bindingContext: KnockoutBindingContext, view: HTMLElement, obj?: any, dataAlias?: string): BindingInstruction;
/**
* Binds the view, preserving the existing binding context. Optionally, a new context can be created, parented to the previous context.
* @param {object} obj The data to bind to.
* @param {DOMElement} view The view to bind.
*/
export function bind(obj: any, view: HTMLElement): BindingInstruction;
}
/**
* The activator module encapsulates all logic related to screen/component activation.
* An activator is essentially an asynchronous state machine that understands a particular state transition protocol.
* The protocol ensures that the following series of events always occur: `canDeactivate` (previous state), `canActivate` (new state), `deactivate` (previous state), `activate` (new state).
* Each of the _can_ callbacks may return a boolean, affirmative value or promise for one of those. If either of the _can_ functions yields a false result, then activation halts.
* @requires system
* @requires knockout
*/
declare module 'durandal/activator' {
/**
* The default settings used by activators.
* @property {ActivatorSettings} defaults
*/
export var defaults: DurandalActivatorSettings;
/**
* Creates a new activator.
* @method create
* @param {object} [initialActiveItem] The item which should be immediately activated upon creation of the ativator.
* @param {ActivatorSettings} [settings] Per activator overrides of the default activator settings.
* @returns {Activator} The created activator.
*/
export function create<T>(initialActiveItem?: T, settings?: DurandalActivatorSettings): DurandalActivator<T>;
/**
* Determines whether or not the provided object is an activator or not.
* @method isActivator
* @param {object} object Any object you wish to verify as an activator or not.
* @returns {boolean} True if the object is an activator; false otherwise.
*/
export function isActivator(object: any): boolean;
}
/**
* The viewLocator module collaborates with the viewEngine module to provide views (literally dom sub-trees) to other parts of the framework as needed. The primary consumer of the viewLocator is the composition module.
* @requires system
* @requires viewEngine
*/
declare module 'durandal/viewLocator' {
var theModule: DurandalViewLocatorModule;
export = theModule;
}
interface DurandalViewLocatorModule {
/**
* Allows you to set up a convention for mapping module folders to view folders. It is a convenience method that customizes `convertModuleIdToViewId` and `translateViewIdToArea` under the covers.
* @param {string} [modulesPath] A string to match in the path and replace with the viewsPath. If not specified, the match is 'viewmodels'.
* @param {string} [viewsPath] The replacement for the modulesPath. If not specified, the replacement is 'views'.
* @param {string} [areasPath] Partial views are mapped to the "views" folder if not specified. Use this parameter to change their location.
*/
useConvention(modulesPath?: string, viewsPath?: string, areasPath?: string): void;
/**
* Maps an object instance to a view instance.
* @param {object} obj The object to locate the view for.
* @param {string} [area] The area to translate the view to.
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateViewForObject(obj: any, area: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
/**
* Converts a module id into a view id. By default the ids are the same.
* @param {string} moduleId The module id.
* @returns {string} The view id.
*/
convertModuleIdToViewId(moduleId: string): string;
/**
* If no view id can be determined, this function is called to genreate one. By default it attempts to determine the object's type and use that.
* @param {object} obj The object to determine the fallback id for.
* @returns {string} The view id.
*/
determineFallbackViewId(obj: any): string;
/**
* Takes a view id and translates it into a particular area. By default, no translation occurs.
* @param {string} viewId The view id.
* @param {string} area The area to translate the view to.
* @returns {string} The translated view id.
*/
translateViewIdToArea(viewId: string, area: string): string;
/**
* Locates the specified view.
* @param {string|DOMElement} view A view. It will be immediately returned.
* @param {string} [area] The area to translate the view to.
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateView(view: HTMLElement, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
/**
* Locates the specified view.
* @param {string|DOMElement} viewUrlOrId A view url or view id to locate.
* @param {string} [area] The area to translate the view to.
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateView(viewUrlOrId: string, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
}
/**
* The composition module encapsulates all functionality related to visual composition.
* @requires system
* @requires viewLocator
* @requires binder
* @requires viewEngine
* @requires activator
* @requires jquery
* @requires knockout
*/
declare module 'durandal/composition' {
interface CompositionTransation {
/**
* Registers a callback which will be invoked when the current composition transaction has completed. The transaction includes all parent and children compositions.
* @param {function} callback The callback to be invoked when composition is complete.
*/
complete(callback: Function): void;
}
interface CompositionContext {
mode: string;
parent: HTMLElement;
activeView: HTMLElement;
triggerAttach(): void;
bindingContext?: KnockoutBindingContext;
cacheViews?: boolean;
viewElements?: HTMLElement[];
model?: any;
view?: any;
area?: string;
preserveContext?: boolean;
activate?: boolean;
strategy?: (context: CompositionContext) => JQueryPromise<HTMLElement>;
composingNewView: boolean;
child: HTMLElement;
binding?: (child: HTMLElement, parent: HTMLElement, context: CompositionContext) => void;
attached?: (child: HTMLElement, parent: HTMLElement, context: CompositionContext) => void;
compositionComplete?: (child: HTMLElement, parent: HTMLElement, context: CompositionContext) => void;
transition?: string;
}
/**
* Converts a transition name to its moduleId.
* @param {string} name The name of the transtion.
* @returns {string} The moduleId.
*/
export function convertTransitionToModuleId(name: string): string;
/**
* The name of the transition to use in all compositions.
* @default null
*/
export var defaultTransitionName: string;
/**
* Represents the currently executing composition transaction.
*/
export var current: CompositionTransation;
/**
* Registers a binding handler that will be invoked when the current composition transaction is complete.
* @param {string} name The name of the binding handler.
* @param {object} [config] The binding handler instance. If none is provided, the name will be used to look up an existing handler which will then be converted to a composition handler.
* @param {function} [initOptionsFactory] If the registered binding needs to return options from its init call back to knockout, this function will server as a factory for those options. It will receive the same parameters that the init function does.
*/
export function addBindingHandler(name, config?: KnockoutBindingHandler, initOptionsFactory?: (element?: HTMLElement, valueAccessor?: any, allBindingsAccessor?: any, viewModel?: any, bindingContext?: KnockoutBindingContext) => any);
/**
* Gets an object keyed with all the elements that are replacable parts, found within the supplied elements. The key will be the part name and the value will be the element itself.
* @param {DOMElement[]} elements The elements to search for parts.
* @returns {object} An object keyed by part.
*/
export function getParts(elements: HTMLElement[]): any;
/**
* Gets an object keyed with all the elements that are replacable parts, found within the supplied element. The key will be the part name and the value will be the element itself.
* @param {DOMElement} element The element to search for parts.
* @returns {object} An object keyed by part.
*/
export function getParts(element: HTMLElement): any;
/**
* Eecutes the default view location strategy.
* @param {object} context The composition context containing the model and possibly existing viewElements.
* @returns {promise} A promise for the view.
*/
export var defaultStrategy: (context: CompositionContext) => JQueryPromise<HTMLElement>;
/**
* Initiates a composition.
* @param {DOMElement} element The DOMElement or knockout virtual element that serves as the parent for the composition.
* @param {object} settings The composition settings.
* @param {object} [bindingContext] The current binding context.
*/
export function compose(element: HTMLElement, settings: CompositionContext, bindingContext: KnockoutBindingContext): void;
}
/**
* The app module controls app startup, plugin loading/configuration and root visual display.
* @requires system
* @requires viewEngine
* @requires composition
* @requires events
* @requires jquery
*/
declare module 'durandal/app' {
var theModule: DurandalAppModule;
export = theModule;
}
/**
* The dialog module enables the display of message boxes, custom modal dialogs and other overlays or slide-out UI abstractions. Dialogs are constructed by the composition system which interacts with a user defined dialog context. The dialog module enforced the activator lifecycle.
* @requires system
* @requires app
* @requires composition
* @requires activator
* @requires viewEngine
* @requires jquery
* @requires knockout
*/
declare module 'plugins/dialog' {
import composition = require('durandal/composition');
/**
* Models a message box's message, title and options.
* @class
*/
class Box {
constructor(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object);
/**
* Selects an option and closes the message box, returning the selected option through the dialog system's promise.
* @param {string} dialogResult The result to select.
*/
selectOption(dialogResult: string): void;
/**
* Provides the view to the composition system.
* @returns {DOMElement} The view of the message box.
*/
getView(): HTMLElement;
/**
* Configures a custom view to use when displaying message boxes.
* @method setViewUrl
* @param {string} viewUrl The view url relative to the base url which the view locator will use to find the message box's view.
*/
static setViewUrl(viewUrl: string): void;
/**
* The title to be used for the message box if one is not provided.
* @default Application
* @static
*/
static defaultTitle: string;
/**
* The options to display in the message box if none are specified.
* @default ['Ok']
* @static
*/
static defaultOptions: string[];
/**
* Sets the classes and styles used throughout the message box markup.
* @method setDefaults
* @param {object} settings A settings object containing the following optional properties: buttonClass, primaryButtonClass, secondaryButtonClass, class, style.
*/
static setDefaults(settings: Object): void;
/**
* The markup for the message box's view.
*/
static defaultViewMarkup: string;
}
interface DialogContext {
/**
* In this function, you are expected to add a DOM element to the tree which will serve as the "host" for the modal's composed view. You must add a property called host to the modalWindow object which references the dom element. It is this host which is passed to the composition module.
* @param {Dialog} theDialog The dialog model.
*/
addHost(theDialog: Dialog);
/**
* This function is expected to remove any DOM machinery associated with the specified dialog and do any other necessary cleanup.
* @param {Dialog} theDialog The dialog model.
*/
removeHost(theDialog: Dialog);
/**
* This function is called after the modal is fully composed into the DOM, allowing your implementation to do any final modifications, such as positioning or animation. You can obtain the original dialog object by using `getDialog` on context.model.
* @param {DOMElement} child The dialog view.
* @param {DOMElement} parent The parent view.
* @param {object} context The composition context.
*/
compositionComplete(child: HTMLElement, parent: HTMLElement, context: composition.CompositionContext);
}
interface Dialog {
owner: any;
context: DialogContext;
activator: DurandalActivator<any>;
close(): JQueryPromise<any>;
settings: composition.CompositionContext;
}
/**
* The constructor function used to create message boxes.
*/
export var MessageBox: Box;
/**
* The css zIndex that the last dialog was displayed at.
*/
export var currentZIndex: number;
/**
* Gets the next css zIndex at which a dialog should be displayed.
* @returns {number} The next usable zIndex.
*/
export function getNextZIndex(): number;
/**
* Determines whether or not there are any dialogs open.
* @returns {boolean} True if a dialog is open. false otherwise.
*/
export function isOpen(): boolean;
/**
* Gets the dialog context by name or returns the default context if no name is specified.
* @param {string} [name] The name of the context to retrieve.
* @returns {DialogContext} True context.
*/
export function getContext(name: string): DialogContext;
/**
* Adds (or replaces) a dialog context.
* @param {string} name The name of the context to add.
* @param {DialogContext} dialogContext The context to add.
*/
export function addContext(name: string, modalContext: DialogContext): void;
/**
* Gets the dialog model that is associated with the specified object.
* @param {object} obj The object for whom to retrieve the dialog.
* @returns {Dialog} The dialog model.
*/
export function getDialog(obj: any): Dialog;
/**
* Closes the dialog associated with the specified object.
* @param {object} obj The object whose dialog should be closed.
* @param {object} results* The results to return back to the dialog caller after closing.
*/
export function close(obj: any, ...results: any[]): void;
/**
* Shows a dialog.
* @param {object|string} obj The object (or moduleId) to display as a dialog.
* @param {object} [activationData] The data that should be passed to the object upon activation.
* @param {string} [context] The name of the dialog context to use. Uses the default context if none is specified.
* @returns {Promise} A promise that resolves when the dialog is closed and returns any data passed at the time of closing.
*/
export function show(obj: any, activationData?: any, context?: string): JQueryPromise<any>;
/**
* Shows a message box.
* @param {string} message The message to display in the dialog.
* @param {string} [title] The title message.
* @param {string[]} [options] The options to provide to the user.
* @param {boolean} [autoclose] Automatically close the the message box when clicking outside?
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
export function showMessage(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object): JQueryPromise<string>;
/**
* Shows a message box.
* @param {string} message The message to display in the dialog.
* @param {string} [title] The title message.
* @param {DialogButton[]} [options] The options to provide to the user.
* @param {boolean} [autoclose] Automatically close the the message box when clicking outside?
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
export function showMessage(message: string, title?: string, options?: DialogButton[], autoclose?: boolean, settings?: Object): JQueryPromise<any>;
/**
* Installs this module into Durandal; called by the framework. Adds `app.showDialog` and `app.showMessage` convenience methods.
* @param {object} [config] Add a `messageBox` property to supply a custom message box constructor. Add a `messageBoxView` property to supply custom view markup for the built-in message box. You can also use messageBoxViewUrl to specify the view url.
*/
export function install(config: Object): void;
}
/**
* This module is based on Backbone's core history support. It abstracts away the low level details of working with browser history and url changes in order to provide a solid foundation for a router.
* @requires system
* @requires jquery
*/
declare module 'plugins/history' {
/**
* The setTimeout interval used when the browser does not support hash change events.
* @default 50
*/
export var interval: number;
/**
* Indicates whether or not the history module is actively tracking history.
*/
export var active: boolean;
/**
* Gets the true hash value. Cannot use location.hash directly due to a bug in Firefox where location.hash will always be decoded.
* @param {string} [window] The optional window instance
* @returns {string} The hash.
*/
export function getHash(window?: Window): string;
/**
* Get the cross-browser normalized URL fragment, either from the URL, the hash, or the override.
* @param {string} fragment The fragment.
* @param {boolean} forcePushState Should we force push state?
* @returns {string} he fragment.
*/
export function getFragment(fragment: string, forcePushState: boolean): string;
/**
* Activate the hash change handling, returning `true` if the current URL matches an existing route, and `false` otherwise.
* @param {HistoryOptions} options.
* @returns {boolean|undefined} Returns true/false from loading the url unless the silent option was selected.
*/
export function activate(options: DurandalHistoryOptions): boolean;
/**
* Disable history, perhaps temporarily. Not useful in a real app, but possibly useful for unit testing Routers.
*/
export function deactivate(): void;
/**
* Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe.
* @returns {boolean} Returns true/false from loading the url.
*/
export function checkUrl(): boolean;
/**
* Attempts to load the current URL fragment. A pass-through to options.routeHandler.
* @returns {boolean} Returns true/false from the route handler.
*/
export function loadUrl(): boolean;
/**
* Save a fragment into the hash history, or replace the URL state if the
* 'replace' option is passed. You are responsible for properly URL-encoding
* the fragment in advance.
* The options object can contain `trigger: false` if you wish to not have the
* route callback be fired, or `replace: true`, if
* you wish to modify the current URL without adding an entry to the history.
* @param {string} fragment The url fragment to navigate to.
* @param {object|boolean} options An options object with optional trigger and replace flags. You can also pass a boolean directly to set the trigger option. Trigger is `true` by default.
* @return {boolean} Returns true/false from loading the url.
*/
export function navigate(fragment: string, trigger?: boolean): boolean;
/**
* Save a fragment into the hash history, or replace the URL state if the
* 'replace' option is passed. You are responsible for properly URL-encoding
* the fragment in advance.
* The options object can contain `trigger: false` if you wish to not have the
* route callback be fired, or `replace: true`, if
* you wish to modify the current URL without adding an entry to the history.
* @param {string} fragment The url fragment to navigate to.
* @param {object|boolean} options An options object with optional trigger and replace flags. You can also pass a boolean directly to set the trigger option. Trigger is `true` by default.
* @return {boolean} Returns true/false from loading the url.
*/
export function navigate(fragment: string, options: DurandalNavigationOptions): boolean;
/**
* Navigates back in the browser history.
*/
export function navigateBack(): void;
}
/**
* Enables common http request scenarios.
* @requires jquery
* @requires knockout
*/
declare module 'plugins/http' {
/**
* The name of the callback parameter to inject into jsonp requests by default.
* @default callback
*/
export var callbackParam: string;
/**
* Converts the data to JSON.
* @param {object} data The data to convert to JSON.
* @return {string} JSON.
*/
export function toJSON(data: Object): string;
/**
* Makes an HTTP GET request.
* @param {string} url The url to send the get request to.
* @param {object} [query] An optional key/value object to transform into query string parameters.
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the get response data.
*/
export function get(url: string, query?: Object, headers?: Object): JQueryPromise<any>;
/**
* Makes an JSONP request.
* @param {string} url The url to send the get request to.
* @param {object} [query] An optional key/value object to transform into query string parameters.
* @param {string} [callbackParam] The name of the callback parameter the api expects (overrides the default callbackParam).
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the response data.
*/
export function jsonp(url: string, query?: Object, callbackParam?: string, headers?: Object): JQueryPromise<any>;
/**
* Makes an HTTP POST request.
* @param {string} url The url to send the post request to.
* @param {object} data The data to post. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the response data.
*/
export function post(url: string, data: Object, headers?: Object): JQueryPromise<any>;
/**
* Makes an HTTP PUT request.
* @method put
* @param {string} url The url to send the put request to.
* @param {object} data The data to put. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @return {Promise} A promise of the response data.
*/
export function put(url: string, data: Object, headers?: Object): JQueryPromise<any>;
/**
* Makes an HTTP DELETE request.
* @method remove
* @param {string} url The url to send the delete request to.
* @param {object} [query] An optional key/value object to transform into query string parameters.
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @return {Promise} A promise of the get response data.
*/
export function remove(url: string, query?: Object, headers?: Object): JQueryPromise<any>;
}
/**
* Enables automatic observability of plain javascript object for ES5 compatible browsers. Also, converts promise properties into observables that are updated when the promise resolves.
* @requires system
* @requires binder
* @requires knockout
*/
declare module 'plugins/observable' {
function observable(obj: any, property: string): KnockoutObservable<any>;
module observable {
/**
* Converts an entire object into an observable object by re-writing its attributes using ES5 getters and setters. Attributes beginning with '_' or '$' are ignored.
* @param {object} obj The target object to convert.
*/
export function convertObject(obj: any): void;
/**
* Converts a normal property into an observable property using ES5 getters and setters.
* @param {object} obj The target object on which the property to convert lives.
* @param {string} propertyName The name of the property to convert.
* @param {object} [original] The original value of the property. If not specified, it will be retrieved from the object.
* @returns {KnockoutObservable} The underlying observable.
*/
export function convertProperty(obj: any, propertyName: string, original?: any): KnockoutObservable<any>;
/**
* Defines a computed property using ES5 getters and setters.
* @param {object} obj The target object on which to create the property.
* @param {string} propertyName The name of the property to define.
* @param {function|object} evaluatorOrOptions The Knockout computed function or computed options object.
* @returns {KnockoutComputed} The underlying computed observable.
*/
export function defineProperty<T>(obj: any, propertyName: string, evaluatorOrOptions?: KnockoutComputedDefine<T>);
/**
* Installs the plugin into the view model binder's `beforeBind` hook so that objects are automatically converted before being bound.
*/
export function install(config: Object): void;
}
export = observable;
}
/**
* Serializes and deserializes data to/from JSON.
* @requires system
*/
declare module 'plugins/serializer' {
interface SerializerOptions {
/**
* The default replacer function used during serialization. By default properties starting with '_' or '$' are removed from the serialized object.
* @param {string} key The object key to check.
* @param {object} value The object value to check.
* @returns {object} The value to serialize.
*/
replacer?: (key: string, value: any) => any;
/**
* The amount of space to use for indentation when writing out JSON.
* @default undefined
*/
space: any;
}
interface DeserializerOptions {
/**