diff --git a/durandal/durandal.d.ts b/durandal/durandal.d.ts index 2c1660d89..5ba4d5130 100644 --- a/durandal/durandal.d.ts +++ b/durandal/durandal.d.ts @@ -1,527 +1,1718 @@ -// Type definitions for durandal 1.1.1 -// Project: http://durandaljs.com -// Definitions by: Evan Larsen -// Definitions: https://github.com/borisyankov/DefinitelyTyped +/** + * Durandal 2.0.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. + */ /// /// -declare module "durandal/system" { +/** + * The system module encapsulates the most basic features used by other modules. + * @requires require + * @requires jquery + */ +declare module 'durandal/system' { /** - * Returns the module id associated with the specified object - */ - export var getModuleId: (obj: any) => string; - /** - * Sets the module id on the module. - */ - export var setModuleId: (obj, id: string) => void; - /** - * Call this function to enable or disable Durandal's debug mode. Calling it with no parameters will return true if the framework is currently in debug mode, false otherwise. - */ - export var debug: (debug?: boolean) => boolean; - /** - * Checks if the obj is an array - */ - export var isArray: (obj: any) => 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. - */ - export var log: (...msgs: any[]) => 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. - */ - export var defer: (action?: Function) => JQueryDeferred; - /** - * 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. - */ - export var guid: () => string; - /** - * Uses require.js to obtain a module. This function returns a promise which resolves with the module instance. You can pass more than one module id to this function. If more than one is passed, then the promise will resolve with one callback parameter per module. - */ - export var acquire: (...modules: string[]) => JQueryPromise; -} + * Durandal's version. + */ + export var version: string; -declare module "durandal/app" { /** - * Sets the title for the app. You must set this before calling start. This will set the document title and the default message box header. It is also used internally by the router to set the document title when pages change. - */ - export var title: string; - /** - * simple helper function that wraps a call to modalDialog.show() - */ - export var showModal: (obj, activationData?, context?) => JQueryPromise; - /** - * A simple helper function that translates to return modalDialog.show(new MessageBox(message, title, options)); - */ - export var showMessage: (message: string, title?: string, options?: any) => JQueryPromise; - /** - * Call this function to bootstrap the Durandal framework. It returns a promise which is resolved when the framework is configured and the dom is ready. At that point you are ready to set your root. - */ - export var start: () => JQueryPromise; - /** - * This sets the root view or view model and displays the composed application in the specified application host. - * @param root parameter is required and can be anything that the composition module understands as a view or view model. This includes strings and objects. - * @param transition If you have a splash screen, you may want to specify an optional transition to animate from the splash to your main shell. - * @param applicationHost parameter is optional. If provided it should be an element id for the node into which the UI should be composed. If it is not provided the default is to look for an element with an id of "applicationHost". - */ - export var setRoot: (root: any, transition?: string, applicationHost?: string) => void; - /** - * If you intend to run on mobile, you should also call app.adaptToDevice() before setting the root. - */ - export var adaptToDevice: () => void; - /** - * The events parameter is a space delimited string containing one or more event identifiers. When one of these events is triggered, the callback is called and passed the event data provided by the trigger. The special events value of "all" binds all events on the object to the callback. If a context is provided, it will be bound to this for the callback. If the callback is omitted, then a promise-like object is returned from on. This object represents a subscription and has a then function used to register callbacks. - */ - export var on: (events: string, callback: Function, context?) => IEventSubscription; - /** - * Unwires callbacks from events. If no context is specified, all callbacks with different contexts will be removed. If no callback is specified, all callbacks for the event will be removed. If no event is specified, all event callbacks on the object will be removed. - */ - export var off: (events: string, callback: Function, context?) => any; - /** - * Triggers an event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks. - */ - export var trigger: (events: string, ...args: any[]) => any; - /** - * Provides a function which can be used as a callback to trigger the events. This is useful in combination with jQuery events which may need to trigger the aggregator's events. - */ - export var proxy: (events) => Function; -} + * A noop function. + */ + export var noop: Function; -declare module "durandal/composition" { /** - * sets activate: true on every compose binding - */ - export var activateDuringComposition: boolean; - /** - * changes the convention for finding where transitions are located - */ - export var convertTransitionToModuleId: (name: string) => string; - /** - * sets a default transition for all compositions - */ - export var defaultTransitionName: string; - /** - * the default implementation for switching the content during composition - */ - export var switchContent: (parent: HTMLElement, newChild: HTMLElement, settings: any) => void; - /** - * the default implementation on binding and showing content during composition - */ - export var bindAndShow: (element: HTMLElement, view: HTMLElement, settings: any) => void; - /** - * the default strategy which is: return viewLocator.locateViewForObject(settings.model, settings.viewElements); - */ - export var defaultStrategy: (settings: any) => JQueryPromise; - /** - * the default method for getting settings from the binding handler compose. - */ - export var getSettings: (valueAccessor: any) => any; - /** - * the default method for executing a strategy during composition - */ - export var executeStrategy: (element: HTMLElement, settings: any) => void; - /** - * the default method for injecting during composition - */ - export var inject: (element: HTMLElement, settings: any) => void; - /** - * the default method for composing - */ - export var compose: (element: HTMLElement, settings: any, bindingContext: any) => void; -} + * 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. + */ + export function getModuleId(obj: any): string; -declare module "durandal/http" { /** - * the default is 'callback' - */ - export var defaultJSONPCallbackParam: string; - /** - * Performs an HTTP GET request on the specified URL. This function returns a promise which resolves with the returned response data. You can optionally return a query object whose properties will be used to construct a query string. - */ - export var get: (url: string, query: Object) => JQueryPromise; - /** - * Performs a JSONP request to the specified url. You can optionally include a query object whose properties will be used to construct the query string. Also, you can pass the name of the API's callback parameter. If none is specified, it defaults to "callback". This api returns a promise. If you are using a callback parameter other than "callback" consistently throughout your application, then you may want to set the http module's defaultJSONPCallbackParam so that you don't need to specify it on every request. - */ - export var jsonp: (url: string, query: Object, callbackParam: string) => JQueryPromise; - /** - * Performs an HTTP POST request on the specified URL with the supplied data. The data object is converted to JSON and the request is sent with an application/json content type. Thie function returns a promise which resolves with the returned response data. - */ - export var post: (url: string, data: Object) => JQueryPromise; -} + * 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. + */ + export function setModuleId(obj, id: string): void; -declare module "durandal/modalDialog" { /** - * the default is 1050 - */ - export var currentZIndex: number; - /** - * This is a helper function which can be used in the creation of custom modal contexts. Each time it is called, it returns a successively higher zIndex value than the last time. - */ - export var getNextZIndex: () => number; - /** - * This is a helper function which will tell you if any modals are currently open. - */ - export var isModalOpen: () => boolean; - /** - * You may wish to customize modal displays or add additional contexts in order to display modals in different ways. To alter the default context, you would acquire it by calling getContext() and then alter it's pipeline. If you don't provide a value for name it returns the default context. - */ - export var getContext: (name: string) => any; - /** - * Pass a name and an object which defines the proper modal display pipeline via the functions described in the next section. This creates a new modal context or "modal style." - */ - export var addContext: (name: string, modalContext: any) => JQueryPromise; - /** - * creates a settings obj from the supplied params - */ - export var createCompositionSettings: (obj: any, modalContext: any) => any; - /** - * This API uses the composition module to compose your obj into a modal popover. It also uses the viewModel module to check and enforce any screen lifecycle needs that obj may have. A promise is returned which will be resolved when the modal dialog is dismissed. The obj is the view model for your modal dialog, or a moduleId for the view model to load. Your view model instance will have a single property added to it by this mechanism called modal which represents the dialog infrastructure itself. This modal object has a single function called close which can be invoked to close the modal. You may also pass data to close which will be returned via the promise mechanism. The modal object also references it's owner, activator, the composition settings it was created with and its display context. Speaking of context, this parameter represents the display context or modal style. By default, there is one context registered with the system, named 'default'. If no context is specified, the default context with be used to display the modal. You can also specify activationData which is an arbitrary object that will be passed to your modal's activate function, if it has one. - */ - export var show: (obj: any, activationData: any, context: any) => JQueryPromise; -} + * 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. + */ + export function resolveObject(module: any): any; -declare module "durandal/viewEngine" { /** - * The file extension that view source files are expected to have. - */ - export var 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). - */ - export var viewPlugin: string; - /** - * Returns true if the potential string is a url for a view, according to the view engine. - */ - export var isViewUrl: (url: string) => boolean; - /** - * Converts a view url into a view id. - */ - export var convertViewUrlToViewId: (url: string) => string; - /** - * Converts a view id into a full RequireJS path. - */ - export var convertViewIdToRequirePath: (viewId: string) => string; - /** - * Parses some markup and turns it into a dom element. - */ - export var parseMarkup: (markup: string) => HTMLElement; - /** - * Returns a promise for a dom element identified by the viewId parameter. - */ - export var createView: (viewId: string) => JQueryPromise; -} + * 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. + */ + export function debug(enable?: boolean): boolean; -declare module "durandal/viewLocator" { /** - * Allows you to set up a convention for mapping module folders to view folders. modulesPath is a string in the path that will be replaced by viewsPath. Partial views will be mapped to the "views" folder unless an areasPath is specified. All parameters are optional. If none are specified, the convention will map modules in a "viewmodels" folder to views in a "views" folder. - */ - export var useConvention: (modulesPath?: string, viewsPath?: string, areasPath?: string) => string; - /** - * This function takes in an object instance, which it then maps to a view id. That id is then passed to the locateView function and it is processed as above. If elementsToSearch are provided, those are passed along to locateView. Following is a description of how locateViewForObject determines the view for a given object instance. - */ - export var locateViewForObject: (obj: {}, elementsToSearch: HTMLElement[]) => JQueryPromise; - /** - * This function does nothing by default which is why editCustomer.js is mapped to editCustomer.html (both have the same underlying id of editCustomer). Replace this function with your own implementation to easily create your own mapping logic based on moduleId. - */ - export var convertModuleIdToViewId: (moduleId: string) => string; - /** - * As mentioned above, if no view id can be determined, the system falls back to attempting to determine the object's type and then uses that. This function contains the implementation of that fallback behavior. Replace it if you desire something different. Under normal usage however, this function should not be called. - */ - export var determineFallbackViewId: (obj: any) => string; - /** - * When a view area is specified, it along with the requested view id will be passed to this function, allowing you to customize the path of your view. You can specify area as part of the locateView call, but more commonly you would specify it as part of a compose binding. Any compose binding that does not include a model, but only a view, has a default area of 'partial'. - */ - export var translateViewIdToArea: (viewId: string, area?: string) => string; - /** - * The viewOrUrlOrId parameter represents a url/id for the view. The file extension is not necessary (ie. .html). When this function is called, the viewEngine will be used to construct the view. The viewEngine is passed the finalized id and returns a constructed DOM sub-tree, which is returned from this function. If the viewOrUrlOrId is not a string but is actually a DOM node, then the DOM node will be immediately returned. Optionally, you can pass an area string and it along with the url will be passed to the view locator's translateViewIdToArea before constructing the final id to pass to the view engine. If you provide an array of DOM elements for elementsToSearch, before we call the view engine, we will search the existing array for a match and return it if found. - */ - export var locateView: (viewOrUrlOrId: any, area: string, elementsToSearch: HTMLElement[]) => JQueryPromise; -} + * 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. + */ + export function log(...msgs: any[]): void; -declare module "durandal/viewModel" { /** - * A property which is the home to some basic settings and functions that control how all activators work. These are used to create the instance settings object for each activator. They can be overriden on a per-instance-basis by passing a settings object when creating an activator or by accessing the settings property of the activator. To change them for all activators, change them on the defaults property. The two most common customizations are presented below. See the source for additional information. - */ - export var defaults: IViewModelDefaults; - /** - * This creates a computed observable which enforces a lifecycle on all values the observable is set to. When creating the activator, you can specify an initialActiveItem to activate. You can also specify a settings object. Use of the settings object is for advanced scenarios and will not be detailed much here. - */ - export var activator: { - (): IDurandalViewModelActiveItem; - (initialActiveItem: any, settings?: IViewModelDefaults): IDurandalViewModelActiveItem; - }; -} + * Logs an error. + * @param {string} obj The error to report. + */ + export function error(error: string): void; -declare module "durandal/viewModelBinder" { /** - * Applies bindings to a view using a pre-existing bindingContext. This is used by the composition module when a view is supplied without a model. It allows the parent binding context to be preserved. If the optional obj parameter is supplied, a new binding context will be created that is a child of bindingContext with its model set to obj. This is used by the widget framework to provide the widget binding while allowing templated parts to access their surrounding scope. - */ - export var bindContext: (bindingContext: KnockoutBindingContext, view: HTMLElement, obj?: any) => void; - /** - * Databinds obj, which can be an arbitrary object, to view which is a dom sub-tree. If obj has a function called setView, then, following binding, this function will be called, providing obj with an opportunity to interact directly with the dom fragment that it is bound to. - */ - export var bind: (obj: any, view: HTMLElement) => void; -} + * Logs an error. + * @param {Error} obj The error to report. + */ + export function error(error: Error): void; -interface IViewModelDefaults { /** - * When the activator attempts to activate an item as described below, it will only activate the new item, by default, if it is a different instance than the current. Overwrite this function to change that behavior. - */ - areSameItem(currentItem, newItem, activationData): boolean; - /** - * default is true - */ - closeOnDeactivate: boolean; - /** - * Interprets values returned from guard methods like canActivate and canDeactivate by transforming them into bools. The default implementation translates string values "Yes" and "Ok" as true...and all other string values as false. Non string values evaluate according to the truthy/falsey values of JavaScript. Replace this function with your own to expand or set up different values. This transformation is used by the activator internally and allows it to work smoothly in the common scenario where a deactivated item needs to show a message box to prompt the user before closing. Since the message box returns a promise that resolves to the button option the user selected, it can be automatically processed as part of the activator's guard check. - */ - interpretResponse(value: any): boolean; - /** - * called before activating a module - */ - beforeActivate(newItem: any): any; - /** - * called after deactivating a module - */ - afterDeactivate(): any; -} + * 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. + */ + export function assert(condition: boolean, message: string): void; -interface IDurandalViewModelActiveItem { /** - * knockout observable - */ - (val?): any; + * 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. + */ + export function defer(action?: (dfd: JQueryDeferred) => void ): JQueryDeferred; + /** - * A property which is the home to some basic settings and functions that control how all activators work. These are used to create the instance settings object for each activator. They can be overriden on a per-instance-basis by passing a settings object when creating an activator or by accessing the settings property of the activator. To change them for all activators, change them on the defaults property. The two most common customizations are presented below. See the source for additional information. - */ - settings: IViewModelDefaults; + * 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. + */ + export function guid(): string; + /** - * This observable is set internally by the activator during the activation process. It can be used to determine if an activation is currently happening. - */ - isActivating(val?: boolean): boolean; + * 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. + */ + export function acquire(moduleId: string): JQueryPromise; + /** - * Pass a specific item as well as an indication of whether it should be closed, and this function will tell you the answer. - */ - canDeactivateItem(item, close): JQueryPromise; + * 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. + */ + export function acquire(modules: string[]): JQueryPromise; + /** - * Deactivates the specified item (optionally closing it). Deactivation follows the lifecycle and thus only works if the item can be deactivated. - */ - deactivateItem(item, close): JQueryDeferred; + * 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. + */ + export function acquire(...moduleIds: string[]): JQueryPromise; + /** - * Determines if a specific item can be activated. You can pass an arbitrary object to this function, which will be passed to the item's canActivate function , if present. This is useful if you are manually controlling activation and you want to provide some context for the operation. - */ - canActivateItem(newItem, activationData?): JQueryPromise; + * 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. + */ + export function extend(obj: any, ...extensions: any[]): any; + /** - * Activates a specific item. Activation follows the lifecycle and thus only occurs if possible. activationData functions as stated above. - */ - activateItem(newItem, activationData?): JQueryPromise; + * Uses a setTimeout to wait the specified milliseconds. + * @param {number} milliseconds The number of milliseconds to wait. + * @returns {JQueryPromise} + */ + export function wait(milliseconds: number): JQueryPromise; + /** - * Checks whether or not the activator itself can be activated...that is whether or not it's current item or initial value can be activated. - */ - canActivate(): JQueryPromise; + * Gets all the owned keys of the specified object. + * @param {object} object The object whose owned keys should be returned. + * @returns {string[]} The keys. + */ + export function keys(obj: any): string[]; + /** - * Activates the activator...that is..it activates it's current item or initial value. - */ - activate(): JQueryPromise; + * 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. + */ + export function isElement(obj: any): boolean; + /** - * Checks whether or not the activator itself can be deactivated...that is whether or not it's current item can be deactivated. - */ - canDeactivate(): JQueryPromise; + * Determines if the specified object is an array. + * @param {object} object The object to check. + * @returns {boolean} True if matches the type, false otherwise. + */ + export function isArray(obj: any): boolean; + /** - * Deactivates the activator...interpreted as deactivating its current item. - */ - deactivate(): JQueryDeferred; + * Determines if the specified object is a boolean. + * @param {object} object The object to check. + * @returns {boolean} True if matches the type, false otherwise. + */ + export function isObject(obj: any): boolean; + /** - * Adds canActivate, activate, canDeactivate and deactivate functions to the provided model which pass through to the corresponding functions on the activator. - */ - includeIn(includeIn: any): JQueryPromise; + * Determines if the specified object is a promise. + * @param {object} object The object to check. + * @returns {boolean} True if matches the type, false otherwise. + */ + export function isPromise(obj: any): boolean; + /** - * Sets up a collection representing a pool of objects which the activator will activate. See below for details. Activators without an item boolean always close their values on deactivate. Activators with an items pool only deactivate, but do not close them. - */ - forItems(items): IDurandalViewModelActiveItem; + * 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function isBoolean(obj: any): boolean; } /** - * A router plugin, currently based on SammyJS. The router abstracts away the core configuration of Sammy and re-interprets it in terms of durandal's composition and activation mechanism. To use the router, you must require it, configure it and bind it in the UI. - * Documentation at http://durandaljs.com/documentation/Router/ - */ -declare module "durandal/plugins/router" { + * 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' { /** - * Parameters to the map function. or information on route url patterns, see the SammyJS documentation. But - * basically, you can have simple routes my/route/, parameterized routes customers/:id or Regex routes. If you - * have a parameter in your route, then the activation data passed to your module's activate function will have a - * property for every parameter in the route (rather than the splat array, which is only present for automapped - * routes). - */ - interface IRouteInfo { - url: string; - moduleId: string; - name: string; - /** used to set the document title */ - caption: string; - /** determines whether or not to include it in the router's visibleRoutes array for easy navigation UI binding */ - visible: boolean; - settings: Object; - hash: string; - /** only present on visible routes to track if they are active in the nav */ + * The file extension that view source files are expected to have. + * @default .html + */ + export var 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 + */ + export var viewPlugin: 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. + */ + export function isViewUrl(url: string):boolean; + + /** + * Converts a view url into a view id. + * @param {string} url The url to convert. + * @returns {string} The view id. + */ + export function 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. + */ + export function 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. + */ + export function parseMarkup(markup: string):Node[]; + + /** + * Calls `parseMarkup` and then pipes the results through `ensureSingleElement`. + * @param {string} markup The markup to process. + * @returns {HTMLElement} The view. + */ + export function 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. + */ + export function ensureSingleElement(allElements: Node[]): HTMLElement; + + /** + * Creates the view associated with the view id. + * @param {string} viewId The view id whose view should be created. + * @returns {JQueryPromise} A promise of the view. + */ + export function createView(viewId: string): JQueryPromise; + + /** + * 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. + */ + export function createFallbackView(viewId: string, requirePath: string, err: Error): JQueryPromise; +} + +/** + * 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' { + import ts = require('durandal/typescript'); + + /** + * Creates an object with eventing capabilities. + * @class Events + */ + class Events { + constructor(); + + /** + * Creates a subscription or registers a callback for the specified event. + * @param {string} events One or more events, separated by white space. + * @returns {Subscription} A subscription is returned. + */ + on(events: string): ts.EventSubscription; + + /** + * Creates a subscription or registers a callback for the specified event. + * @param {string} events One or more events, separated by white space. + * @param {function} [callback] The callback function to invoke when the event is triggered. + * @param {object} [context] An object to use as `this` when invoking the `callback`. + * @returns {Events} The events object is returned for chaining. + */ + on(events: string, callback: Function, context?: any): Events; + + /** + * Removes the callbacks for the specified events. + * @param {string} [events] One or more events, separated by white space to turn off. If no events are specified, then the callbacks will be removed. + * @param {function} [callback] The callback function to remove. If `callback` is not provided, all callbacks for the specified events will be removed. + * @param {object} [context] The object that was used as `this`. Callbacks with this context will be removed. + * @chainable + */ + off(events: string, callback: Function, context?: any): Events; + + /** + * Triggers the specified events. + * @param {string} [events] One or more events, separated by white space to trigger. + * @chainable + */ + trigger(events: string, ...eventArgs: any[]): Events; + + /** + * Creates a function that will trigger the specified events when called. Simplifies proxying jQuery (or other) events through to the events object. + * @param {string} events One or more events, separated by white space to trigger by invoking the returned function. + * @returns {function} Calling the function will invoke the previously specified events on the events object. + */ + proxy(events: string): Function; + + /** + * Adds eventing capabilities to the specified object. + * @param {object} targetObject The object to add eventing capabilities to. + */ + static includeIn(targetObject: any): void; + } + + export = Events; +} + +/** + * 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. + */ + export function bindContext(bindingContext: KnockoutBindingContext, view: HTMLElement, obj?: any): 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' { + interface ActivatorSettings { + /** + * The default value passed to an object's deactivate function as its close parameter. + * @default true + */ + closeOnDeactivate: boolean; + + /** + * Lower-cased words which represent a truthy value. + * @default ['yes', 'ok', 'true'] + */ + affirmations: string[]; + + /** + * Interprets the response of a `canActivate` or `canDeactivate` call using the known affirmative values in the `affirmations` array. + * @param {object} value + * @returns {boolean} + */ + interpretResponse(value: any): boolean; + + /** + * Determines whether or not the current item and the new item are the same. + * @param {object} currentItem + * @param {object} newItem + * @param {object} currentActivationData + * @param {object} newActivationData + * @returns {boolean} + */ + areSameItem(currentItem: any, newItem: any, currentActivationData: any, newActivationData: any): boolean; + + /** + * Called immediately before the new item is activated. + * @param {object} newItem + */ + beforeActivate(newItem: any): any; + + /** + * Called immediately after the old item is deactivated. + * @param {object} oldItem The previous item. + * @param {boolean} close Whether or not the previous item was closed. + * @param {function} setter The activate item setter function. + */ + afterDeactivate(oldItem: any, close: boolean, setter: Function): void; + } + + interface Activator extends KnockoutComputed { + /** + * The settings for this activator. + */ + settings: ActivatorSettings; + + /** + * An observable which indicates whether or not the activator is currently in the process of activating an instance. + * @returns {boolean} + */ + isActivating: KnockoutObservable; + + /** + * Determines whether or not the specified item can be deactivated. + * @param {object} item The item to check. + * @param {boolean} close Whether or not to check if close is possible. + * @returns {promise} + */ + canDeactivateItem(item: T, close: boolean): JQueryPromise; + + /** + * Deactivates the specified item. + * @param {object} item The item to deactivate. + * @param {boolean} close Whether or not to close the item. + * @returns {promise} + */ + deactivateItem(item: T, close: boolean): JQueryPromise; + + /** + * Determines whether or not the specified item can be activated. + * @param {object} item The item to check. + * @param {object} activationData Data associated with the activation. + * @returns {promise} + */ + canActivateItem(newItem: T, activationData?: any): JQueryPromise; + + /** + * Activates the specified item. + * @param {object} newItem The item to activate. + * @param {object} newActivationData Data associated with the activation. + * @returns {promise} + */ + activateItem(newItem: T, activationData?: any): JQueryPromise; + + /** + * Determines whether or not the activator, in its current state, can be activated. + * @returns {promise} + */ + canActivate(): JQueryPromise; + + /** + * Activates the activator, in its current state. + * @returns {promise} + */ + activate(): JQueryPromise; + + /** + * Determines whether or not the activator, in its current state, can be deactivated. + * @returns {promise} + */ + canDeactivate(close: boolean): JQueryPromise; + + /** + * Deactivates the activator, in its current state. + * @returns {promise} + */ + deactivate(close: boolean): JQueryPromise; + + /** + * Adds canActivate, activate, canDeactivate and deactivate functions to the provided model which pass through to the corresponding functions on the activator. + */ + includeIn(includeIn: any): void; + + /** + * Sets up a collection representing a pool of objects which the activator will activate. See below for details. Activators without an item bool always close their values on deactivate. Activators with an items pool only deactivate, but do not close them. + */ + forItems(items): Activator; + } + + /** + * The default settings used by activators. + * @property {ActivatorSettings} defaults + */ + export var defaults: ActivatorSettings; + + /** + * 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(initialActiveItem?: T, settings?: ActivatorSettings): Activator; + + /** + * 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' { + /** + * 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. + */ + export function 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. + */ + export function locateViewForObject(obj: any, area:string, elementsToSearch?: HTMLElement[]): JQueryPromise; + + /** + * 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function locateView(view: HTMLElement, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise; + + /** + * 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. + */ + export function locateView(viewUrlOrId: string, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise; +} + +/** + * 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; + 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; + tranistion?: 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; + + /** + * 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' { + import Events = require('durandal/events'); + import ts = require('durandal/typescript'); + + /** + * The title of your application. + */ + export var title: string; + + /** + * Shows a dialog via the dialog plugin. + * @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 showDialog(obj: any, activationData?: any, context?: string):JQueryPromise; + + /** + * Shows a message box via the dialog plugin. + * @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. + * @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[]): JQueryPromise; + + /** + * Configures one or more plugins to be loaded and installed into the application. + * @method configurePlugins + * @param {object} config Keys are plugin names. Values can be truthy, to simply install the plugin, or a configuration object to pass to the plugin. + * @param {string} [baseUrl] The base url to load the plugins from. + */ + export function configurePlugins(config: Object, baseUrl?: string): void; + + /** + * Starts the application. + * @returns {promise} + */ + export function start(): JQueryPromise; + + /** + * Sets the root module/view for the application. + * @param {string} root The root view or module. + * @param {string} [transition] The transition to use from the previous root (or splash screen) into the new root. + * @param {string} [applicationHost] The application host element id. By default the id 'applicationHost' will be used. + */ + export function setRoot(root: any, transition?: string, applicationHost?: string): void; + + /** + * Sets the root module/view for the application. + * @param {string} root The root view or module. + * @param {string} [transition] The transition to use from the previous root (or splash screen) into the new root. + * @param {string} [applicationHost] The application host element. By default the id 'applicationHost' will be used. + */ + export function setRoot(root: any, transition?: string, applicationHost?: HTMLElement): void; + + /** + * Creates a subscription or registers a callback for the specified event. + * @param {string} events One or more events, separated by white space. + * @returns {Subscription} A subscription is returned. + */ + export function on(events: string): ts.EventSubscription; + + /** + * Creates a subscription or registers a callback for the specified event. + * @param {string} events One or more events, separated by white space. + * @param {function} [callback] The callback function to invoke when the event is triggered. + * @param {object} [context] An object to use as `this` when invoking the `callback`. + * @returns {Events} The events object is returned for chaining. + */ + export function on(events: string, callback: Function, context?: any): Events; + + /** + * Removes the callbacks for the specified events. + * @param {string} [events] One or more events, separated by white space to turn off. If no events are specified, then the callbacks will be removed. + * @param {function} [callback] The callback function to remove. If `callback` is not provided, all callbacks for the specified events will be removed. + * @param {object} [context] The object that was used as `this`. Callbacks with this context will be removed. + * @chainable + */ + export function off(events: string, callback: Function, context?: any): Events; + + /** + * Triggers the specified events. + * @param {string} [events] One or more events, separated by white space to trigger. + * @chainable + */ + export function trigger(events: string, ...eventArgs:any[]): Events; + + /** + * Creates a function that will trigger the specified events when called. Simplifies proxying jQuery (or other) events through to the events object. + * @param {string} events One or more events, separated by white space to trigger by invoking the returned function. + * @returns {function} Calling the function will invoke the previously specified events on the events object. + */ + export function proxy(events: string): Function; +} + +/** + * 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 activator = require('durandal/activator'); + import composition = require('durandal/composition'); + + /** + * Models a message box's message, title and options. + * @class + */ + class Box { + constructor(message: string, title: string, options: string[]); + + /** + * 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. + */ + selectOptions(dialogResult: string): void; + + /** + * Provides the view to the composition system. + * @returns {DOMElement} The view of the message box. + */ + getView(): HTMLElement; + + /** + * 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 of none are specified. + * @default ['Ok'] + * @static + */ + static defaultOptions: string[]; + + /** + * The markup for the message box's view. + * @static + */ + static defaultViewMarkup: string; + + /** + * Configures a custom view to use when displaying message boxes. + * @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 + */ + static setViewUrl(url:string):void; + } + + 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: activator.Activator; + close(): JQueryPromise; + 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} result* The results to return back to the dialog caller after closing. + */ + export function close(obj: 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; + + /** + * 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. + * @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[]): JQueryPromise; + + /** + * 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. + */ + 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' { + interface HistoryOptions { + /** + * The function that will be called back when the fragment changes. + */ + routeHandler: (fragment: string) => void; + + /** + * The url root used to extract the fragment when using push state. + */ + root?: string; + + /** + * Use hash change when present. + * @default true + */ + hashChange?: boolean; + + /** + * Use push state when present. + * @default false + */ + pushState?: boolean; + + /** + * Prevents loading of the current url when activating history. + * @default false + */ + silent?: boolean; + } + + interface NavigationOptions { + trigger: boolean; + replace: boolean; + } + + /** + * 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: HistoryOptions): 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: NavigationOptions): 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; + + /** + * 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. + * @returns {Promise} A promise of the get response data. + */ + export function get(url: string, query?: Object): JQueryPromise; + + /** + * 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). + * @returns {Promise} A promise of the response data. + */ + export function jsonp(url: string, query?: Object, callbackParam?: string): JQueryPromise; + + /** + * 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. + * @returns {Promise} A promise of the response data. + */ + export function post(url: string, data: Object): JQueryPromise; +} + +/** + * 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; + + 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; + + /** + * 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(obj: any, propertyName: string, evaluatorOrOptions?: KnockoutComputedDefine); + + /** + * 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 { + /** + * Gets the type id for an object instance, using the configured `typeAttribute`. + * @param {object} object The object to serialize. + * @returns {string} The type. + */ + getTypeId: (object: any) => string; + + /** + * Gets the constructor based on the type id. + * @param {string} typeId The type id. + * @returns {Function} The constructor. + */ + getConstructor: (typeId: string) => () => any; + + /** + * The default reviver function used during deserialization. By default is detects type properties on objects and uses them to re-construct the correct object using the provided constructor mapping. + * @param {string} key The attribute key. + * @param {object} value The object value associated with the key. + * @returns {object} The value. + */ + reviver: (key: string, value: any) => any; + } + + /** + * The name of the attribute that the serializer should use to identify an object's type. + * @default type + */ + export var typeAttribute: string; + + /** + * The amount of space to use for indentation when writing out JSON. + * @default undefined + */ + export var space: any; + + /** + * 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. + */ + export function replacer(key: string, value: any): any; + + /** + * Serializes the object. + * @param {object} object The object to serialize. + * @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults. + * @returns {string} The JSON string. + */ + export function serialize(object: any, settings?: string); + + /** + * Serializes the object. + * @param {object} object The object to serialize. + * @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults. + * @returns {string} The JSON string. + */ + export function serialize(object: any, settings?: number); + + /** + * Serializes the object. + * @param {object} object The object to serialize. + * @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults. + * @returns {string} The JSON string. + */ + export function serialize(object: any, settings?: SerializerOptions); + + /** + * Gets the type id for an object instance, using the configured `typeAttribute`. + * @param {object} object The object to serialize. + * @returns {string} The type. + */ + export function getTypeId(object: any): string; + + /** + * Maps type ids to object constructor functions. Keys are type ids and values are functions. + */ + export var typeMap: any; + + /** + * Adds a type id/constructor function mampping to the `typeMap`. + * @param {string} typeId The type id. + * @param {function} constructor The constructor. + */ + export function registerType(typeId: string, constructor: () => any); + + /** + * The default reviver function used during deserialization. By default is detects type properties on objects and uses them to re-construct the correct object using the provided constructor mapping. + * @param {string} key The attribute key. + * @param {object} value The object value associated with the key. + * @param {function} getTypeId A custom function used to get the type id from a value. + * @param {object} getConstructor A custom function used to get the constructor function associated with a type id. + * @returns {object} The value. + */ + export function reviver(key: string, value: any, getTypeId: (value: any) => string, getConstructor: (string) => () => any): any; + + /** + * Deserialize the JSON. + * @param {text} string The JSON string. + * @param {DeserializerOptions} settings Settings can specify a reviver, getTypeId function or getConstructor function. + * @returns {object} The deserialized object. + */ + export function deserialize(text: string, settings?: DeserializerOptions): T; +} + +/** + * Layers the widget sugar on top of the composition system. + * @requires system + * @requires composition + * @requires jquery + * @requires knockout + */ +declare module 'plugins/widget' { + interface WidgetSettings { + kind: string; + model?: any; + view?: any; + } + + /** + * Creates a ko binding handler for the specified kind. + * @param {string} kind The kind to create a custom binding handler for. + */ + export function registerKind(kind: string); + + /** + * Maps views and module to the kind identifier if a non-standard pattern is desired. + * @param {string} kind The kind name. + * @param {string} [viewId] The unconventional view id to map the kind to. + * @param {string} [moduleId] The unconventional module id to map the kind to. + */ + export function mapKind(kind: string, viewId?: string, moduleId?: string); + + /** + * Maps a kind name to it's module id. First it looks up a custom mapped kind, then falls back to `convertKindToModulePath`. + * @param {string} kind The kind name. + * @returns {string} The module id. + */ + export function mapKindToModuleId(kind: string): string; + + /** + * Converts a kind name to it's module path. Used to conventionally map kinds who aren't explicitly mapped through `mapKind`. + * @param {string} kind The kind name. + * @returns {string} The module path. + */ + export function convertKindToModulePath(kind: string): string; + + /** + * Maps a kind name to it's view id. First it looks up a custom mapped kind, then falls back to `convertKindToViewPath`. + * @param {string} kind The kind name. + * @returns {string} The view id. + */ + export function mapKindToViewId(kind: string): string; + + /** + * Converts a kind name to it's view id. Used to conventionally map kinds who aren't explicitly mapped through `mapKind`. + * @param {string} kind The kind name. + * @returns {string} The view id. + */ + export function convertKindToViewPath(kind: string): string; + + /** + * Creates a widget. + * @param {DOMElement} element The DOMElement or knockout virtual element that serves as the target element for the widget. + * @param {object} settings The widget settings. + * @param {object} [bindingContext] The current binding context. + */ + export function create(element: HTMLElement, settings: WidgetSettings, bindingContext?: KnockoutBindingContext); +} + +/** + * Connects the history module's url and history tracking support to Durandal's activation and composition engine allowing you to easily build navigation-style applications. + * @requires system + * @requires app + * @requires activator + * @requires events + * @requires composition + * @requires history + * @requires knockout + * @requires jquery + */ +declare module 'plugins/router' { + import activator = require('durandal/activator'); + import Events = require('durandal/events'); + import ts = require('durandal/typescript'); + + var RootRouter: ts.RootRouter; + + export = RootRouter; +} + +/** + * Interface definitions used by other modules which were not possible to define within those modules due to TypeScript limitations. + */ +declare module 'durandal/typescript' { + import activator = require('durandal/activator'); + import history = require('plugins/history'); + + /** + * Represents an event subscription. + * @class + */ + export interface EventSubscription { + /** + * Attaches a callback to the event subscription. + * @param {function} callback The callback function to invoke when the event is triggered. + * @param {object} [context] An object to use as `this` when invoking the `callback`. + * @chainable + */ + then(thenCallback: Function, context?: any): EventSubscription; + + /** + * Attaches a callback to the event subscription. + * @param {function} [callback] The callback function to invoke when the event is triggered. If `callback` is not provided, the previous callback will be re-activated. + * @param {object} [context] An object to use as `this` when invoking the `callback`. + * @chainable + */ + on(thenCallback: Function, context?: any): EventSubscription; + + /** + * Cancels the subscription. + * @chainable + */ + off(): EventSubscription; + } + + export interface RouteConfiguration { + title?: string; + moduleId?: string; + hash?: string; + routePattern?: RegExp; isActive?: KnockoutComputed; } - /** - * Parameters to the map function. e only required parameter is url the rest can be derived. The derivation - * happens by stripping parameters from the url and casing where appropriate. You can always explicitly provide - * url, name, moduleId, caption, settings, hash and visible. In 99% of situations, you should not need to provide - * hash; it's just there to simplify databinding for you. Most of the time you may want to teach the router how - * to properly derive the moduleId and name based on a url. If you want to do that, overwrite. - */ - interface IRouteInfoParameters { - /** your url pattern. The only required parameter */ - url: any; - /** if not supplied, router.convertRouteToName derives it */ + + export interface RouteInstruction { + fragment: string; + queryString: string; + config: RouteConfiguration; + params: any[]; + queryParams: Object; + } + + export interface RelativeRouteSettings { moduleId?: string; - /** if not supplied, router.convertRouteToModuleId derives it */ - name?: string; - /** used to set the document title */ - caption?: string; - /** determines whether or not to include it in the router's visibleRoutes array for easy navigation UI binding */ - visible?: boolean; - settings?: Object; + route?: string; + fromParent?: boolean; } - /** - * observable that is called when the router is ready - */ - export var ready: KnockoutObservable; - /** - * An observable array containing all route info objects. - */ - export var allRoutes: KnockoutObservableArray; - /** - * An observable array containing route info objects configured with visible:true (or by calling the mapNav function). - */ - export var visibleRoutes: KnockoutObservableArray; - /** - * An observable boolean which is true while navigation is in process; false otherwise. - */ - export var isNavigating: KnockoutObservable; - /** - * An observable whose value is the currently active item/module/page. - */ - export var activeItem: IDurandalViewModelActiveItem; - /** - * An observable whose value is the currently active route. - */ - export var activeRoute: KnockoutObservable; - /** - * called after an a new module is composed - */ - export var afterCompose: () => void; - /** - * Returns the activatable instance from the supplied module. - */ - export var getActivatableInstance: (routeInfo: IRouteInfo, params: any, module: any) => any; - /** - * Causes the router to move backwards in page history. - */ - export var navigateBack: () => void; - /** - * Use router default convention. - */ - export var useConvention: () => void; - /** - * Causes the router to navigate to a specific url. - */ - export var navigateTo: (url: string) => void; - /** - * replaces the windows.location w/ the url - */ - export var replaceLocation: (url: string) => void; - /** - * akes a route in and returns a calculated name. - */ - export var convertRouteToName: (route: string) => string; - /** - * Takes a route in and returns a calculated moduleId. Simple transformations of this can be done via the useConvention function above. For more advanced transformations, you can override this function. - */ - export var convertRouteToModuleId: (url: string) => string; - /** - * This can be overwritten to provide your own convention for automatically converting routes to module ids. - */ - export var autoConvertRouteToModuleId: (url: string) => string; - /** - * This should not normally be overwritten. But advanced users can override this to completely transform the developer's routeInfo input into the final version used to configure the router. - */ - export var prepareRouteInfo: (info: IRouteInfo) => void; - /** - * This should not normally be overwritten. But advanced users can override this to completely transform the developer's routeInfo input into the final version used to configure the router. - */ - export var handleInvalidRoute: (route: IRouteInfo, parameters: any) => void; - /** - * Once the router is required, you can call router.mapAuto(). This is the most basic configuration option. When you call this function (with no parameters) it tells the router to directly correlate route parameters to module names in the viewmodels folder. - */ - export var mapAuto: (path?: string) => void; - /** - * Works the same as mapRoute except that routes are automatically added to the visibleRoutes array. - */ - export var mapNav: (url: string, moduleId?: string, name?: string) => IRouteInfo; - /** - * You can pass a single routeInfo to this function, or you can pass the basic configuration parameters. url is your url pattern, moduleId is the module path this pattern will map to, name is used as the document title and visible determines whether or not to include it in the router's visibleRoutes array for easy navigation UI binding. - */ - export var mapRoute: { - (route: IRouteInfoParameters): IRouteInfo; - (url: string, moduleId?: string, name?: string, visible?: boolean): IRouteInfo; + + export interface Router { + /** + * The route handlers that are registered. Each handler consists of a `routePattern` and a `callback`. + */ + handlers: { routePattern: RegExp; callback: (fragment: string) => void; }[]; + + /** + * The route configs that are registered. + */ + routes: RouteConfiguration[]; + + /** + * The active item/screen based on the current navigation state. + */ + activeItem: activator.Activator; + + /** + * The route configurations that have been designated as displayable in a nav ui (nav:true). + */ + navigationModel: KnockoutObservableArray; + + /** + * Indicates that the router (or a child router) is currently in the process of navigating. + */ + isNavigating: KnockoutComputed; + + /** + * An observable surfacing the active routing instruction that is currently being processed or has recently finished processing. + * The instruction object has `config`, `fragment`, `queryString`, `params` and `queryParams` properties. + */ + activeInstruction: KnockoutObservable; + + /** + * Parses a query string into an object. + * @param {string} queryString The query string to parse. + * @returns {object} An object keyed according to the query string parameters. + */ + parseQueryString(queryString: string): Object; + + /** + * Add a route to be tested when the url fragment changes. + * @param {RegEx} routePattern The route pattern to test against. + * @param {function} callback The callback to execute when the route pattern is matched. + */ + route(routePattern: RegExp, callback: (fragment: string) => void ): void; + + /** + * Attempt to load the specified URL fragment. If a route succeeds with a match, returns `true`. If no defined routes matches the fragment, returns `false`. + * @param {string} fragment The URL fragment to find a match for. + * @returns {boolean} True if a match was found, false otherwise. + */ + loadUrl(fragment: string): boolean; + + /** + * Updates the document title based on the activated module instance, the routing instruction and the app.title. + * @param {object} instance The activated module. + * @param {object} instruction The routing instruction associated with the action. It has a `config` property that references the original route mapping config. + */ + updateDocumentTitle(instance: Object, instruction: RouteInstruction): void; + + /** + * 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. + */ + 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. + */ + navigate(fragment: string, options: history.NavigationOptions): boolean; + + /** + * Navigates back in the browser history. + */ + navigateBack(): void; + + /** + * Converts a route to a hash suitable for binding to a link's href. + * @param {string} route + * @returns {string} The hash. + */ + convertRouteToHash(route: string): string; + + /** + * Converts a route to a module id. This is only called if no module id is supplied as part of the route mapping. + * @param {string} route + * @returns {string} The module id. + */ + convertRouteToModuleId(route: string): string; + + /** + * Converts a route to a displayable title. This is only called if no title is specified as part of the route mapping. + * @method convertRouteToTitle + * @param {string} route + * @returns {string} The title. + */ + convertRouteToTitle(route: string): string; + + /** + * Maps route patterns to modules. + * @param {string} route A route. + * @chainable + */ + map(route: string): Router; + + /** + * Maps route patterns to modules. + * @param {string} route A route pattern. + * @param {string} moduleId The module id to map the route to. + * @chainable + */ + map(route: string, moduleId: string): Router; + + /** + * Maps route patterns to modules. + * @param {RegExp} route A route pattern. + * @param {string} moduleId The module id to map the route to. + * @chainable + */ + map(route: RegExp, moduleId: string): Router; + + /** + * Maps route patterns to modules. + * @param {string} route A route pattern. + * @param {RouteConfiguration} config The route's configuration. + * @chainable + */ + map(route: string, config: RouteConfiguration): Router; + + /** + * Maps route patterns to modules. + * @method map + * @param {RegExp} route A route pattern. + * @param {RouteConfiguration} config The route's configuration. + * @chainable + */ + map(route: RegExp, config: RouteConfiguration): Router; + + /** + * Maps route patterns to modules. + * @param {RouteConfiguration} config The route's configuration. + * @chainable + */ + map(config: RouteConfiguration): Router; + + /** + * Maps route patterns to modules. + * @param {RouteConfiguration[]} configs An array of route configurations. + * @chainable + */ + map(configs: RouteConfiguration[]): Router; + + /** + * Builds an observable array designed to bind a navigation UI to. The model will exist in the `navigationModel` property. + * @param {number} defaultOrder The default order to use for navigation visible routes that don't specify an order. The defualt is 100. + * @chainable + */ + buildNavigationModel(defaultOrder?: number): Router; + + /** + * Configures the router to map unknown routes to modules at the same path. + * @chainable + */ + mapUnknownRoutes(): Router; + + /** + * Configures the router use the specified module id for all unknown routes. + * @param {string} notFoundModuleId Represents the module id to route all unknown routes to. + * @param {string} [replaceRoute] Optionally provide a route to replace the url with. + * @chainable + */ + mapUnknownRoutes(notFoundModuleId: string, replaceRoute?: string): Router; + + /** + * Configures how the router will handle unknown routes. + * @param {function} callback Called back with the route instruction containing the route info. The function can then modify the instruction by adding a moduleId and the router will take over from there. + * @chainable + */ + mapUnknownRoutes(callback: (instruction: RouteInstruction) => void ): Router; + + /** + * Configures how the router will handle unknown routes. + * @param {RouteConfiguration} config The route configuration to use for unknown routes. + * @chainable + */ + mapUnknownRoutes(config: RouteConfiguration): Router; + + /** + * Resets the router by removing handlers, routes, event handlers and previously configured options. + * @chainable + */ + reset(): Router; + + /** + * Makes all configured routes and/or module ids relative to a certain base url. + * @param {string} settings The value is used as the base for routes and module ids. + * @chainable + */ + makeRelative(settings: string): Router; + + /** + * Makes all configured routes and/or module ids relative to a certain base url. + * @param {RelativeRouteSettings} settings If an object, you can specify `route` and `moduleId` separately. In place of specifying route, you can set `fromParent:true` to make routes automatically relative to the parent router's active route. + * @chainable + */ + makeRelative(settings: RelativeRouteSettings): Router; + + /** + * Creates a child router. + * @returns {Router} The child router. + */ + createChildRouter(): Router; + + /** + * Inspects routes and modules before activation. Can be used to protect access by cancelling navigation or redirecting. + * @param {object} instance The module instance that is about to be activated by the router. + * @param {object} instruction The route instruction. The instruction object has config, fragment, queryString, params and queryParams properties. + * @returns {Promise|Boolean|String} If a boolean, determines whether or not the route should activate or be cancelled. If a string, causes a redirect to the specified route. Can also be a promise for either of these value types. + */ + guardRoute?:(instance:Object, instruction:RouteInstruction) => any; } - /** - * This function takes an array of routeInfo objects or a single routeInfo object and uses it to configure the router. The finalized routeInfo (or array of infos) is returned. - */ - export var map: { - (routeOrRouteArray: IRouteInfoParameters): IRouteInfo; - (routeOrRouteArray: IRouteInfoParameters[]): IRouteInfo[]; + + export interface RootRouter extends Router { + /** + * Activates the router and the underlying history tracking mechanism. + * @returns {Promise} A promise that resolves when the router is ready. + */ + activate(options?: history.HistoryOptions): JQueryPromise; + + /** + * Disable history, perhaps temporarily. Not useful in a real app, but possibly useful for unit testing Routers. + */ + deactivate(): void; + + /** + * Installs the router's custom ko binding handler. + */ + install(): void; } - /** - * After you've configured the router, you need to activate it. This is usually done in your shell. The activate function of the router returns a promise that resolves when the router is ready to start. To use the router, you should add an activate function to your shell and return the result from that. The application startup infrastructure of Durandal will detect your shell's activate function and call it at the appropriate time, waiting for it's promise to resolve. This allows Durandal to properly orchestrate the timing of composition and databinding along with animations and splash screen display. - */ - export var activate: (defaultRoute: string) => JQueryPromise; - /** - * Before any route is activated, the guardRoute funtion is called. You can plug into this function to add custom logic to allow, deny or redirect based on the requested route. To allow, return true. To deny, return false. To redirect, return a string with the hash or url. You may also return a promise for any of these values. - */ - export var guardRoute: (routeInfo: IRouteInfo, params: any, instance: any) => any; -} - -declare module "durandal/widget" { - /** - * Use this function to create a widget through code. The element should reference a dom element that the widget will be created on. The settings can be either a string or an object. If it's a string, it should specify the widget kind. If it's an object, it represents settings that will be passed along to the widget. This object should have a kind property used to identify the widget kind to create. Optionally, you can specify a bindingContext of which you want the widget's binding context to be created as a child. - */ - export function create(element: any, settings: any, bindingContext?: any); - /** - * By default, you can create widgets in html by using the widget binding extension. Calling registerKind allows you to easily create a custom binding handler for your widget kind. Without calling registerKind you might declare a widget binding for an expander control with - */ - export function registerKind(kind: string); - /** - * Use this to re-map a widget kind identifier to a new viewId or moduleId representing the 'skin' and 'behavior' respectively. - */ - export function mapKind(kind: string, viewId?: string, moduleId?: string); - /** - * Developers implementing widgets may wish to use this function to acquire the resolved template parts for a widget. Pass a single dom element or an array of elements and get back an object keyed by part name whose values are the dom elements corresponding to each part in that scope. - */ - export function getParts(elements: any): any; - /** - * (overrridable) Replace this to re-interpret the kind id as a module path. By default it does a lookup for any custom maps added through mapKind and then falls back to the path "durandal/widgets/{kind}/controller". - */ - export function convertKindToModuleId(kind): string; - /** - * (overridable) Replace this to re-interpret the kind id as a view id. The default does a lookup for any custom maps added through mapKind and then falls back to the path "durandal/widgets/{kind}/view". - */ - export function convertKindToViewId(kind): string; -} - -interface IEventSubscription -{ - /** - * This function adding callback to event subscription - */ - then(thenCallback: any): void; - - /** - * This function removing current subscription from event handlers - */ - off(): void; - } +} \ No newline at end of file