diff --git a/README.md b/README.md index f18d6fee0..03f212210 100755 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ List of Definitions * [async](https://github.com/caolan/async) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm)) +* [BigScreen](http://brad.is/coding/BigScreen/) (by [Douglas Eichelberger](https://github.com/dduugg)) * [Bluebird](https://github.com/petkaantonov/bluebird) (by [Bart van der Schoor](https://github.com/Bartvds)) * [Bootbox](https://github.com/makeusabrew/bootbox) (by [Vincent Bortone](https://github.com/vbortone/)) * [Bootstrap](http://twitter.github.com/bootstrap/) (by [Boris Yankov](https://github.com/borisyankov)) @@ -186,8 +187,9 @@ List of Definitions * [Lodash](http://lodash.com/) (by [Brian Zengel](https://github.com/bczengel)) * [Logg](https://github.com/dpup/node-logg) (by [Bret Little](https://github.com/blittle)) * [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr)) -* [mCustomScrollbar](https://github.com/malihu/malihu-custom-scrollbar-plugin) (by [Sarah Williams] (https://github.com/flurg)) +* [mCustomScrollbar](https://github.com/malihu/malihu-custom-scrollbar-plugin) (by [Sarah Williams](https://github.com/flurg)) * [Meteor](https://www.meteor.com) (by [Dave Allen](https://github.com/fullflavedave)) +* [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk)) * [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov) and [Theodore Brown](https://github.com/theodorejb/)) * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield)) * [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee)) @@ -202,7 +204,7 @@ List of Definitions * [node-sqlserver](https://github.com/WindowsAzure/node-sqlserver) (by [Boris Yankov](https://github.com/borisyankov)) * [NProgress](https://github.com/rstacruz/nprogress) (by [Judah Gabriel Himango](https://github.com/judahgabriel)) * [Numeral.js](https://github.com/adamwdraper/Numeral-js) (by [Vincent Bortone](https://github.com/vbortone/)) -* [OpenLayers] (https://github.com/openlayers/openlayers) (by [Ilya Bolkhovsky](https://github.com/bolhovsky/)) +* [OpenLayers](https://github.com/openlayers/openlayers) (by [Ilya Bolkhovsky](https://github.com/bolhovsky/)) * [Parallel.js](https://github.com/adambom/parallel.js) (by [Josh Baldwin](https://github.com/jbaldwin)) * [PDF.js](https://github.com/mozilla/pdf.js) (by [Josh Baldwin](https://github.com/jbaldwin)) * [Persona](http://www.mozilla.org/en-US/persona) (by [James Frasca](https://github.com/Nycto)) diff --git a/bigscreen/bigscreen-tests.ts b/bigscreen/bigscreen-tests.ts new file mode 100644 index 000000000..0ae13acd7 --- /dev/null +++ b/bigscreen/bigscreen-tests.ts @@ -0,0 +1,23 @@ +/// + +BigScreen.onchange = function(element: Element) { + console.log("Full-screen element " + element + " changed."); +} + +BigScreen.onenter = function(element: Element) { + console.log(BigScreen.element + " entered full-screen."); +}; + +BigScreen.onexit = function() { + console.log("Exited full-screen."); +} + +BigScreen.onerror = function(element: Element, reason: string) { + console.log("Error sending " + element + " into full-screen: " + reason); +} + +console.log("full-screen-enabled? " + BigScreen.enabled); + +BigScreen.request(document.documentElement); +BigScreen.exit(); +BigScreen.toggle(document.documentElement); diff --git a/bigscreen/bigscreen.d.ts b/bigscreen/bigscreen.d.ts new file mode 100644 index 000000000..bdabdc101 --- /dev/null +++ b/bigscreen/bigscreen.d.ts @@ -0,0 +1,20 @@ +// Type definitions for BigScreen 2.0.4 +// Project: http://brad.is/coding/BigScreen/ +// Definitions by: Douglas Eichelberger +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface BigScreenStatic { + element: any; + enabled: boolean; + + exit(): void; + onchange(element: Element): void; + onenter(element: Element): void; + onerror(element: Element, reason: string): void; + onexit(): void; + request(element: Element, onEnter?: (element: Element) => void, onExit?: () => void, onError?: (element: Element, reason: string) => void): void; + toggle(element: Element, onEnter?: (element: Element) => void, onExit?: () => void, onError?: (element: Element, reason: string) => void): void; + videoEnabled(video: HTMLVideoElement): boolean; +} + +declare var BigScreen: BigScreenStatic; diff --git a/bluebird/bluebird-tests.ts b/bluebird/bluebird-tests.ts index 92e5e7b6b..14528b9b5 100644 --- a/bluebird/bluebird-tests.ts +++ b/bluebird/bluebird-tests.ts @@ -1,5 +1,7 @@ /// +// Note: try to maintain the ordering and separators + var obj:Object; var bool:boolean; var num:number; @@ -15,32 +17,25 @@ var numArr:string[]; var value:any = null; var reason:any = null; -var Promise:Bluebird.PromiseStatic; +var promise:Promise; +var p:Promise; -var promise:Bluebird.Promise; -var p:Bluebird.Promise; - -var resolver:Bluebird.PromiseResolver; -var inspection:Bluebird.PromiseInspection; -var arrLike:Bluebird.ArrayLike; +var resolver:Promise.Resolver; +var inspection:Promise.Inspection; // - - - - - - - - - - - - - - - - - - - - - - - - var promise = new Promise((resolve:(value:any) => void, reject:(reason:any) => void) => { - if(true) { - resolve(123); - } - else { - reject(new Error('nope')); - } + if(true) { + resolve(123); + } + else { + reject(new Error('nope')); + } }); // - - - - - - - - - - - - - - - - - - - - - - - - -num = arrLike.length; - -// - - - - - - - - - - - - - - - - - - - - - - - - - resolver.resolve(x); resolver.reject(x); @@ -89,12 +84,12 @@ p = promise.caught((reason:any) => { }); p = promise.catch((reason:any) => { - return true; + return true; }, (reason:any) => { }); p = promise.caught((reason:any) => { - return true; + return true; }, (reason:any) => { }); @@ -219,43 +214,40 @@ p = promise.spread((value:any) => { }); p = promise.map((item:any, index:number, arrayLength:number) => { - return x; + return x; }); p = promise.reduce((total:number, memo:any, index:number, arrayLength:number) => { - return memo; + return memo; }); p = promise.reduce((total:number, memo:any, index:number, arrayLength:number) => { - return memo; + return memo; }, x); p = promise.filter((item:any, index?:number, arrayLength?:number) => { - return true; + return true; }); // - - - - - - - - - - - - - - - - - - - - - - - - p = new Promise((resolve:(value:any) => any, reject:(reason:any) => any) => { - if(true) { - resolve(value); - } - else { - reject(new Error('xyz')); - } + if(true) { + resolve(value); + } + else { + reject(new Error('xyz')); + } }); -p = Promise.try(() => {}); -p = Promise.try(() => {}, arr); -p = Promise.try(() => {}, arr, x); -p = Promise.try(() => {}, arrLike); -p = Promise.try(() => {}, arrLike, x); - +/* + p = Promise.try(() => {}); + p = Promise.try(() => {}, arr); + p = Promise.try(() => {}, arr, x); + */ p = Promise.attempt(() => {}); p = Promise.attempt(() => {}, arr); p = Promise.attempt(() => {}, arr, x); -p = Promise.attempt(() => {}, arrLike); -p = Promise.attempt(() => {}, arrLike, x); f = Promise.method(function() { @@ -312,16 +304,16 @@ p = Promise.some(arr, x); p = Promise.join(1, 2, 3); p = Promise.map(arr, (item:any, index:number, arrayLength:number) => { - return x; + return x; }); p = Promise.reduce(arr, (total:number, memo:any, index:number, arrayLength:number) => { - return memo; + return memo; }); p = Promise.reduce(arr, (total:number, memo:any, index:number, arrayLength:number) => { - return memo; + return memo; }, x); p = Promise.filter(arr, (item:any, index?:number, arrayLength?:number) => { - return true; + return true; }); diff --git a/bluebird/bluebird.d.ts b/bluebird/bluebird.d.ts index 470699143..5db21d63e 100644 --- a/bluebird/bluebird.d.ts +++ b/bluebird/bluebird.d.ts @@ -3,506 +3,499 @@ // Definitions by: Bart van der Schoor // Definitions: https://github.com/borisyankov/DefinitelyTyped -// note: these are preliminary typings using `any`: the generic versions are under construction, see: - -// https://github.com/borisyankov/DefinitelyTyped/issues/1563 - -// https://github.com/borisyankov/DefinitelyTyped/tree/def/bluebird - - -declare module Bluebird { - - interface ArrayLike { - length:number; - } - - interface Promise { - /** - * Promises/A+ `.then()` with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. - */ - then(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; - - /** - * This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler. - * - * Alias `.caught();` for compatibility with earlier ECMAScript version. - */ - catch(handler:(reason:any) => any):Promise; - caught(handler:(reason:any) => any):Promise; - - /** - * This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called. - * - * This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called. - * - * Alias `.caught();` for compatibility with earlier ECMAScript version. - */ - //TODO expand this complex overload (weird) - catch(predicate:(reason:any) => boolean, handler:(reason:any) => any):Promise; - caught(predicate:(reason:any) => boolean, handler:(reason:any) => any):Promise; - - catch(ErrorClass:Function, handler:(reason:any) => any):Promise; - caught(ErrorClass:Function, handler:(reason:any) => any):Promise; - - /** - * Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. - */ - error(rejectedHandler:(reason:any) => any):Promise; - - /** - * Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for `.finally()` in that the final value cannot be modified from the handler. - * - * Alias `.lastly();` for compatibility with earlier ECMAScript version. - */ - finally(handler:(value:any) => any):Promise; - lastly(handler:(value:any) => any):Promise; - - /** - * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. - */ - bind(thisArg:any):Promise; - - /** - * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. - */ - done(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; - - /** - * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. - */ - progressed(handler:(note:any) => any):Promise; - - /** - * Same as calling `Promise.delay(this, ms)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - delay(ms:number):Promise; - - /** - * Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within `ms` milliseconds, the returned promise is rejected with a `Promise.TimeoutError` instance. - * - * You may specify a custom error message with the `message` parameter. - */ - - timeout(ms:number, message?:string):Promise; - - /** - * Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be `null` in case of success. - * Returns back this promise instead of creating a new one. If the `callback` argument is not a function, this method does not do anything. - */ - nodeify(callback?:Function):Promise; - - /** - * Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for `.cancel()` to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise. - */ - cancellable():Promise; - - /** - * Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending. - * - * That ancestor will then be rejected with a `CancellationError` (get a reference from `Promise.CancellationError`) object as the rejection reason. - * - * In a promise rejection handler you may check for a cancellation by seeing if the reason object has `.name === "Cancel"`. - * - * Promises are by default not cancellable. Use `.cancellable()` to mark a promise as cancellable. - */ - cancel():Promise; - - /** - * Like `.then()`, but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors. - */ - fork(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; - - /** - * Create an uncancellable promise based on this promise. - */ - uncancellable():Promise; - - /** - * See if this promise can be cancelled. - */ - isCancellable():boolean; - - /** - * See if this `promise` has been fulfilled. - */ - isFulfilled():boolean; - - /** - * See if this `promise` has been rejected. - */ - isRejected():boolean; - - /** - * See if this `promise` is still defer. - */ - isPending():boolean; - - /** - * See if this `promise` is resolved -> either fulfilled or rejected. - */ - isResolved():boolean; - - /** - * Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. - */ - inspect():PromiseInspection; - - /** - * This is a convenience method for doing: - * - * - * promise.then(function(obj){ - * return obj[propertyName].call(obj, arg...); - * }); - * - */ - call(propertyName:string, ...args:any[]):Promise; - - /** - * This is a convenience method for doing: - * - * - * promise.then(function(obj){ - * return obj[propertyName]; - * }); - * - */ - get(propertyName:string):Promise; - - /** - * Convenience method for: - * - * - * .then(function() { - * return value; - * }); - * - * - * in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()` - * - * Alias `.thenReturn();` for compatibility with earlier ECMAScript version. - */ - return(value:any):Promise; - thenReturn():Promise; - - /** - * Convenience method for: - * - * - * .then(function() { - * throw reason; - * }); - * - * Same limitations apply as with `.return()`. - * - * Alias `.thenThrow();` for compatibility with earlier ECMAScript version. - */ - throw(reason:any):Promise; - thenThrow():Promise; - - /** - * Convert to String. - */ - toString():string; - - /** - * This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`. - */ - toJSON():Object; - - /** - * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - all():Promise; - - /** - * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - props():Promise; - - /** - * Same as calling `Promise.settle(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - settle():Promise; - - /** - * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - any():Promise; - - /** - * Same as calling `Promise.race(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - some(count:number):Promise; - - /** - * Same as calling `Promise.some(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - race():Promise; - - /** - * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. - */ - spread(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any):Promise; - - /** - * Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - map(mapper:(item:any, index:number, arrayLength:number) => any):Promise; - - /** - * Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - reduce(reducer:(total:number, current:any, index:number, arrayLength:number) => any, initialValue?:any):Promise; - - /** - * Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. - */ - filter(filterer:(item:any, index:number, arrayLength:number) => any):Promise; - } - - interface PromiseResolver { - /** - * Resolve the underlying promise with `value` as the resolution value. If `value` is a thenable or a promise, the underlying promise will assume its state. - */ - resolve(value:any):void; - - /** - * Reject the underlying promise with `reason` as the rejection reason. - */ - reject(reason:any):void; - - /** - * Progress the underlying promise with `value` as the progression value. - */ - progress(value:any):void; - - /** - * Gives you a callback representation of the `PromiseResolver`. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions. - * - * If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values. - */ - callback:Function; - } - - interface PromiseInspection { - /** - * See if the underlying promise was fulfilled at the creation time of this inspection object. - */ - isFulfilled():boolean; - - /** - * See if the underlying promise was rejected at the creation time of this inspection object. - */ - isRejected():boolean; - - /** - * See if the underlying promise was defer at the creation time of this inspection object. - */ - isPending():boolean; - - /** - * Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object. - * - * throws `TypeError` - */ - value():any; - - /** - * Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object. - * - * throws `TypeError` - */ - error():any; - } - - interface PromiseStatic { - /** - * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. - */ - new(resolver:(resolve:(value:any) => void, reject:(reason:any) => any) => void):Promise; - - /** - * Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise. - * - * Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call. - * - * Alias for `attempt();` for compatibility with earlier ECMAScript version. - */ - try(fn:() => any, args?:any[], ctx?:any):Promise; - try(fn:() => any, args?:ArrayLike, ctx?:any):Promise; - attempt(fn:() => any, args?:any[], ctx?:any):Promise; - attempt(fn:() => any, args?:ArrayLike, ctx?:any):Promise; - - /** - * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. - * This method is convenient when a function can sometimes return synchronously or throw synchronously. - */ - method(fn:Function):Function; - - /** - * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. - */ - resolve(value:any):Promise; - - /** - * Create a promise that is rejected with the given `reason`. - */ - reject(reason:any):Promise; - - /** - * Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?:Promise(#promise-resolution). - */ - defer():PromiseResolver; - - /** - * Cast the given `value` to a trusted promise. If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is:Promise returned with `value` as its fulfillment value. If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that:Promise assimilates the state of the thenable. - */ - cast(value:any):Promise; - - /** - * Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`. - */ - bind(thisArg:any):Promise; - - /** - * See if `value` is a trusted Promise. - */ - is(value:any):boolean; - - /** - * Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency. - */ - longStackTraces():void; - - /** - * Returns a promise that will be fulfilled with `value` (or `undefined`) after given `ms` milliseconds. If `value` is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the `value` promise. - */ - delay(value:Promise, ms:number):Promise; - delay(value:any, ms:number):Promise; - delay(ms:number):Promise; - - /** - * Returns a function that will wrap the given `nodeFunction`. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. - * - * If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them. - * - * If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`. - */ - promisify(nodeFunction:Function, receiver?:any):Function; - - /** - * This overload has been **deprecated**. The overload will continue working for now. The recommended method for promisifying multiple methods at once is ``Promise.promisifyAll(Object target)`` - */ - promisify(target:Object):Object; - - /** - * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. - * - * Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method. - */ - promisifyAll(target:Object):Object; - - /** - * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. - */ - coroutine(generatorFunction:Function):Function; - - /** - * Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. - */ - spawn(generatorFunction:Function):Promise; - - /** - * This is relevant to browser environments with no module loader. - * - * Release control of the `Promise` namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else. - */ - noConflict():Object; - - /** - * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. - * - * Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections. - */ - onPossiblyUnhandledRejection(handler:(reason:any) => any):void; - - /** - * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason. - */ - all(values:any[]):Promise; - - /** - * Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason. - * - * If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties. - * - * *The original object is not modified.* - */ - props(object:Promise):Promise; - props(object:Object):Promise; - - /** - * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of ``PromiseInspection`` instances at respective positions in relation to the input array. - * - * *original:The array is not modified. The input array sparsity is retained in the resulting array.* - */ - settle(values:any[]):Promise; - - /** - * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. - */ - any(values:any[]):Promise; - - /** - * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. - * - * **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending. - */ - race(values:any[]):Promise; - - /** - * Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution. - * - * If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in. - * - * *The original array is not modified.* - */ - some(values:any[], count:number):Promise; - - /** - * Like `Promise.all()` but instead of having to pass an array, the array is generated from the passed variadic arguments. - */ - join(...values:any[]):Promise; - - /** - * Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. - * - * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. - * - * *The original array is not modified.* - */ - map(values:any[], mapper:(item:any, index:number, arrayLength:number) => any):Promise; - - /** - * Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. - * - * If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. - * - * *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.* - */ - reduce(values:any[], reducer:(total:number, current:any, index:number, arrayLength:number) => any, initialValue?:any):Promise; - - /** - * Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. - * - * The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result. - * - * *The original array is not modified. - */ - filter(values:any[], filterer:(item:any, index?:number, arrayLength?:number) => any):Promise; - } +// Note: these are preliminary non-generic typings using `any`: the generic versions are ready but need (tsc >= v1.0.0) due to issues in the compiler +// - https://github.com/borisyankov/DefinitelyTyped/issues/1563 +// - https://github.com/borisyankov/DefinitelyTyped/tree/def/bluebird/bluebird + +declare class Promise { + /** + * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. + */ + constructor(resolver: (resolve: (value: any) => void, reject: (reason: any) => any) => void); + /** + * Promises/A+ `.then()` with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. + */ + then(fulfilledHandler?: (value: any) => any, rejectedHandler?: (reason: any) => any, progressHandler?: (note: any) => any):Promise; + + /** + * This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + catch(handler: (reason: any) => any):Promise; + caught(handler: (reason: any) => any):Promise; + + /** + * This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called. + * + * This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + //TODO expand this complex overload (weird) + catch(predicate: (reason: any) => boolean, handler: (reason: any) => any): Promise; + caught(predicate: (reason: any) => boolean, handler: (reason: any) => any): Promise; + + catch(ErrorClass: Function, handler: (reason: any) => any): Promise; + caught(ErrorClass: Function, handler: (reason: any) => any): Promise; + + /** + * Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. + */ + error(rejectedHandler: (reason: any) => any): Promise; + + /** + * Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for `.finally()` in that the final value cannot be modified from the handler. + * + * Alias `.lastly();` for compatibility with earlier ECMAScript version. + */ + finally(handler: (value: any) => any): Promise; + lastly(handler: (value: any) => any): Promise; + + /** + * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. + */ + bind(thisArg: any): Promise; + + /** + * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. + */ + done(fulfilledHandler?: (value: any) => any, rejectedHandler?: (reason: any) => any, progressHandler?: (note: any) => any): Promise; + + /** + * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. + */ + progressed(handler: (note: any) => any): Promise; + + /** + * Same as calling `Promise.delay(this, ms)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + delay(ms: number): Promise; + + /** + * Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within `ms` milliseconds, the returned promise is rejected with a `Promise.TimeoutError` instance. + * + * You may specify a custom error message with the `message` parameter. + */ + + timeout(ms: number, message?: string): Promise; + + /** + * Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be `null` in case of success. + * Returns back this promise instead of creating a new one. If the `callback` argument is not a function, this method does not do anything. + */ + nodeify(callback?: Function): Promise; + + /** + * Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for `.cancel()` to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise. + */ + cancellable(): Promise; + + /** + * Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending. + * + * That ancestor will then be rejected with a `CancellationError` (get a reference from `Promise.CancellationError`) object as the rejection reason. + * + * In a promise rejection handler you may check for a cancellation by seeing if the reason object has `.name === "Cancel"`. + * + * Promises are by default not cancellable. Use `.cancellable()` to mark a promise as cancellable. + */ + cancel(): Promise; + + /** + * Like `.then()`, but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors. + */ + fork(fulfilledHandler?: (value: any) => any, rejectedHandler?: (reason: any) => any, progressHandler?: (note: any) => any): Promise; + + /** + * Create an uncancellable promise based on this promise. + */ + uncancellable(): Promise; + + /** + * See if this promise can be cancelled. + */ + isCancellable(): boolean; + + /** + * See if this `promise` has been fulfilled. + */ + isFulfilled(): boolean; + + /** + * See if this `promise` has been rejected. + */ + isRejected(): boolean; + + /** + * See if this `promise` is still defer. + */ + isPending(): boolean; + + /** + * See if this `promise` is resolved -> either fulfilled or rejected. + */ + isResolved(): boolean; + + /** + * Synchronously inspect the state of this `promise`. The `Promise.Inspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. + */ + inspect(): Promise.Inspection; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName].call(obj, arg...); + * }); + * + */ + call(propertyName: string, ...args: any[]): Promise; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName]; + * }); + * + */ + get(propertyName: string): Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * return value; + * }); + * + * + * in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()` + * + * Alias `.thenReturn();` for compatibility with earlier ECMAScript version. + */ + return(value: any): Promise; + thenReturn(): Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * throw reason; + * }); + * + * Same limitations apply as with `.return()`. + * + * Alias `.thenThrow();` for compatibility with earlier ECMAScript version. + */ + throw(reason: any): Promise; + thenThrow(): Promise; + + /** + * Convert to String. + */ + toString(): string; + + /** + * This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`. + */ + toJSON(): Object; + + /** + * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + all(): Promise; + + /** + * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + props(): Promise; + + /** + * Same as calling `Promise.settle(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + settle(): Promise; + + /** + * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + any(): Promise; + + /** + * Same as calling `Promise.race(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + some(count: number): Promise; + + /** + * Same as calling `Promise.some(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + race(): Promise; + + /** + * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. + */ + spread(fulfilledHandler?: (value: any) => any, rejectedHandler?: (reason: any) => any): Promise; + + /** + * Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + map(mapper: (item: any, index: number, arrayLength: number) => any): Promise; + + /** + * Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + reduce(reducer: (total: number, current: any, index: number, arrayLength: number) => any, initialValue?: any): Promise; + + /** + * Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + filter(filterer: (item: any, index: number, arrayLength: number) => any): Promise; } + +declare module Promise { + + interface Resolver { + /** + * Resolve the underlying promise with `value` as the resolution value. If `value` is a thenable or a promise, the underlying promise will assume its state. + */ + resolve(value: any): void; + + /** + * Reject the underlying promise with `reason` as the rejection reason. + */ + reject(reason: any): void; + + /** + * Progress the underlying promise with `value` as the progression value. + */ + progress(value: any): void; + + /** + * Gives you a callback representation of the `Promise.Resolver`. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions. + * + * If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values. + */ + callback:Function; + } + + interface Inspection { + /** + * See if the underlying promise was fulfilled at the creation time of this inspection object. + */ + isFulfilled(): boolean; + + /** + * See if the underlying promise was rejected at the creation time of this inspection object. + */ + isRejected(): boolean; + + /** + * See if the underlying promise was defer at the creation time of this inspection object. + */ + isPending(): boolean; + + /** + * Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object. + * + * throws `TypeError` + */ + value(): any; + + /** + * Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object. + * + * throws `TypeError` + */ + error(): any; + } + + /** + * Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise. + * + * Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call. + * + * Alias for `attempt();` for compatibility with earlier ECMAScript version. + */ + // function try(fn: () => any, args?: any[], ctx?: any): Promise; + + function attempt(fn: () => any, args?: any[], ctx?: any): Promise; + + /** + * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. + * This method is convenient when a function can sometimes return synchronously or throw synchronously. + */ + function method(fn: Function): Function; + + /** + * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. + */ + function resolve(value: any): Promise; + + /** + * Create a promise that is rejected with the given `reason`. + */ + function reject(reason: any): Promise; + + /** + * Create a promise with undecided fate and return a `Promise.Resolver` to control it. See resolution?:Promise(#promise-resolution). + */ + function defer(): Promise.Resolver; + + /** + * Cast the given `value` to a trusted promise. If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is:Promise returned with `value` as its fulfillment value. If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that:Promise assimilates the state of the thenable. + */ + function cast(value: any): Promise; + + /** + * Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`. + */ + function bind(thisArg: any): Promise; + + /** + * See if `value` is a trusted Promise. + */ + function is(value: any): boolean; + + /** + * Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency. + */ + function longStackTraces(): void; + + /** + * Returns a promise that will be fulfilled with `value` (or `undefined`) after given `ms` milliseconds. If `value` is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the `value` promise. + */ + function delay(value: Promise, ms: number): Promise; + + function delay(value: any, ms: number): Promise; + + function delay(ms: number): Promise; + + /** + * Returns a function that will wrap the given `nodeFunction`. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. + * + * If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them. + * + * If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`. + */ + function promisify(nodeFunction: Function, receiver?: any): Function; + + /** + * This overload has been **deprecated**. The overload will continue working for now. The recommended method for promisifying multiple methods at once is ``Promise.promisifyAll(Object target)`` + */ + function promisify(target: Object): Object; + + /** + * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. + * + * Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method. + */ + function promisifyAll(target: Object): Object; + + /** + * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + function coroutine(generatorFunction: Function): Function; + + /** + * Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + function spawn(generatorFunction: Function): Promise; + + /** + * This is relevant to browser environments with no module loader. + * + * Release control of the `Promise` namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else. + */ + function noConflict(): Object; + + /** + * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. + * + * Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections. + */ + function onPossiblyUnhandledRejection(handler: (reason: any) => any): void; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason. + */ + function all(values: any[]): Promise; + + /** + * Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason. + * + * If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties. + * + * *The original object is not modified.* + */ + function props(object: Promise): Promise; + + function props(object: Object): Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of ``Promise.Inspection`` instances at respective positions in relation to the input array. + * + * *original:The array is not modified. The input array sparsity is retained in the resulting array.* + */ + function settle(values: any[]): Promise; + + /** + * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. + */ + function any(values: any[]): Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. + * + * **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending. + */ + function race(values: any[]): Promise; + + /** + * Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution. + * + * If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in. + * + * *The original array is not modified.* + */ + function some(values: any[], count: number): Promise; + + /** + * Like `Promise.all()` but instead of having to pass an array, the array is generated from the passed variadic arguments. + */ + function join(...values: any[]): Promise; + + /** + * Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. + * + * *The original array is not modified.* + */ + function map(values: any[], mapper: (item: any, index: number, arrayLength: number) => any): Promise; + + /** + * Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. + * + * *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.* + */ + function reduce(values: any[], reducer: (total: number, current: any, index: number, arrayLength: number) => any, initialValue?: any): Promise; + + /** + * Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result. + * + * *The original array is not modified. + */ + function filter(values: any[], filterer: (item: any, index?: number, arrayLength?: number) => any): Promise; +} + declare module 'bluebird' { - export = Bluebird; +export = Promise; } diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index cfd4ae56f..06f19801d 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1877,15 +1877,10 @@ function test_has() { } function test_hasClass() { - $("div#result1").append($("p:first").hasClass("selected")); - $("div#result2").append($("p:last").hasClass("selected")); - $("div#result3").append($("p").hasClass("selected")); - $('#mydiv').hasClass('foo'); - // typescript has a bug to (boolean).toString() - I'll comment this code until typescript team solve this problem. - //$("div#result1").append($("p:first").hasClass("selected").toString()); - //$("div#result2").append($("p:last").hasClass("selected").toString()); - //$("div#result3").append($("p").hasClass("selected").toString()); + $("div#result1").append($("p:first").hasClass("selected").toString()); + $("div#result2").append($("p:last").hasClass("selected").toString()); + $("div#result3").append($("p").hasClass("selected").toString()); } function test_hasData() { @@ -2171,11 +2166,17 @@ function test_index() { function test_innerHeight() { var p = $("p:first"); $("p:last").text("innerHeight:" + p.innerHeight()); + + p.innerHeight(123); + p.innerHeight('123px'); } function test_innerWidth() { var p = $("p:first"); $("p:last").text("innerWidth:" + p.innerWidth()); + + p.innerWidth(123); + p.innerWidth('123px'); } function test_outerHeight() { @@ -2183,6 +2184,9 @@ function test_outerHeight() { $("p:last").text( "outerHeight:" + p.outerHeight() + " , outerHeight( true ):" + p.outerHeight(true)); + + p.outerHeight(123); + p.outerHeight('123px'); } function test_outerWidth() { @@ -2190,6 +2194,9 @@ function test_outerWidth() { $("p:last").text( "outerWidth:" + p.outerWidth() + " , outerWidth( true ):" + p.outerWidth(true)); + + p.outerWidth(123); + p.outerWidth('123px'); } function test_scrollLeft() { diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 329e0a177..958128e2c 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -1418,11 +1418,39 @@ interface JQuery { */ innerHeight(): number; + /** + * Sets the inner height on elements in the set of matched elements, including padding but not border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + innerHeight(height: number): JQuery; + + /** + * Sets the inner height on elements in the set of matched elements, including padding but not border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + innerHeight(height: string): JQuery; + /** * Get the current computed width for the first element in the set of matched elements, including padding but not border. */ innerWidth(): number; + /** + * Sets the inner width on elements in the set of matched elements, including padding but not border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + innerWidth(width: number): JQuery; + + /** + * Sets the inner width on elements in the set of matched elements, including padding but not border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + innerWidth(width: string): JQuery; + /** * Get the current coordinates of the first element in the set of matched elements, relative to the document. */ @@ -1447,6 +1475,20 @@ interface JQuery { */ outerHeight(includeMargin?: boolean): number; + /** + * Sets the outer height on elements in the set of matched elements, including padding and border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + outerHeight(height: number): JQuery; + + /** + * Sets the outer height on elements in the set of matched elements, including padding and border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + outerHeight(height: string): JQuery; + /** * Get the current computed width for the first element in the set of matched elements, including padding and border. * @@ -1454,6 +1496,20 @@ interface JQuery { */ outerWidth(includeMargin?: boolean): number; + /** + * Sets the outer width on elements in the set of matched elements, including padding and border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + outerWidth(width: number): JQuery; + + /** + * Sets the outer width on elements in the set of matched elements, including padding and border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + outerWidth(width: string): JQuery; + /** * Get the current coordinates of the first element in the set of matched elements, relative to the offset parent. */ @@ -2660,27 +2716,164 @@ interface JQuery { */ undelegate(namespace: string): JQuery; + /** + * Bind an event handler to the "unload" JavaScript event. (DEPRECATED from v1.8) + * + * @param handler A function to execute when the event is triggered. + */ unload(handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Bind an event handler to the "unload" JavaScript event. (DEPRECATED from v1.8) + * + * @param eventData A plain object of data that will be passed to the event handler. + * @param handler A function to execute when the event is triggered. + */ unload(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; - // Internals + /** + * The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document. (DEPRECATED from v1.10) + */ context: Element; + jquery: string; + /** + * Bind an event handler to the "error" JavaScript event. (DEPRECATED from v1.8) + * + * @param handler A function to execute when the event is triggered. + */ error(handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Bind an event handler to the "error" JavaScript event. (DEPRECATED from v1.8) + * + * @param eventData A plain object of data that will be passed to the event handler. + * @param handler A function to execute when the event is triggered. + */ error(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Add a collection of DOM elements onto the jQuery stack. + * + * @param elements An array of elements to push onto the stack and make into a new jQuery object. + */ pushStack(elements: any[]): JQuery; - pushStack(elements: any[], name: any, arguments: any): JQuery; + /** + * Add a collection of DOM elements onto the jQuery stack. + * + * @param elements An array of elements to push onto the stack and make into a new jQuery object. + * @param name The name of a jQuery method that generated the array of elements. + * @param arguments The arguments that were passed in to the jQuery method (for serialization). + */ + pushStack(elements: any[], name: string, arguments: any[]): JQuery; - // Manipulation - after(...content: any[]): JQuery; - after(func: (index: any) => any): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param content1 HTML string, DOM element, array of elements, or jQuery object to insert after each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + */ + after(content1: JQuery, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param content1 HTML string, DOM element, array of elements, or jQuery object to insert after each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + */ + after(content1: any[], ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param content1 HTML string, DOM element, array of elements, or jQuery object to insert after each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + */ + after(content1: Element, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param content1 HTML string, DOM element, array of elements, or jQuery object to insert after each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + */ + after(content1: Text, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param content1 HTML string, DOM element, array of elements, or jQuery object to insert after each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + */ + after(content1: string, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. + */ + after(func: (index: number) => any): JQuery; - append(...content: any[]): JQuery; - append(func: (index: any, html: any) => any): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param content1 DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + */ + append(content1: JQuery, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param content1 DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + */ + append(content1: any[], ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param content1 DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + */ + append(content1: Element, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param content1 DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + */ + append(content1: Text, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param content1 DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + */ + append(content1: string, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert at the end of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set. + */ + append(func: (index: number, html: string) => any): JQuery; - appendTo(target: any): JQuery; + /** + * Insert every element in the set of matched elements to the end of the target. + * + * @param target A selector, element, HTML string, array of elements, or jQuery object; the matched set of elements will be inserted at the end of the element(s) specified by this parameter. + */ + appendTo(target: JQuery): JQuery; + /** + * Insert every element in the set of matched elements to the end of the target. + * + * @param target A selector, element, HTML string, array of elements, or jQuery object; the matched set of elements will be inserted at the end of the element(s) specified by this parameter. + */ + appendTo(target: any[]): JQuery; + /** + * Insert every element in the set of matched elements to the end of the target. + * + * @param target A selector, element, HTML string, array of elements, or jQuery object; the matched set of elements will be inserted at the end of the element(s) specified by this parameter. + */ + appendTo(target: Element): JQuery; + /** + * Insert every element in the set of matched elements to the end of the target. + * + * @param target A selector, element, HTML string, array of elements, or jQuery object; the matched set of elements will be inserted at the end of the element(s) specified by this parameter. + */ + appendTo(target: string): JQuery; before(...content: any[]): JQuery; before(func: (index: any) => any): JQuery; diff --git a/lazy.js/lazy.js.d.ts b/lazy.js/lazy.js.d.ts index baba46a46..47925bdf9 100644 --- a/lazy.js/lazy.js.d.ts +++ b/lazy.js/lazy.js.d.ts @@ -242,3 +242,7 @@ declare module LazyJS { declare var Lazy:LazyJS.LazyStatic; +declare module 'lazy.js' { +export = Lazy; +} + diff --git a/microsoft-live-connect/microsoft-live-connect.d.ts b/microsoft-live-connect/microsoft-live-connect.d.ts new file mode 100644 index 000000000..04ff3ef79 --- /dev/null +++ b/microsoft-live-connect/microsoft-live-connect.d.ts @@ -0,0 +1,2337 @@ +/// +// Type definitions for Microsoft Live Connect v5.0. +// Project: http://msdn.microsoft.com/en-us/library/live/hh243643.aspx +// Definitions by: John Vilk +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Microsoft.Live { + //#region REST Object Information + + /** + * Sub object of REST objects that contains information about a user. + */ + interface IUserInfo { + /** + * The name of the user. + */ + name: string; + /** + * The Live ID of the user. + */ + id: string; + } + + /** + * Sub object of REST objects that contains information about who the + * item is shared with. + */ + interface ISharedWith { + /** + * A localized string that contains info about who can access the + * item. The options are: + * - People I selected + * - Just me + * - Everyone (public) + * - Friends + * - My friends and their friends + * - People with a link + * The default is Just me. + */ + access: string; + } + + /** + * Convenience interface for when you have a bunch of objects of different + * types in a single collection. You discriminate between them using their + * 'type' field. + */ + interface IObject { + /** + * The object's type. + */ + type: string; + } + + /** + * Contains a collection of one type of object. + */ + interface IObjectCollection { + /** + * An array container for objects when a collection of objects is + * returned. + */ + data: T[]; + } + + /** + * The Album object contains info about a user's albums in Microsoft + * SkyDrive. Albums are stored at the root level of a user's SkyDrive + * directory, and can contain combinations of photos, videos, audio, files, + * and folders. The Live Connect REST API supports reading Album objects. + * Use the wl.photos scope to read a user's Album objects. Use the + * wl.skydrive scope to read a user's files. Use the wl.contacts_photos + * scope to read any albums, photos, videos, and audio that other users have + * shared with the user. + */ + interface IAlbum { + /** + * The Album object's ID. + */ + id: string; + /** + * Info about the user who authored the album. + */ + from: IUserInfo; + /** + * The name of the album. + */ + name: string; + /** + * A description of the album, or null if no description is specified. + */ + description: string; + /** + * The resource ID of the parent. + */ + parent_id: string; + /** + * The URL to upload items to the album, hosted in SkyDrive. Requires + * the wl.skydrive scope. + */ + upload_location: string; + /** + * A value that indicates whether this album can be embedded. If this + * album can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * The total number of items in the album. + */ + count: number; + /** + * A URL of the album, hosted in SkyDrive. + */ + link: string; + /** + * The type of object; in this case, "album". + */ + type: string; + /** + * The object that contains permissions info for the album. Requires the + * wl.skydrive scope. + */ + shared_with: ISharedWith; + /** + * The time, in ISO 8601 format, at which the album was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, that the system updated the album last. + */ + updated_time: string; + /** + * The time, in ISO 8601 format, that the file was last updated. + */ + client_updated_time: string; + } + + /** + * Represents a new album. + */ + interface INewAlbum { + /** + * The name of the album. + */ + name: string; + /** + * A description of the album. + */ + description?: string; + } + + /** + * The Audio object contains info about a user's audio in SkyDrive. The Live + * Connect REST API supports creating, reading, updating, and deleting Audio + * objects. Use the wl.skydrive scope to read Audio objects. Use the + * wl.contacts_skydrive scope to read any audio that other users have shared + * with the user. Use the wl.skydrive_update scope to create, update, or + * delete Audio objects. + */ + interface IAudio { + /** + * The Audio object's ID. + */ + id: string; + /** + * Info about the user who uploaded the audio. + */ + from: IUserInfo; + /** + * The name of the audio. + */ + name: string; + /** + * A description of the audio, or null if no description is specified. + */ + description: string; + /** + * The id of the folder in which the audio is currently stored. + */ + parent_id: string; + /** + * The size, in bytes, of the audio. + */ + size: number; + /** + * The URL to use to upload a new audio to overwrite the existing audio. + */ + upload_location: string; + /** + * The number of comments associated with the audio. + */ + comments_count: number; + /** + * A value that indicates whether comments are enabled for the audio. If + * comments can be made, this value is true; otherwise, it is false. + */ + comments_enabled: boolean; + /** + * A value that indicates whether this audio can be embedded. If this + * audio can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * The URL to use to download the audio from SkyDrive. + * Warning + * This value is not persistent. Use it immediately after making the + * request, and avoid caching. + */ + source: string; + /** + * A URL to view the item on SkyDrive. + */ + link: string; + /** + * The type of object; in this case, "audio". + */ + type: string; + /** + * The audio's title. + */ + title: string; + /** + * The audio's artist name. + */ + artist: string; + /** + * The audio's album name. + */ + album: string; + /** + * The artist name of the audio's album. + */ + album_artist: string; + /** + * The audio's genre. + */ + genre: string; + /** + * The audio's playing time, in milliseconds. + */ + duration: number; + /** + * A URL to view the audio's picture on SkyDrive. + */ + picture: string; + /** + * The object that contains permission info. + */ + shared_with: ISharedWith; + /** + * The time, in ISO 8601 format, at which the audio was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, at which the audio was last updated. + */ + updated_time: string; + } + + /** + * Represents a new audio item. + */ + interface INewAudio { + /** + * The name of the audio. + */ + name: string; + /** + * A description of the audio. + */ + description?: string; + /** + * The audio's title. + */ + title?: string; + /** + * The audio's artist name. + */ + artist?: string; + /** + * The audio's album name. + */ + album?: string; + /** + * The artist name of the audio's album. + */ + album_artist?: string; + /** + * The audio's genre. + */ + genre?: string; + } + + /** + * The Calendar object contains info about a user's Outlook.com calendar. + * The Live Connect REST API supports creating, reading, updating, and + * deleting calendars. Use the wl.calendars scope to read a user's Calendar + * objects. Use the wl.calendars_update scope to create Calendar objects for + * a user. Use the wl.contacts_calendars scope to read a user's friends' + * Calendar objects. + */ + interface ICalendar { + /** + * The Calendar object's ID. + */ + id: string; + /** + * Name of the calendar. + */ + name: string; + /** + * Description of the calendar. + */ + description: string; + /** + * The time, in ISO 8601 format, at which the calendar was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, that the calendar was last updated. + */ + updated_time: string; + /** + * Info about the user who owns the calendar. + */ + from: IUserInfo; + /** + * A value that indicates whether this calendar is the default calendar. + * If this calendar is the default calendar, this value is true; + * otherwise, it is false. + */ + is_default: boolean; + /** + * A public subscription URL with which Live Connect will synchronize + * properties and events periodically for this calendar. A NULL value + * indicates that this is not a subscribed calendar. + */ + subscription_location: string; + /** + * Role and permissions that are granted to the user for the calendar. + * The possible values are: + * - free_busy: The user can see only free/busy info. + * - limited_details: The user can see a subset of all details. + * - read: The user can only read the content of the calendar events. + * - read_write: The user can read and write calendar and events. + * - co_owner: The user is co-owner of this calendar. + * - owner: The user is the owner of this calendar. + */ + permissions: string; + } + + /** + * Represents a new calendar item. + */ + interface INewCalendar { + /** + * Name of the calendar. + */ + name: string; + /** + * Description of the calendar. + */ + description?: string; + } + + /** + * Represents a request to create a new calendar that subscribes to the + * given iCal calendar. + */ + interface INewCalendarSubscription { + /** + * Name of the calendar. + */ + name: string; + /** + * A public subscription URL with which Live Connect will synchronize + * properties and events periodically for this calendar. + */ + subscription_location: string; + } + + /** + * The Comment object contains info about comments that are associated with + * a photo, audio, or video on SkyDrive. The Live Connect REST API supports + * reading Comment objects. Use the wl.photos scope to read Comment objects. + * Use the wl.contacts_photos scope to read the Comment objects that are + * associated with any albums, photos, and videos that other users have + * shared with the user. + */ + interface IComment { + /** + * The Comment object's id. + */ + id: string; + /** + * Info about the user who created the comment. + */ + from: IUserInfo; + /** + * The text of the comment. The maximum length of a comment is 10,000 + * characters. + */ + message: string; + /** + * The time, in ISO 8601 format, at which the comment was created. + */ + created_time: string; + } + + /** + * Represents a new comment. + */ + interface INewComment { + /** + * The text of the comment. The maximum length of a comment is 10,000 + * characters. + */ + message: string; + } + + /** + * The Contact object contains info about a user's Outlook.com contacts. The + * Live Connect REST API supports reading Contact objects. + */ + interface IContact { + /** + * The Contact object's ID. + */ + id: string; + /** + * The contact's first name, or null if no first name is specified. + */ + first_name: string; + /** + * The contact's last name, or null if no last name is specified. + */ + last_name: string; + /** + * The contact's full name, formatted for location. + */ + name: string; + /** + * A value that indicates whether the contact is set as a friend. If the + * contact is a friend, this value is true; otherwise, it is false. + */ + is_friend: boolean; + /** + * A value that indicates whether the contact is set as a favorite + * contact. If the contact is a favorite, this value is true; otherwise, + * it is false. + */ + is_favorite: boolean; + /** + * The contact's ID, if the contact has one. If not, this value is null. + */ + user_id: string; + /** + * An array containing a SHA-256 hash for each of the contact's email + * addresses. For more info, see Friend finder. + */ + email_hashes: string[]; + /** + * The time, in ISO 8601 format, at which the user last updated the + * data. + */ + updated_time: string; + /** + * The day of the contact's birth date, or null if no birth date is + * specified. + */ + birth_day: number; + /** + * The month of the contact's birth date, or null if no birth date is + * specified. + */ + birth_month: number; + } + + /** + * Represents a new contact. + */ + interface INewContact { + /** + * The contact's first name. + */ + first_name?: string; + /** + * The contact's last name. + */ + last_name?: string; + /** + * An array that contains the contact's work info. + */ + work?: { + employer: { + name: string; + } + }[]; + /** + * The contact's email addresses. + */ + emails?: { + /** + * The contact's preferred email address. + */ + preferred?: string; + /** + * The contact's personal email address. + */ + personal?: string; + /** + * The contact's business email address. + */ + business?: string; + /** + * The contact's "alternate" email address. + */ + other?: string; + }; + } + + /** + * The Error object contains info about an error that is returned by the + * Live Connect APIs. + */ + interface IError { + /** + * Info about the error. + */ + error: { + /** + * The error code. + */ + code: string; + /** + * The error message. + */ + message: string; + }; + } + + /** + * The Event object contains info about events on a user's Outlook.com + * calendars. The Live Connect REST API supports creating Event objects. Use + * the wl.events_create scope to create Event objects on the user's default + * calendar only. Use the wl.calendars scope to read Event objects on the + * user's calendars. Use wl.calendars_update to create Event objects on any + * of the user's calendars. Use the wl.contacts_calendars scope to read + * Event objects from the user's friend's calendars. + */ + interface IEvent { + /** + * The ID of the event. + */ + id: string; + /** + * The name of the event, with a maximum length of 255 characters. This + * structure is required. + */ + name: string; + /** + * The time, in ISO 8601 format, at which the event was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, at which the event was updated. This + * structure is visible only in the Event object that is returned if the + * event was successfully created. + */ + updated_time: string; + /** + * A description of the event, with a maximum length of 32,768 + * characters. This structure is required. + */ + description: string; + /** + * The ID of the calendar that contains the event. + */ + calendar_id: string; + /** + * The object that contains the name and ID of the organizer. + */ + from: IUserInfo; + /** + * The start time, in ISO 8601 format, of the event. When the event is + * being read, the time will be the user's local time, in ISO 8601 + * format. + */ + start_time: string; + /** + * The end time, in ISO 8601 format, of the event. If no end time is + * specified, the default value is 30 minutes after start_time. This + * structure is optional when creating an event. When the event is being + * read, the time will be the user's local time, in ISO 8601 format. + */ + end_time: string; + /** + * The name of the location at which the event will take place. The + * maximum length is 1,000 characters. + */ + location: string; + /** + * A value that specifies whether the event is an all-day event. If the + * event is an all-day event, this value is true; otherwise, it is + * false. If this structure is missing, the default value is false. + */ + is_all_day_event: boolean; + /** + * A value that specifies whether the event is recurring. If the event + * is recurring, this value is true; otherwise, it is false. + */ + is_recurrent: boolean; + /** + * The text description of the recurrence pattern, for example, "Occurs + * every week on Tuesday". The value is Null if this is not a recurrent + * event. + */ + recurrence: string; + /** + * The time, in minutes, before the event for the reminder alarm. + */ + reminder_time: number; + /** + * The user's availability status for the event. Valid values are: + * - free + * - busy + * - tentative + * - out_of_office + * @default "free" + */ + availability: string; + /** + * A value that specifies whether the event is publicly visible. Valid + * values are: + * - public—the event is visible to anyone who can view the calendar. + * - private"—the event is visible only to the event owner. + * @default "public" + */ + visibility: string; + } + + /** + * Represents a new event. + */ + interface INewEvent { + /** + * The name of the event, with a maximum length of 255 characters. This + * structure is required. + */ + name: string; + /** + * A description of the event, with a maximum length of 32,768 + * characters. This structure is required. + */ + description: string; + /** + * The start time of the event. When the event is being read, the time + * will be the user's local time, in ISO 8601 format. + * Can be a date string, or a Date object. + */ + start_time: any; + /** + * The end time of the event. If no end time is specified, the default + * value is 30 minutes after start_time. This structure is optional when + * creating an event. When the event is being read, the time will be the + * user's local time, in ISO 8601 format. + * Can be a date string, or a Date object. + */ + end_time?: any; + /** + * The name of the location at which the event will take place. The + * maximum length is 1,000 characters. + */ + location?: string; + /** + * A value that specifies whether the event is an all-day event. If the + * event is an all-day event, this value is true; otherwise, it is + * false. If this structure is missing, the default value is false. + */ + is_all_day_event?: boolean; + /** + * The time, in minutes, before the event for the reminder alarm. + */ + reminder_time?: number; + /** + * The user's availability status for the event. Valid values are: + * - free + * - busy + * - tentative + * - out_of_office + * @default "free" + */ + availability?: string; + /** + * A value that specifies whether the event is publicly visible. Valid + * values are: + * - public—the event is visible to anyone who can view the calendar. + * - private"—the event is visible only to the event owner. + * @default "public" + */ + visibility?: string; + } + + /** + * Response received after successfully creating a new event. + */ + interface INewEventResponse { + /** + * The name of the event, with a maximum length of 255 characters. This + * structure is required. + */ + name: string; + /** + * A description of the event, with a maximum length of 32,768 + * characters. This structure is required. + */ + description: string; + /** + * The start time, in ISO 8601 format, of the event. When the event is + * being read, the time will be the user's local time, in ISO 8601 + * format. + */ + start_time: string; + /** + * The end time, in ISO 8601 format, of the event. If no end time is + * specified, the default value is 30 minutes after start_time. This + * structure is optional when creating an event. When the event is being + * read, the time will be the user's local time, in ISO 8601 format. + */ + end_time: string; + /** + * The name of the location at which the event will take place. The + * maximum length is 1,000 characters. + */ + location: string; + /** + * A value that specifies whether the event is an all-day event. If the + * event is an all-day event, this value is true; otherwise, it is + * false. If this structure is missing, the default value is false. + */ + is_all_day_event: boolean; + /** + * A value that specifies whether the event is recurring. If the event + * is recurring, this value is true; otherwise, it is false. + */ + is_recurrent: boolean; + /** + * The text description of the recurrence pattern, for example, "Occurs + * every week on Tuesday". The value is Null if this is not a recurrent + * event. + */ + recurrence: string; + /** + * The time, in minutes, before the event for the reminder alarm. + */ + reminder_time: number; + /** + * The user's availability status for the event. Valid values are: + * - free + * - busy + * - tentative + * - out_of_office + * @default "free" + */ + availability: string; + /** + * A value that specifies whether the event is publicly visible. Valid + * values are: + * - public—the event is visible to anyone who can view the calendar. + * - private"—the event is visible only to the event owner. + * @default "public" + */ + visibility: string; + /** + * The time, in ISO 8601 format, at which the event was updated. This + * structure is visible only in the Event object that is returned if the + * event was successfully created. + */ + updated_time: string; + } + + /** + * The File object contains info about a user's files in SkyDrive. The Live + * Connect REST API supports creating, reading, updating, and deleting File + * objects. Use the wl.skydrive scope to read File objects. Use the + * wl.contacts_skydrive scope to read any files that other users have shared + * with the user. Use the wl.skydrive_update scope to create, update, or + * delete File objects. + */ + interface IFile { + /** + * The File object's ID. + */ + id: string; + /** + * Info about the user who uploaded the file. + */ + from: IUserInfo; + /** + * The name of the file. + */ + name: string; + /** + * A description of the file, or null if no description is specified. + */ + description: string; + /** + * The ID of the folder the file is currently stored in. + */ + parent_id: string; + /** + * The size, in bytes, of the file. + */ + size: number; + /** + * The URL to upload file content hosted in SkyDrive. + * Note: This structure is not available if the file is an Microsoft + * Office OneNote notebook. + */ + upload_location: string; + /** + * The number of comments that are associated with the file. + */ + comments_count: number; + /** + * A value that indicates whether comments are enabled for the file. If + * comments can be made, this value is true; otherwise, it is false. + */ + comments_enabled: boolean; + /** + * A value that indicates whether this file can be embedded. If this + * file can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * The URL to use to download the file from SkyDrive. + * Warning: This value is not persistent. Use it immediately after + * making the request, and avoid caching. + * Note: This structure is not available if the file is an Office + * OneNote notebook. + */ + source: string; + /** + * A URL to view the item on SkyDrive. + */ + link: string; + /** + * The type of object; in this case, "file". + * Note: If the file is a Office OneNote notebook, the type structure is + * set to "notebook". + */ + type: string; + /** + * Object that contains permission info. + */ + shared_with: ISharedWith; + /** + * The time, in ISO 8601 format, at which the file was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, that the system updated the file last. + */ + updated_time: string; + /** + * The time, in ISO 8601 format, that the client machine updated the + * file last. + */ + client_updated_time: string; + /** + * Sorts the items to specify the following criteria: updated, name, + * size, or default. + */ + sort_by: string; + } + + /** + * Success response to a new file creation request. + */ + interface INewFileResponse { + /** + * ID of the new item. + */ + id: string; + /** + * The file's name and file extension. + */ + name: string; + /** + * URL where the item can be downloaded from. + */ + source: string; + } + + /** + * Returns when you perform a GET request to /FILE_ID/content. + */ + interface IFileDownloadLink { + /** + * A URL download link for the file. + */ + location: string; + } + + /** + * The Folder object contains info about a user's folders in SkyDrive. + * Folders can contain combinations of photos, videos, audio, and + * subfolders. The Live Connect REST API supports reading Folder objects. + * Use the wl.photos scope to read Folder objects. Use the + * wl.contacts_photos scope to read any albums, photos, videos, and audio + * that other users have shared with the user. + */ + interface IFolder { + /** + * The Folder object's ID. + */ + id: string; + /** + * Info about the user who created the folder. + */ + from: IUserInfo; + /** + * The name of the folder. + */ + name: string; + /** + * A description of the folder, or null if no description is specified. + */ + description: string; + /** + * The total number of items in the folder. + */ + count: number; + /** + * The URL of the folder, hosted in SkyDrive. + */ + link: string; + /** + * The resource ID of the parent. + */ + parent_id: string; + /** + * The URL to upload items to the folder hosted in SkyDrive. Requires + * the wl.skydrive scope. + */ + upload_location: string; + /** + * A value that indicates whether this folder can be embedded. If this + * folder can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * The type of object; in this case, "folder". + */ + type: string; + /** + * The time, in ISO 8601 format, at which the folder was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, that the system updated the file last. + */ + updated_time: string; + /** + * The time, in ISO 8601 format, that the client machine updated the + * file last. + */ + client_updated_time: string; + /** + * Permissions info for the folder. Requires the wl.skydrive scope. + */ + shared_with: ISharedWith; + /** + * Sorts the items to specify the following criteria: updated, name, + * size, or default. + */ + sort_by: string; + } + + /** + * Represents a new folder. + */ + interface INewFolder { + /** + * The name of the folder. + */ + name: string; + /** + * A description of the folder. + */ + description?: string; + /** + * Sorts the items to specify the following criteria: updated, name, + * size, or default. + */ + sort_by?: string; + } + + /** + * The Friend object contains info about a user's friends. A Friend object + * represents a user's contact whose is_friend value is set to true. The + * Live Connect REST API supports reading Friend objects. + */ + interface IFriend { + /** + * The friend's ID. + */ + id: string; + /** + * The friend's full name, formatted for locale. + */ + name: string; + } + + /** + * The Permissions object contains a list of scopes, showing those scopes to + * which the user has consented. The response body contains a JSON object + * that lists all consented scopes as a name/value pair. Each scope to which + * the user consented is present as a key. + */ + interface IPermissions { + [scope: string]: number; + } + + /** + * Information about an image. + */ + interface IImageInfo { + /** + * The height, in pixels, of this image of this particular size. + */ + height: number; + /** + * The width, in pixels, of this image of this particular size. + */ + width: number; + /** + * The width, in pixels, of this image of this particular size. + */ + source: string; + /** + * The type of this image of this particular size. Valid values are: + * full (maximum size: 2048 × 2048 pixels) + * - normal (maximum size 800 × 800 pixels) + * - album (maximum size 176 × 176 pixels) + * - small (maximum size 96 × 96 pixels) + */ + type: string; + } + + /** + * Represents location information. + */ + interface ILocation { + /** + * The latitude portion of the location, expressed as positive (north) + * or negative (south) degrees relative to the equator. + */ + latitude: number; + /** + * The longitude portion of the location expressed as positive (east) or + * negative (west) degrees relative to the Prime Meridian. + */ + longitude: number; + /** + * The altitude portion of the location, expressed as positive (above) + * or negative (below) values relative to sea level, in units of + * measurement as determined by the camera. + */ + altitude: number; + } + + /** + * The Photo object contains info about a user's photos on SkyDrive. The + * Live Connect REST API supports creating, reading, updating, and deleting + * Photo objects. Use the wl.photos scope to read Photo objects. Use the + * wl.contacts_photos scope to read any albums, photos, videos, and audio + * that other users have shared with the user. Use the wl.skydrive_update + * scope to create, update, or delete Photo objects. + */ + interface IPhoto { + /** + * The Photo object's ID. + */ + id: string; + /** + * Info about the user who uploaded the photo. + */ + from: IUserInfo; + /** + * The file name of the photo. + */ + name: string; + /** + * A description of the photo, or null if no description is specified. + */ + description: string; + /** + * The ID of the folder where the item is stored. + */ + parent_id: string; + /** + * The size, in bytes, of the photo. + */ + size: number; + /** + * The number of comments associated with the photo. + */ + comments_count: number; + /** + * A value that indicates whether comments are enabled for the photo. If + * comments can be made, this value is true; otherwise, it is false. + */ + comments_enabled: boolean; + /** + * The number of tags on the photo. + */ + tags_count: number; + /** + * A value that indicates whether tags are enabled for the photo. If + * users can tag the photo, this value is true; otherwise, it is false. + */ + tags_enabled: boolean; + /** + * A value that indicates whether this photo can be embedded. If this + * photo can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * A URL of the photo's picture. + */ + picture: string; + /** + * The download URL for the photo. + * Warning: This value is not persistent. Use it immediately after + * making the request, and avoid caching. + */ + source: string; + /** + * The URL to upload photo content hosted in SkyDrive. This value is + * returned only if the wl.skydrive scope is present. + */ + upload_location: string; + /** + * Info about various sizes of the photo. + */ + images: IImageInfo[]; + /** + * A URL of the photo, hosted in SkyDrive. + */ + link: string; + /** + * The date, in ISO 8601 format, on which the photo was taken, or null + * if no date is specified. + */ + when_taken: string; + /** + * The height, in pixels, of the photo. + */ + height: number; + /** + * The width, in pixels, of the photo. + */ + width: number; + /** + * The type of object; in this case, "photo". + */ + type: string; + /** + * The location where the photo was taken. + * Note: The location object is not available for shared photos. + */ + location: ILocation; + /** + * The manufacturer of the camera that took the photo. + */ + camera_make: string; + /** + * The brand and model number of the camera that took the photo. + */ + camera_model: string; + /** + * The f-number that the photo was taken at. + */ + focal_ratio: number; + /** + * The focal length that the photo was taken at, typically expressed in + * millimeters for newer lenses. + */ + focal_length: number; + /** + * The numerator of the shutter speed (for example, the "1" in "1/15 s") + * that the photo was taken at. + */ + exposure_numerator: number; + /** + * The denominator of the shutter speed (for example, the "15" in "1/15 + * s") that the photo was taken at. + */ + exposure_denominator: number; + /** + * The object that contains permissions info for the photo. + */ + shared_with: ISharedWith; + /** + * The time, in ISO 8601 format, at which the photo was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, at which the photo was last updated. + */ + updated_time: string; + } + + /** + * The Search object contains info about the objects found in a user's + * SkyDrive that match the search query. See Search query parameters for + * info about formatting a search query request. + */ + interface ISearch { + /** + * An array of file and folder objects found in a user's SkyDrive that + * match the search query. + */ + data: IObject[]; + /** + * The path strings that reference the next and previous sets in a + * paginated response. + */ + paging?: { + /** + * Path string for the next set of results. + */ + next?: string; + /** + * Path string for the previous set of results. + */ + previous?: string; + }; + } + + /** + * The Tag object contains info about tags that are associated with a photo + * or a video on SkyDrive. The Live Connect REST API supports reading Tag + * objects. Use the wl.photos, and wl.skydrive scopes to read Tag objects. + * Use the wl.contacts_photos and wl.contacts_skydrive scopes to read the + * Tag objects that are associated with any photos that other users have + * shared with the user. + */ + interface ITag { + /** + * The Tag object's ID. + */ + id: string; + /** + * The user object for the tagged person. + */ + user: IUserInfo; + /** + * The center of the tag's horizontal position, measured as a + * floating-point percentage from 0 to 100, from the left edge of the + * photo. This value is not returned for Video objects. + */ + x: number; + /** + * The center of the tag's vertical position, measured as a + * floating-point percentage from 0 to 100, from the top edge of the + * photo. This value is not returned for Video objects. + */ + y: number; + /** + * The time, in ISO 8601 format, at which the tag was created. + */ + created_time: string; + } + + /** + * Contains work information for one employer. + */ + interface IWorkInfo { + /** + * Info about the user's employer. + */ + employer: { + /** + * The name of the user's employer, or null if the employer's name + * is not specified. + */ + name: string; + }; + /** + * Info about the user's work position. + */ + position: { + /** + * The name of the user's work position, or null if the name of the + * work position is not specified. + */ + name: string; + }; + } + + /** + * Information about one postal address. + */ + interface IPostalAddress { + /** + * The street address, or null if one is not specified. + */ + street: string; + /** + * The second line of the street address, or null if one is not + * specified. + */ + street_2: string; + /** + * The city of the address, or null if one is not specified. + */ + city: string; + /** + * The state of the address, or null if one is not specified. + */ + state: string; + /** + * The postal code of the address, or null if one is not specified. + */ + postal_code: string; + /** + * The region of the address, or null if one is not specified. + */ + region: string; + } + + /** + * The User object contains info about a user. The Live Connect REST API + * supports reading User objects. + */ + interface IUser { + /** + * The user's ID. + */ + id: string; + /** + * The user's full name. + */ + name: string; + /** + * The user's first name. + */ + first_name: string; + /** + * The user's last name. + */ + last_name: string; + /** + * The user's gender, or null if no gender is specified. + */ + gender: string; + /** + * The URL of the user's profile page. + */ + link: string; + /** + * The day of the user's birth date, or null if no birth date is + * specified. + */ + birth_day: number; + /** + * The month of the user's birth date, or null if no birth date is + * specified. + */ + birth_month: number; + /** + * The year of the user's birth date, or null if no birth date is + * specified. + */ + birth_year: number; + /** + * An array that contains the user's work info. + */ + work: IWorkInfo[]; + /** + * The user's email addresses. + */ + emails: { + /** + * The user's preferred email address, or null if one is not + * specified. + */ + preferred: string; + /** + * The email address that is associated with the account. + */ + account: string; + /** + * The user's personal email address, or null if one is not + * specified. + */ + personal: string; + /** + * The user's business email address, or null if one is not + * specified. + */ + business: string; + /** + * The user's "alternate" email address, or null if one is not + * specified. + */ + other: string; + }; + /** + * The user's postal addresses. + */ + addresses: { + /** + * The user's personal postal address. + */ + personal: IPostalAddress; + /** + * The user's business postal address. + */ + business: IPostalAddress; + }; + /** + * The user's phone numbers. + */ + phones: { + /** + * The user's personal phone number, or null if one is not + * specified. + */ + personal: string; + /** + * The user's business phone number, or null if one is not + * specified. + */ + business: string; + /** + * The user's mobile phone number, or null if one is not specified. + */ + mobile: string; + }; + /** + * The user's locale code. + */ + locale: string; + /** + * The time, in ISO 8601 format, at which the user last updated the + * object. + */ + updated_time: string; + } + + /** + * The Video object contains info about a user's videos on SkyDrive. The + * Live Connect REST API supports creating, reading, updating, and deleting + * Video objects. Use the wl.photos scope to read Video objects. Use the + * wl.contacts_photos scope to read albums, photos, and videos that other + * users have shared with the user. Use the wl.skydrive_update scope to + * create, update, or delete Video objects. + */ + interface IVideo { + /** + * The Video object's ID. + */ + id: string; + /** + * Info about the user who uploaded the video. + */ + from: IUserInfo; + /** + * The file name of the video. + */ + name: string; + /** + * A description of the video, or null if no description is specified. + */ + description: string; + /** + * The id of the folder where the item is stored. + */ + parent_id: string; + /** + * The size, in bytes, of the video. + */ + size: number; + /** + * The number of comments that are associated with the video. + */ + comments_count: number; + /** + * A value that indicates whether comments are enabled for the video. If + * comments can be made, this value is true; otherwise, it is false. + */ + comments_enabled: boolean; + /** + * The number of tags on the video. + */ + tags_count: number; + /** + * A value that indicates whether tags are enabled for the video. If + * tags can be set, this value is true; otherwise, it is false. + */ + tags_enabled: boolean; + /** + * A value that indicates whether this video can be embedded. If this + * video can be embedded, this value is true; otherwise, it is false. + */ + is_embeddable: boolean; + /** + * A URL of a picture that represents the video. + */ + picture: string; + /** + * The download URL for the video. + * Warning: This value is not persistent. Use it immediately after + * making the request, and avoid caching. + */ + source: string; + /** + * The URL to upload video content, hosted in SkyDrive. This value is + * returned only if the wl.skydrive scope is present. + */ + upload_location: string; + /** + * A URL of the video, hosted in SkyDrive. + */ + link: string; + /** + * The height, in pixels, of the video. + */ + height: number; + /** + * The width, in pixels, of the video. + */ + width: number; + /** + * The duration, in milliseconds, of the video run time. + */ + duration: number; + /** + * The bit rate, in bits per second, of the video. + */ + bitrate: number; + /** + * The type of object; in this case, "video". + */ + type: string; + /** + * The object that contains permission info. + */ + shared_with: ISharedWith; + /** + * The time, in ISO 8601 format, at which the video was created. + */ + created_time: string; + /** + * The time, in ISO 8601 format, at which the video was last updated. + */ + updated_time: string; + } + + //#endregion REST Object Information + + //#region API Properties Interfaces + + /** + * 'Properties' object passed into the WL.api method. + */ + interface IAPIProperties { + /** + * Contains the path to the REST API object. For information on + * specifying paths for REST objects, see REST reference. + * http://msdn.microsoft.com/en-us/library/live/hh243648.aspx + */ + path: string; + /** + * An HTTP method that specifies the action required for the API call. + * These actions are standard REST API actions: "COPY", "GET", "MOVE", + * "PUT", "POST", and "DELETE". + * @default "GET" + */ + method?: string; + /** + * A JSON object that specifies the REST API request body. The body + * property is used only for "POST" and "PUT" requests. + */ + body?: any; + } + + /** + * 'Properties' object passed into the WL.backgroundDownload method. + */ + interface IBackgroundDownloadProperties { + /** + * The path to the file to download. For information on specifying paths + * for REST objects, see REST reference. + * http://msdn.microsoft.com/en-us/library/live/hh243648.aspx + */ + path: string; + /** + * The file output object to which the downloaded file data is written. + */ + file_output?: Windows.Storage.StorageFile; + } + + /** + * 'Properties' object passed into the WL.backgroundUpload method. + */ + interface IBackgroundUploadProperties { + /** + * The path to the file to upload. + */ + path: string; + /** + * The name of the file to upload. + */ + file_name?: string; + /** + * The file input object to read the file from. Can be a + * Windows.Storage.StorageFile or an IFile. + */ + file_input?: any; + /** + * The file input stream to read the file from. + */ + stream_input?: Windows.Storage.Streams.IInputStream; + /** + * Indicates whether the uploaded file should overwrite an existing + * copy. Specify "true" to overwrite, "false" to not overwrite and for + * the WL.backgroundUpload method call to fail, or "rename" to not + * overwrite and enable SkyDrive to assign a new name to the uploaded + * file. + * @default "false". + */ + overwrite?: string; + } + + /** + * 'Properties' object passed into the WL.download method. + */ + interface IDownloadProperties { + /** + * The path to the file to download. For information on specifying paths + * for REST objects, see REST reference. + * http://msdn.microsoft.com/en-us/library/live/hh243648.aspx + */ + path: string; + } + + /** + * 'Properties' object passed into the WL.fileDialog method. + */ + interface IFileDialogProperties { + /** + * Specifies the type of SkyDrive file picker to display. Specify "open" + * to display the download version of the file picker. Specify "save" + * to display the upload version of the file picker. + */ + mode: string; + /** + * Specify only if the mode property is set to "open". Specifies how + * many files the user can select to download. Specify "single" for a + * single file. Specify "multi" for multiple files. + * @default "single" + */ + select?: string; + /** + * The color pallette to use for the file picker. Specify "white", + * "grey", or "transparent". + * @default "white" + */ + lightbox?: string; + } + + /** + * 'Properties' object passed into the WL.init method. + */ + interface IInitProperties { + /** + * Web apps: Required. + * Specifies your app's OAuth client ID for web apps. + * + * Windows Store apps using JavaScript: not needed. + */ + client_id?: string; + /** + * Contains the default redirect URI to be used for OAuth + * authentication. For web apps, the OAuth server redirects to this URI + * during the OAuth flow. + * + * For Windows Store apps using JavaScript, specifying this value will + * enable the library to return the authentication token. + */ + redirect_uri?: string; + /** + * The scope values used to determine which portions of user data the + * app has access to, if the user consents. + * + * For a single scope, use this format: scope: "wl.signin". For multiple + * scopes, use this format: scope: ["wl.signin", "wl.basic"]. + */ + scope?: any; + /** + * If set to "true", the library logs error info to the web browser + * console and notifies your app by means of the wl.log event. + * @default true + */ + logging?: boolean; + /** + * Web apps: optional. + * Windows Store apps using JavaScript: not applicable. + * If set to "true", the library attempts to retrieve the user's sign-in + * status from Live Connect. + * @default true + */ + status?: boolean; + /** + * Web apps: optional. + * Windows Store apps using JavaScript: not applicable. + * Specifies the OAuth response type value. If set to "token", the + * client receives the access token directly. If set to "code", the + * client receives an authorization code, and the app server that serves + * the redirect_uri page should retrieve the access_token from the OAuth + * server by using the authorization code and client secret. + * + * You can only set response_type to "code" for web apps. + * @default "token" + */ + response_type?: string; + /** + * Web apps: optional. + * Windows Store apps using JavaScript: not applicable. + * If set to "true", the library specifies a secure attribute when + * writing a cookie on an HTTPS page. + * @default "false" + */ + secure_cookie?: string; + } + + /** + * 'Properties' object passed into the WL.login method. + */ + interface ILoginProperties { + /** + * This parameter only applies to web apps. + * Contains the redirect URI to be used for OAuth authentication. This + * value overrides the default redirect URI that is provided in the call + * to WL.init. + */ + redirect_uri?: string; + /** + * Specifies the scopes to which the user who is signing in consents. + * + * For a single scope, use this format: scope: "wl.signin". For multiple + * scopes, use this format: scope: ["wl.signin", "wl.basic"]. + * + * If no scope is provided, the scope value of WL.init is used. If no + * scope is provided in WL.init or WL.login, WL.login returns an error. + * + * Note WL.login can request the "wl.offline_access" scope, but it + * requires a server-side implementation, and the WL.init function must + * set its response_type property to "code". For more info, see + * Server-side scenarios. + * http://msdn.microsoft.com/en-us/library/live/hh243649.aspx + */ + scope: any; + /** + * Windows Store apps using JavaScript: not applicable. + * Web apps: Optional. If the WL.init function's response_type object is + * set to "code" and the app uses server-flow authentication, the state + * object here can be used to track the web app's calling state on the + * web app server side. For more info, see the description of the state + * query parameter in the Server-side scenarios topic's "Getting an + * authorization code" section. + * http://msdn.microsoft.com/en-us/library/live/hh243649.aspx + */ + state?: string; + } + + /** + * 'Properties' object passed into the WL.ui method. + */ + interface IUIProperties { + /** + * Specifies the type of button to display. Specify "signin" to display + * the Live Connect sign-in button. Specify "skydrivepicker" to display + * the SkyDrive button. + */ + name: string; + /** + * The value of the id attribute of the
tag to display the button + * in. + */ + element: string; + /** + * Windows Store apps using JavaScript: not applicable. + * Web apps: Optional. If the name property is set to "signin", the + * WL.init function's response_type property is set to "code", and the + * app uses server-flow authentication, the state object here can be + * used to track the web app's calling state on the web app server side. + * For more info, see the description of the state query parameter in + * the Server-side scenarios topic's "Getting an authorization code" + * section. + * http://msdn.microsoft.com/en-us/library/live/hh243649.aspx + */ + state?: string; + } + + /** + * 'Properties' object passed into the WL.ui method when 'name' is set to + * 'skydrivepicker'. + */ + interface ISkyDrivePickerProperies extends IUIProperties { + /** + * The type of SkyDrive file picker button to display. Specify "save" to + * display the upload button. Specify "open" to display the download + * button. + */ + mode: string; + /** + * Required if the mode property is set to "open". Specifies how many + * files the user can select to download. Specify "single" for a single + * file. Specify "multi" for multiple files. + * @default "single" + */ + select?: string; + /** + * Defines the color pallette used for the file picker button. Valid + * values are "white" and "blue". + * @default "white" + */ + theme?: string; + /** + * Defines the color pallette used for the file picker dialog box. Valid + * values are "white", "gray", and "transparent". + * @default "white" + */ + lightbox?: string; + /** + * If the mode property is set to "save", specifies the function to call + * after the user clicks either Save or Cancel in the file picker. If + * the mode property is set to "open", specifies the function to call + * after the user clicks either Open or Cancel in the file picker. + */ + onselected?: Function; + /** + * Specifies the function to call if the selected files cannot be + * successfully uploaded or downloaded. + */ + onerror?: Function; + } + + /** + * 'Properties' object passed into the WL.ui method when 'name' is set to + * 'signin'. + */ + interface ISignInProperties extends IUIProperties { + /** + * Defines the brand, or type of icon, to be used with the Live Connect + * sign-in button. + * @default "windows" + */ + brand?: string; + /** + * Defines the color pallette used for the sign-in button. For Windows + * Store apps using JavaScript, valid values are "dark" and "light". + * For web apps, valid values are "blue" and "white". + */ + theme?: string; + /** + * Defines the type of button. + * @default "signin" + */ + type?: string; + /** + * If the value of the type property is set to "custom", this value + * specifies the sign-in text to be displayed in the button. + */ + sign_in_text?: string; + /** + * If the value of the type property is "custom", this value specifies + * the sign-out text to be displayed in the button. + */ + sign_out_text?: string; + /** + * Specifies the function to call after the user completes the sign-in + * process. + */ + onloggedin?: Function; + /** + * Specifies the function to call after the user completes the sign-out + * process. + */ + onloggedout?: Function; + /** + * Specifies the function to call whenever there is any error while the + * sign-in control is initializing or while the user is signing in. + */ + onerror?: Function; + } + + /** + * 'Properties' object passed into the WL.upload method. + */ + interface IUploadProperties { + /** + * The path to the file to upload. + */ + path: string; + /** + * The id attribute of the tag containing info about the file to + * upload. + */ + element: string; + /** + * Indicates whether the uploaded file should overwrite an existing + * copy. Specify true or "true" to overwrite, false or "false" to not + * overwrite and for the WL.upload method call to fail, or "rename" to + * not overwrite and enable SkyDrive to assign a new name to the + * uploaded file. + * @default "false" + */ + overwrite?: string; + } + + //#endregion API Properties Interfaces + + /** + * Represents the user's session. + */ + interface ISession { + /** + * The user's access token. + */ + access_token: string; + /** + * The authentication token. + */ + authentication_token: string; + /** + * A list of scopes that the app has requested and that the user has + * consented to. + * + * Note: This property is not available for Windows Store apps using + * JavaScript. + */ + scope?: string[]; + /** + * The amount of time remaining, in seconds, until the user's access + * token expires. + * + * Note: This property is not available for Windows Store apps using + * JavaScript. + */ + expires_in?: number; + /** + * The exact time when the session will expire. This time is expressed + * in the number of seconds since 1 January, 1970. + * + * Note: This property is not available for Windows Store apps using + * JavaScript. + */ + expires?: number; + } + + /** + * Represents the user's login status. + */ + interface ILoginStatus { + /** + * The sign-in status of the user. Valid values are "connected", + * "notConnected", or "unknown". + */ + status: string; + /** + * A JSON object that contains the properties of the current session. + */ + session: ISession; + } + + /** + * Represents the Microsoft.Live.API.Event object. + */ + interface IEventAPI { + /** + * Adds a handler to an event. + * @param event Required. The name of the event to which to add a + * handler. + * @param callback Required. Specifies the name of the callback function + * to handle the event. + * @returns This function can return the following errors: + * WL.Event.subscribe: The input parameter/property 'callback' must be + * included. + * WL.Event.subscribe: The input value for parameter/property 'event' + * is not valid. + */ + subscribe(event: string, callback: Function): void; + /** + * Removes a handler from an event. + * @param event Required. The name of the event from which to remove a + * handler. + * @param callback Optional. Removes the callback function from the + * event. If this parameter is omitted or is null, all callback + * functions that are registered to the event are removed. Removes the + * callback function from the specified event. + */ + unsubscribe(event: string, callback?: Function): void; + } + + /** + * Returned from a successful file picker operation. + */ + interface IFilePickerResult { + /** + * Contains data concerning the user's picked files. + */ + data: { + /** + * Information on files choden in the picker. + */ + files?: IFile[]; + /** + * Information on folders chosen in the picker. + */ + folders?: IFolder[]; + } + } + + /** + * The promise API implemented by this library. + */ + interface IPromise { + /** + * Adds event listeners for particular events. + * @param onSuccess Called when the promised event successfully occurs. + * @param onError Called when the promised event fails to occur. Could + * be an IError or an IJSError. + * @param onProgress Called to indicate that the promised event is + * making progress toward completion. + */ + then(onSuccess: (response: T) => void, + onError?: (error: any) => void, + onProgress?: (progress: any) => void): IPromise; + /** + * Cancels the pending request represented by the Promise, and triggers + * the error callback if the promised event has not yet occurred. + */ + cancel(): void; + } + + /** + * An error returned by the JavaScript library, as opposed to an error + * object from the REST API (which we represent with IError). + */ + interface IJSError { + /** + * The error code. + */ + error: string; + /** + * A description of the error. + */ + error_description: string; + } + + /** + * The Live Connect JavaScript API (Windows 8 and web), together with the + * REST API, enables apps to read, update, and share user data by using the + * JavaScript programming language. The JavaScript API (Windows 8 and web) + * provides methods for signing users in and out, getting user status, + * subscribing to events, creating UI controls, and calling the + * Representational State Transfer (REST) API. + */ + interface API { + /** + * Makes a call to the Live Connect Representational State Transfer + * (REST) API. This method encapsulates a REST API request, and then + * calls a callback function to process the response. + * @param properties Required. A JSON object that contains properties + * that are necessary to make the REST API call. + * @param callback Specifies a callback function that is executed when + * the REST API call is complete. The callback function takes the API + * response object as a parameter. The response object exposes the + * data returned from Live Connect, or, if an error occurs, an error + * property that contains the error code. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess, onError, and onProgress parameters to enable your + * code to handle a successful, failed, and in-progress call to the + * corresponding WL.api method, respectively. + */ + api(properties: IAPIProperties, + callback?: (response: any) => void): IPromise; + /** + * Makes a call to download a file from Microsoft SkyDrive. + * + * **Important**: WL.backgroundDownload is supported only for use with + * Windows Store apps using JavaScript. If you are writing a web app, + * use WL.download instead. + * @param properties Required. A JSON object that contains properties + * that are necessary to make the REST API call. + * @param Optional. Specifies a callback function that is executed when + * the REST API call is complete. The callback function takes the API + * response object as a parameter. The response object exposes the + * data that is returned from Live Connect, or, if an error occurs, an + * error property that contains the error code. + * @returns Returns a Promise object. This object's then method accepts + * callback functions for onSuccess, onError, and onProgress to enable + * your code to handle a successful, failed, and in-progress call to + * the corresponding WL.download method, respectively. + * The onSuccess callback is passed a response object that contains + * content_type and stream properties, representing the downloaded + * file's content type and file stream, respectively. + */ + backgroundDownload(properties: IBackgroundDownloadProperties, + callback?: (response: any) => void): IPromise; + /** + * Makes a call to upload a file to Microsoft SkyDrive. + * + * **Important**: WL.backgroundUpload is supported only for use with + * Windows Store apps using JavaScript. If you are writing a web app, + * use WL.upload instead. + * @param properties Required. A JSON object that contains properties + * that are necessary to make the REST API call. + * @param callback Optional. Specifies a callback function that is + * executed when the REST API call is complete. The callback function + * takes the API response object as a parameter. The response object + * exposes the data returned from Live Connect, or if an error occurs, + * an error property that contains the error code. + * @returns Returns a Promise object. For Windows Store apps using + * JavaScript, this object's then method accepts callback functions + * for onSuccess, onError, and onProgress to enable your code to + * handle a successful, failed, and in-progress call to the + * corresponding WL.backgroudUpload method, respectively. + */ + backgroundUpload(properties: IBackgroundUploadProperties, + callback?: (response: any) => void): IPromise; + /** + * Specifies whether the current user can be signed out of his or her + * Microsoft account. + * + * For Windows Store apps using JavaScript, you can use this function to + * determine whether you should display a control to the user to enable + * him or her to sign out of his or her Microsoft account. If this + * function returns true, you should display the control. However, if + * this function returns false, you should not display this control, as + * attempting to sign out the user in this case will have no effect. + * + * For web apps, this function always returns true. + * @returns Returns true if the user can be signed out; otherwise, + * returns false if the user can't be signed out. + */ + canLogout(): boolean; + /** + * Makes a call to download a file from Microsoft SkyDrive. + * + * **Important**: WL.download is supported only for use with web apps. + * If you are writing a Windows Store app using JavaScript, use + * WL.backgroundDownload instead. + * @param properties Required. A JSON object that contains properties + * that are necessary to make the REST API call. + * @param callback Specifies a callback function that is executed when + * the REST API call is complete. The callback function takes the API + * response object as a parameter. The response object exposes the + * data that is returned from Live Connect, or, if an error occurs, an + * error property that contains the error code. + * @returns Returns a Promise object. This object's then method provides + * the onError parameter to enable your code to handle a failed call + * to the corresponding WL.download method. + */ + download(properties: IDownloadProperties, + callback?: (response: any) => void): IPromise; + Event: IEventAPI; + /** + * Displays the Microsoft SkyDrive file picker, which enables + * JavaScript-based web apps to display a pre-built, consistent user + * interface that enables a user to select files to upload and download + * to and from his or her SkyDrive storage location. + * @param properties Required. A JSON object containing properties for + * displaying the button. + * @param callback Optional. A callback function that is executed after + * the user finishes interacting with the SkyDrive file picker. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess and onError parameters to enable your code to handle + * a successful and failed call to the corresponding WL.fileDialog + * method, respectively. + */ + fileDialog(properties: IFileDialogProperties, + callback?: (response: any) => void): IPromise; + /** + * Returns the sign-in status of the current user. If the user is signed + * in and connected to your app, this function returns the session + * object. This is an asynchronous function that returns the user's + * status by contacting the Live Connect authentication web service. + * @param callback Returns the sign-in status of the current user. If + * the user is signed in and connected to your app, this function + * returns the session object. This is an asynchronous function that + * returns the user's status by contacting the Live Connect + * authentication web service. + * @param force Optional. If set to "true", the function contacts the + * Live Connect authentication web service to determine the user's + * status. If set to "false" (the default), the function can return + * the user status that is currently in memory, if there is one. If + * the user's status has already been retrieved, the library can + * return the cached value. However, you can force the library to + * retrieve current status by setting the force parameter to "true". + * @returns Returns a Promise object. This object's then method provides + * the onSuccess and onError parameters to enable your code to handle + * a successful and failed call to the corresponding WL.getLoginStatus + * method, respectively. + * In the body of the onSuccess function, a status object is returned, + * which contains the user's sign-in status and the session object. + */ + getLoginStatus(callback?: (status: ILoginStatus) => void, + force?: boolean): IPromise; + /** + * Retrieves the current session object synchronously, if a session + * object exists. For situations in which performance is critical, such + * as page loads, use the asynchronous WL.getLoginStatus method instead. + * @returns Returns the current session as a session object instance. + */ + getSession(): ISession; + /** + * Initializes the JavaScript library. An app must call this function on + * every page before making other function calls in the library. The app + * should call this function before making function calls that subscribe + * to events. If the JavaScript library has already been initialized on + * the page, calling this function succeeds silently; the client_id and + * redirect_uri parameters are not validated. + * @param properties Required. A JSON object with initialization + * properties. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess and onError parameters to enable your code to handle + * a successful and failed call to the corresponding WL.init method, + * respectively. + * When the onSuccess callback is invoked, a login status object is + * passed in as parameter that indicates the current user's login + * status. + */ + init(properties: IInitProperties): IPromise; + /** + * Signs in the user or expands the user's list of scopes. Because this + * function can result in launching the consent page prompt, you should + * call it only in response to a user action, such as clicking a button. + * Otherwise, the user's web browser might block the popup. + * + * Typically, this function is used by apps that define their own + * sign-in controls, or by apps that ask users to grant additional + * permissions during an activity. For example, to enable a user to post + * his or her status to Live Connect, your app may have to prompt the + * user for permission and call this function with an expanded scope. + * + * If you call this function when the user has already consented to the + * requested scope and is already signed in, the callback function is + * invoked immediately with the current session. + * This function logs errors to the web browser console. + * @param properties Required. A JSON object with login properties. + * @param callback Optional. Specifies a callback function to execute + * when sign-in is complete. The callback function takes the status + * object as a parameter. For a description of the status object, see + * WL.getLoginStatus. If you do not specify a callback function, your + * app can still get the sign-in callback info by listening for an + * auth.sessionChange or auth.statusChange event. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess, onError, and onProgress parameters to enable your + * code to handle a successful, failed, and in-progress call to the + * corresponding WL.login method, respectively. + */ + login(properties: ILoginProperties, + callback?: (status: any) => void): IPromise; + /** + * Signs the user out of Live Connect and clears any user state that is + * maintained by the JavaScript library, such as cookies. If the user + * account is connected, this function logs out the user from the app, + * but not from the PC. This function is useful primarily for websites + * that do not use the sign-in control. + * @param callback Optional. Specifies a callback function that is + * executed when sign-out is complete. The callback function takes the + * status object as a parameter. For a description of the status + * object, see WL.getLoginStatus. If you do not specify a callback + * function, your app can still get the sign-out callback info by + * listening for an auth.sessionChange or auth.statusChange event. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess, onError, and onProgress parameters to enable your + * code to handle a successful, failed, and in-progress call to the + * corresponding WL.logout method, respectively. + */ + logout(callback?: (status: ILoginStatus) => void): IPromise; + /** + * Displays either the Live Connect sign-in button or the Microsoft + * SkyDrive file picker button. The sign-in button either prompts the + * user for his or her Microsoft account credentials if he or she is not + * signed in or else signs out the user if he or she is signed in. The + * file picker button displays the SkyDrive file picker to help the user + * select files to upload or download to or from his or her SkyDrive + * storage location. + * @param properties Required. A JSON object containing properties for + * displaying the button. + * @param callback Optional. A callback function that is executed after + * the sign-in button or file picker button is displayed. + * Note: Do not use the callback parameter to run code after the user + * finishes interacting with the sign-in button or file picker. Use a + * combination of the onselected, onloggedin, onloggedout, and onerror + * properties as previously described. + */ + ui(properties: IUIProperties, callback?: () => void): void; + /** + * Makes a call to upload a file to Microsoft SkyDrive. + * + * **Important**: WL.upload is supported only for use with web apps. If + * you are writing a Windows Store app using JavaScript, use + * WL.backgroundUpload instead. + * @param properties Required. A JSON object that contains properties + * that are necessary to make the REST API call. + * @param callback Optional. Specifies a callback function that is + * executed when the REST API call is complete. The callback function + * takes the API response object as a parameter. The response object + * exposes the data returned from Live Connect, or if an error occurs, + * an error property that contains the error code. + * @returns Returns a Promise object. This object's then method provides + * the onSuccess, onError, and onProgress parameters to enable your + * code to handle a successful, failed, and in-progress call to the + * corresponding WL.upload method, respectively; however, the + * onProgress parameter applies to newer web browsers such as Internet + * Explorer 10 only. + */ + upload(properties: IUploadProperties, + callback?: (response: any) => void): IPromise; + } +} + +/** + * The WL object is a global object that encapsulates all functions of the + * JavaScript API (Windows 8 and web). Your app uses the WL object to call all + * of the JavaScript API (Windows 8 and web) functions. + */ +declare var WL: Microsoft.Live.API; diff --git a/microsoft-live-connect/microsoft-live-connect.ts b/microsoft-live-connect/microsoft-live-connect.ts new file mode 100644 index 000000000..98fcf5a3b --- /dev/null +++ b/microsoft-live-connect/microsoft-live-connect.ts @@ -0,0 +1,1048 @@ +/// + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550838.aspx + */ +function createFolder_onClick() { + var login_props: Microsoft.Live.ILoginProperties = { + scope: "wl.skydrive_update" + }; + WL.login(login_props).then( + function (response) { + var newFolder: Microsoft.Live.INewFolder = { + "name": "This is a new folder", + "description": "A new folder" + }, api_properties: Microsoft.Live.IAPIProperties = { + path: "me/skydrive", + method: "POST", + body: newFolder + }; + WL.api(api_properties).then( + function (response) { + document.getElementById("infoArea").innerText = + "Created folder. Name: " + response.name + ", ID: " + response.id; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoArea").innerText = + "Error calling API: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IJSError) { + document.getElementById("infoArea").innerText = + "Error signing in: " + responseFailed.error_description; + } + ); +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/jj219386.aspx + */ +function downloadFile_onClick() { + var picker = setupSavePicker(); + picker.pickSaveFileAsync().then( + function (file) { + if (file && (file instanceof Windows.Storage.StorageFile)) { + WL.login({ + scope: "wl.skydrive" + }).then( + function (response) { + WL.backgroundDownload({ + path: "file.8c8ce076ca27823f.8C8CE076CA27823F!129/picture?type=thumbnail", + file_output: file + }).then( + function (response) { + document.getElementById("infoLabel").innerText = "Downloaded file."; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoLabel").innerText = + "Error calling API: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoLabel").innerText = + "Error signing in: " + responseFailed.error.message; + } + ); + } + else { + document.getElementById("infoLabel").innerText = "Cannot download file."; + } + }, + function (fileFailed) { + document.getElementById("infoLabel").innerText = "Cannot download file."; + } + ); +} + +function setupSavePicker() { + var savepicker = new Windows.Storage.Pickers.FileSavePicker(); + savepicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary; + // XXX: Type hack for other typings. Apparently string[] isn't an IVector. + (savepicker.fileTypeChoices).insert("Picture", [".jpg"]); + return savepicker; +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/jj219387.aspx + */ +function uploadFile_onClick() { + var picker = setupOpenPicker(); + var filePickOp = picker.pickSingleFileAsync().then( + function (file) { + WL.login({ + scope: "wl.skydrive_update" + }).then( + function (response) { + WL.backgroundUpload({ + path: "me/skydrive", + file_name: file.name, + file_input: file, + overwrite: "rename" + }).then( + function (response) { + document.getElementById("infoLabel").innerText = "Uploaded file."; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoLabel").innerText = + "Error calling API: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoLabel").innerText = + "Error signing in: " + responseFailed.error.message; + } + ); + }, + function (fileFailed) { + document.getElementById("infoLabel").innerText = "Cannot upload file."; + } + ); +} + +function setupOpenPicker() { + var openpicker = new Windows.Storage.Pickers.FileOpenPicker(); + openpicker.fileTypeFilter.replaceAll(["*"]); + return openpicker; +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550839.aspx + */ +function downloadFile() { + WL.login({ + scope: "wl.skydrive" + }).then( + function (response) { + WL.download({ + path: "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/content" + }).then( + function (response) { + // Will not be called for web apps. + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error downloading file: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error signing in: " + responseFailed.error.message; + } + ); +} + +WL.Event.subscribe("auth.login", function () { }); +WL.Event.unsubscribe("auth.logout"); + +/** + * From: http://msdn.microsoft.com/en-us/library/live/jj219389.aspx + */ +function uploadFile_fileDialog() { + WL.fileDialog({ + mode: "save" + }).then( + function (response) { + WL.upload({ + path: response.data.folders[0].id, + element: "file", + overwrite: "rename" + }).then( + function (response) { + document.getElementById("info").innerText = + "File uploaded."; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error uploading file: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error getting folder info: " + responseFailed.error.message; + } + ); +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550842.aspx + */ +function loginStatus() { + WL.getLoginStatus(function (response) { alert("Your status is: " + response.status) }); +} + +/** + * From http://msdn.microsoft.com/en-us/library/live/hh550843.aspx + */ +function onSessionChange() { + var session = WL.getSession(); + if (session) { + document.getElementById("infoLabel").innerText = + "Something about the session changed."; + } + else { + document.getElementById("infoLabel").innerText = + "Signed out or session error."; + } +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550844.aspx + */ +WL.init({ + client_id: "APP_CLIENT_ID", + redirect_uri: "REDIRECT_URL", + scope: "wl.signin", + response_type: "token" +}); +WL.init({ scope: "wl.signin" }); + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550845.aspx + */ +function streamlineAccountReg_onClick() { + WL.login({ + scope: ["wl.signin", "wl.basic", "wl.birthday", "wl.emails"] + }).then( + function (response) { + WL.api({ + path: "me", + method: "GET" + }).then( + function (response) { + document.getElementById("first_name").innerText = response.first_name; + document.getElementById("last_name").innerText = response.last_name; + document.getElementById("email").innerText = response.emails.preferred; + document.getElementById("gender").innerText = response.gender; + document.getElementById("birthday").innerText = + response.birth_month + " " + response.birth_day + " " + response.birth_year; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("infoArea").innerText = + "Error calling API: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IJSError) { + document.getElementById("infoArea").innerText = + "Error signing in: " + responseFailed.error_description; + } + ); +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550846.aspx + */ +function signUserOut() { + WL.logout(); +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550847.aspx + */ +var signInProps: Microsoft.Live.ISignInProperties = { + name: "signin", + element: "signin" +}; +WL.ui(signInProps); +var skyDriveProps: Microsoft.Live.ISkyDrivePickerProperies = { + name: "skydrivepicker", + element: "uploadFile_div", + mode: "save", + onselected: onUploadFileCompleted, + onerror: onUploadFileError +}; +WL.ui(skyDriveProps); + +function onUploadFileCompleted(response: Microsoft.Live.IFilePickerResult) { + WL.upload({ + path: response.data.folders[0].id, + element: "file", + overwrite: "rename" + }).then( + function (response) { + document.getElementById("info").innerText = + "File uploaded."; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error uploading file: " + responseFailed.error.message; + } + ); +}; + +function onUploadFileError(response: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error getting folder info: " + response.error.message; +} +skyDriveProps = { + name: "skydrivepicker", + element: "downloadFile_div", + mode: "open", + select: "multi", + onselected: onDownloadFileCompleted, + onerror: onDownloadFileError +}; +WL.ui(skyDriveProps); + +function onDownloadFileCompleted(response: Microsoft.Live.IFilePickerResult) { + var msg = "", folder, file; + // For each folder selected... + if (response.data.folders.length > 0) { + for (folder = 0; folder < response.data.folders.length; folder++) { + // Use folder IDs to iterate through child folders and files as needed. + msg += "\n" + response.data.folders[folder].id; + } + } + // For each file selected... + if (response.data.files.length > 0) { + for (file = 0; file < response.data.files.length; file++) { + // Use file IDs to iterate through files as needed. + msg += "\n" + response.data.files[file].id; + } + } + document.getElementById("info").innerText = + "Selected folders/files:" + msg; +}; + +function onDownloadFileError(responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error getting folder/file info: " + responseFailed.error.message; +} + +/** + * From: http://msdn.microsoft.com/en-us/library/live/hh550848.aspx + */ +function uploadFile() { + WL.login({ + scope: "wl.skydrive_update" + }).then( + function (response) { + WL.upload({ + path: "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!170", + element: "file", + overwrite: "rename" + }).then( + function (response) { + document.getElementById("info").innerText = + "File uploaded."; + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error uploading file: " + responseFailed.error.message; + } + ); + }, + function (responseFailed: Microsoft.Live.IError) { + document.getElementById("info").innerText = + "Error signing in: " + responseFailed.error.message; + } + ); +} + + +//#region From: http://msdn.microsoft.com/en-us/library/live/hh243648.aspx +/** + * This region contains REST object examples, and verifies that they pass + * type checking. + */ +var albumCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "album.8c8ce076ca27823f.8C8CE076CA27823F!126", + "from": { + "name": "Roberto Tamburello", + "id": "8c8ce076ca27823f" + }, + "name": "My Sample Album 1", + "description": "", + "parent_id": "folder.de57f4126ed7e411", + "upload_location": "https://apis.live.net/v5.0/folder.de57f4126ed7e411.DE57F4126ED7E411!126/files/", + "is_embeddable": true, + "count": 4, + "link": "https://cid-8c8ce076ca27823f.skydrive.live.com/redir.aspx?page\u003dself\u0026resid\u003d8C8CE076CA27823F!126\u0026type\u003d5", + "type": "album", + "shared_with": { + "access": "Everyone (public)" + }, + "created_time": "2011-04-21T23:19:47+0000", + "updated_time": "2011-04-22T19:18:12+0000", + // XXX: The API example documentation missed this property, but it has been wrong in the past... + "client_updated_time": "2011-04-22T19:18:12+0000", + } + ] +}; +var newAlbum: Microsoft.Live.INewAlbum = { + "name": "Vacation 2011", + "description": "Photos from our fun vacation." +}; +var audioCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!144", + "from": { + "name": "Stig Struve-Christensen", + "id": "a6b2a7e8f2515e5e" + }, + "name": "SampleAudio.mp3", + "description": null, + "parent_id": "folder.a6b2a7e8f2515e5e", + "size": 8414449, + "upload_location": "https://apis.live.net/v5.0/file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!144/content/", + "comments_count": 0, + "comments_enabled": false, + "is_embeddable": false, + "source": "http://storage.live.com/s1p60U8Xs4UzIXTScrTioalE-ZaVFiDQBA15MS2BwcsuNjfG64Z2fw-DAjXnPuqC47YR40_xAoPD8aRGhtna9ZFZ9_oO4BTz4CWF973DTXMxc5U3TntcQ9qEA/SampleAudio.mp3:Binary", + "link": "https://skydrive.live.com/redir.aspx?cid\u003d22688711f5410e6c\u0026page\u003dview\u0026resid\u003d22688711F5410E6C!582\u0026parid\u003d22688711F5410E6C!581", + "type": "audio", + "title": "My Sample Audio", + "artist": "My Favorite Artist", + "album": "My Favorite Album", + "album_artist": "My Favorite Artist", + "genre": "Easy Listening", + "duration": 225000, + "picture": "https://storage.live.com/items/A6B2A7E8F2515E5E!144:MobileReady/SampleAudio.mp3?psid=1&ck=0&ex=720", + "shared_with": { + "access": "Just me" + }, + "created_time": "2012-09-23T22:00:57+0000", + "updated_time": "2012-09-03T22:00:57+0000" + } + ] +}; + +var newAudioResponse: Microsoft.Live.INewFileResponse = { + "id": "ID of the new audio", + "name": "The file's name and file extension", + "source": "URL where the audio can be downloaded from" +}; + +var newAudio: Microsoft.Live.INewAudio = { + "name": "SampleAudioChanged.wav", + "description": "Holiday Concert" +}; + +var calendarCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "calendar.42d4dbc866f94c83849c88c6eb9985bc", + "name": "Birthday calendar", + "description": "If you have birthdays listed for your contacts, they'll appear on this calendar. You can add more birthdays, but you can't add other types of events.", + "created_time": "2011-08-05T19:41:04+0000", + "updated_time": "2011-08-05T19:41:04+0000", + "from": { + "name": null, + "id": null + }, + "is_default": false, + "subscription_location": null, + "permissions": "read" + } + ] +}; + +var newCalendar: Microsoft.Live.INewCalendar = { + "name": "Summer Events", + "summary": "Things we are doing this summer." +}; + +var newCalendarSub: Microsoft.Live.INewCalendarSubscription = { + "name": "Soccer League", + "subscription_location": "ical.sharedcalendars.com/98754auv" +}; + +var commentCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "comment.22688711f5410e6c.22688711f0410e6c!818.22688711F5410E6C!979", + "from": { + "name": "Roberto Tamburello", + "id": "8c8ce076ca27823f" + }, + "message": "A lighthouse built on some rocks.", + "created_time": "2011-04-21T23:21:28+0000" + } + ] +}; + +var newContact: Microsoft.Live.INewContact = { + "first_name": "", + "last_name": "", + "emails": { + "preferred": "", + "personal": "", + "business": "", + "other": "" + }, + "work": [ + { + "employer": { + "name": "" + } + } + ] +}; + +var contactCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "contact.b4466224b2ca42798c3d4ea90c75aa56", + "first_name": "Henrik", + "last_name": "Jensen", + "name": "Henrik Jensen", + "is_friend": false, + "is_favorite": false, + "user_id": null, + "email_hashes": [ + "9ecdb19f4eb8e04304c5d1280368c42e85b6e4fe39f08b0c837ec592b905a620", + "fc05492f50da6488aa14dcf221d395bcb29a4e43b43b250d60c68df4f831cad3" + ], + "updated_time": "2011-04-22T00:11:13+0000", + "birth_day": 29, + "birth_month": 3 + + } + ] +}; + +var errorObj: Microsoft.Live.IError = { + "error": { + "code": "request_token_expired", + "message": "The provided access token has expired." + } +}; + +var event: Microsoft.Live.IEvent = { + "id": "event.611afb17fa9448f28cdb8277e8ffeb77.e9f015000d0249ce847c5306a25d7d75", + "name": "Global Project Risk Management Meeting", + "description": "Generate and assess risks for the project", + "calendar_id": "calendar.611afb17fa9448f28cdb8277e8ffeb77", + "from": { + "name": "William Flash", + "id": "de57f4126ed7e411" + }, + "start_time": "2011-04-20T01:00:00+0000", + "end_time": "2011-04-20T02:00:00+0000", + "location": "Building 81, Room 9981, 123 Anywhere St., Redmond WA 19599", + "is_all_day_event": false, + "is_recurrent": false, + "recurrence": null, + "reminder_time": null, + "availability": "busy", + "visibility": "public", + "created_time": "2011-03-14T23:01:31+0000", + "updated_time": "2011-04-19T20:23:03+0000" +}; + +var newEvent: Microsoft.Live.INewEvent = { + "name": "Global Project Risk Management Meeting", + "description": "Generate and assess risks for the project", + "start_time": "2011-04-20T01:00:00-07:00", + "end_time": "2011-04-20T02:00:00-07:00", + "location": "Building 81, Room 9981, 123 Anywhere St., Redmond WA 19599", + "is_all_day_event": false, + "availability": "busy", + "visibility": "public" +}; + +var eventResponse: Microsoft.Live.INewEventResponse = { + "name": "Global Project Risk Management Meeting", + "description": "Generate and assess risks for the project", + "start_time": "2011-04-20T01:00:00+0000", + "end_time": "2011-04-20T02:00:00+0000", + "location": "Building 81, Room 9981, 123 Anywhere St., Redmond WA 19599", + "is_all_day_event": false, + "is_recurrent": false, + "recurrence": null, + "reminder_time": null, + "availability": "busy", + "visibility": "public", + "updated_time": "2011-04-19T20:23:03+0000" +}; + +var file: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "file.22688711f5410e6c.22688711F5410E6C!942", + "from": { + "name": "William Flash", + "id": "22688711f5410e6c" + }, + "name": "Processing.docx", + "description": null, + "parent_id": "folder.22688711f5410e6c.22688711F5410E6C!479", + "size": 12692, + "upload_location": "https://apis.live.net/v5.0/file.22688711f5410e6c.22688711F5410E6C!942/content/", + "comments_count": 0, + "comments_enabled": true, + "is_embeddable": false, + "source": "http://storage.live.com/s1pEwo9qzyT4_BJZqMNm-aVzgLo-WRsQGzjzFsXjyREuQG5pDYr237vKz3i2pmqFuniYPzsuIZAOCUMB_gdfKCUpLpVcaAMXGrk4T7jOWenRniCv9vex7GWfSvy-XCVBVnU/Processing.docx:Binary", + "link": "https://skydrive-df.live.com/redir.aspx?cid\u003d22688711f5410e6c\u0026page\u003dview\u0026resid\u003d22688711F5410E6C!942\u0026parid\u003d22688711F5410E6C!479", + "type": "file", + "shared_with": { + "access": "Everyone (public)" + }, + "created_time": "2011-10-12T23:18:23+0000", + "updated_time": "2011-10-12T23:18:23+0000", + // XXX: Not specified in example. Could be a bug in documentation, or maybe these are optional fields. + "client_updated_time": "2011-10-12T23:18:23+0000", + "sort_by": null + } + ] +}; + +var fileDownload: Microsoft.Live.IFileDownloadLink = { + "location": "..." +}; + +var newFileResponse: Microsoft.Live.INewFileResponse = { + "id": "file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!184", + "name":"MyNewFile.txt", + "source": "http://storage.live.com/s1pasGKzgXFvuEQCbxGtOyIpboUVH1OCHoRzUJNDDwL0zVoidb0RRrNVk88hUrOEve5OMT7eCkuxPbop7dV9tMJQ-eE8SCQ28vFv9ZgPnDGwQMRm-0FeG3-KEY4HL9dQSw9/MyNewFile.txt:Binary,Default/MyNewFile.txt" +}; + +var folderCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "folder.8c8ce076ca27823f.8C8CE076CA27823F!142", + "from": { + "name": "Roberto Tamburello", + "id": "8c8ce076ca27823f" + }, + "name": "My Sample Folder in Album 1", + "description": "", + "parent_id": "folder.de57f4126ed7e411", + "upload_location": "https://apis.live.net/v5.0/folder.de57f4126ed7e411.DE57F4126ED7E411!126/files/", + "is_embeddable": true, + "count": 3, + "link": "https://cid-8c8ce076ca27823f.skydrive.live.com/redir.aspx?page\u003dself\u0026resid\u003d8C8CE076CA27823F!142\u0026parid\u003d8C8CE076CA27823F!126\u0026type\u003d5", + "type": "folder", + "shared_with": { + "access": "Just me" + }, + "created_time": "2011-04-22T00:36:30+0000", + "updated_time": "2011-04-22T19:18:12+0000", + // XXX: Omitted in the example. + "client_updated_time": "???", + "sort_by": "???" + } + ] +}; + +var newFolder: Microsoft.Live.INewFolder = { + "name": "Informative Spreadsheets", + "description": "A folder full of useful data visualizations." +}; + +var friendCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "d09ea18fafc39a0c", + "name": "Henrik Jensen" + } + ] +}; + +var permissionsCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "wl.basic": 1, + "wl.offline_access": 1, + "wl.signin": 1 + } + ] +}; + +var photoCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "file.de57f4126ed7e411.DE57F4126ED7E411!128", + "from": { + "name": "Nuno Bento", + "id": "de57f4126ed7e411" + }, + "name": "Maui-2012_0034.JPG", + "description": null, + "parent_id": "folder.de57f4126ed7e411.DE57F4126ED7E411!126", + "size": 561683, + "comments_count": 1, + "comments_enabled": true, + "tags_count": 0, + "tags_enabled": true, + "is_embeddable": true, + "picture": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:Thumbnail", + "source": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:HighRes", + "upload_location": "https://apis.live.net/v5.0/file.de57f4126ed7e411.DE57F4126ED7E411!128/content/", + "images": [ + { + "height": 450, + "width": 600, + "source": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:WebReady", + "type": "normal" + }, { + "height": 132, + "width": 176, + "source": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:MobileReady", + "type": "album" + }, { + "height": 72, + "width": 96, + "source": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:Thumbnail", + "type": "thumbnail" + }, { + "height": 1200, + "width": 1600, + "source": "http://storage.live.com/s1pKk5vzd-gdPanbzKYhB0nQGn8wGq5DSgqvrgIHU1NTXA4e2-spGkAhQjW1d9pcgKAGLB4NsEsSvDoREmdx5w-JiFrinEJJuEoz08Ws_IFupkX2bPSvy5qmths9ijwvDrXi1OBCWk9GW9Kt-qNNOAA9g/Maui09_0034.JPG:HighRes", + "type": "full" + } + ], + "link": "https://skydrive.live.com/redir.aspx?cid\u003dde57f4126ed7e411\u0026page\u003dview\u0026resid\u003dDE57F4126ED7E411!128\u0026parid\u003dDE57F4126ED7E411!126", + "when_taken": "2008-03-24T23:41:53+0000", + "height": 1200, + "width": 1600, + "type": "photo", + "location": { + "latitude": 47.65316, + "longitude": -122.135911, + "altitude": 43 + }, + "camera_make": "MyManufacturer", + "camera_model": "MyModel", + "focal_ratio": 2.8, + "focal_length": 3.85, + "exposure_numerator": 1, + "exposure_denominator": 15, + "shared_with": { + "access": "Everyone (public)" + }, + "created_time": "2012-12-03T18:14:03+0000", + "updated_time": "2012-12-03T18:31:01+0000" + } + ] +}; + +var tag: Microsoft.Live.ITag = { + "id": "tag.22688711f5410e6c.22688711f5410e6c!767.PRaXZrdHI1uYGQYi9CU0StrzHak", + "user": { + "name": "Roberto Tamburello", + "id": "8c8ce076ca27823f" + }, + "x": 43.8986, + "y": 54.4138, + "created_time": "2011-04-22T01:17:00+0000" +}; + +var user: Microsoft.Live.IUser = { + "id": "8c8ce076ca27823f", + "name": "Roberto Tamburello", + "first_name": "Roberto", + "last_name": "Tamburello", + // XXX: Not in the REST API example, but is included in the WL.ui example. + "gender": null, + "link": "http://cid-8c8ce076ca27823f.profile.live.com/", + "birth_day": 20, + "birth_month": 4, + "birth_year": 2010, + "work": [ + { + "employer": { + "name": "Microsoft Corporation" + }, + "position": { + "name": "Software Development Engineer" + } + } + ], + "emails": { + "preferred": "Roberto@contoso.com", + "account": "Roberto@contoso.com", + "personal": "Roberto@fabrikam.com", + "business": "Robert@adatum.com", + "other": "Roberto@adventure-works.com" + }, + "addresses": { + "personal": { + "street": "123 Main St.", + "street_2": "Apt. A", + "city": "Redmond", + "state": "WA", + "postal_code": "12990", + "region": "United States" + }, + "business": { + "street": "456 Anywhere St.", + "street_2": "Suite 1", + "city": "Redmond", + "state": "WA", + "postal_code": "12399", + "region": "United States" + } + }, + "phones": { + "personal": "(555) 555-1212", + "business": "(555) 111-1212", + "mobile": null + }, + "locale": "en_US", + "updated_time": "2011-04-21T23:55:34+0000" +}; + +var videoCollection: Microsoft.Live.IObjectCollection = { + "data": [ + { + "id": "file.de57f4126ed7e411.DE57F4126ED7E411!135", + "from": { + "name": "Nuno Bento", + "id": "de57f4126ed7e411" + }, + "name": "Wildlife.wmv", + "description": null, + "parent_id": "folder.de57f4126ed7e411.DE57F4126ED7E411!126", + "size": 26246026, + "comments_count": 0, + "comments_enabled": true, + "tags_count": 0, + "tags_enabled": true, + "is_embeddable": true, + "picture": "http://storage.live.com/s1pKk5vzd-gdPaJ5Q1MKN34itsyRlUkAYzD_zsr0Dg-5r4bH8Qo8XRgsunA0M-V4G-XPpu1spowx4xwfjCuDcWQVa7aWld2WCdfeWjBK_coPqaQqzoE26BJP3OZAITB5i_DRPK8jK3ZLilSbNJd-onrOA/Wildlife.wmv:Thumbnail", + "source": "http://storage.live.com/s1pKk5vzd-gdPaJ5Q1MKN34itsyRlUkAYzD_zsr0Dg-5r4bH8Qo8XRgsunA0M-V4G-XPpu1spowx4xwfjCuDcWQVa7aWld2WCdfeWjBK_coPqaQqzoE26BJP3OZAITB5i_DRPK8jK3ZLilSbNJd-onrOA/Wildlife.wmv:VideoMain", + "upload_location": "https://apis.live.net/v5.0/file.de57f4126ed7e411.DE57F4126ED7E411!135/content/", + "link": "https://skydrive.live.com/redir.aspx?cid\u003dde57f4126ed7e411\u0026page\u003dview\u0026resid\u003dDE57F4126ED7E411!135\u0026parid\u003dDE57F4126ED7E411!126", + "height": 720, + "width": 1280, + "duration": 30093, + "bitrate": 5942130, + "type": "video", + "shared_with": { + "access": "Everyone (public)" + }, + "created_time": "2011-08-23T23:41:18+0000", + "updated_time": "2011-08-23T23:41:32+0000" + } + ] +}; +//#endregion From: http://msdn.microsoft.com/en-us/library/live/hh243648.aspx + +//#region From http://isdk.dev.live.com/dev/isdk/Default.aspx +/** + * The following code snippets were lifted from the Interactive Live SDK + * sandbox. We only include snippets that exercise portions of the API not + * already exercised above. + */ + +function log(message) { + var child = document.createTextNode(message); + var parent = document.getElementById('JsOutputDiv') || document.body; + parent.appendChild(child); + parent.appendChild(document.createElement("br")); +} + +function openFromSkyDrive() { + WL.fileDialog({ + mode: 'open', + select: 'single' + }).then( + function (response) { + log("The following file is being downloaded:"); + log(""); + + var files = response.data.files; + for (var i = 0; i < files.length; i++) { + var file = files[i]; + log(file.name); + WL.download({ "path": file.id + "/content" }); + } + }, + function (errorResponse) { + log("WL.fileDialog errorResponse = " + JSON.stringify(errorResponse)); + } + ); +} + +function saveToSkyDrive() { + WL.fileDialog({ mode: 'save' }).then( + function (response) { + var folder = response.data.folders[0]; + + WL.upload({ + path: folder.id, + element: 'save-to-skydrive-file-input', + overwrite: 'rename' + }).then( + function (response) { + log("You saved to " + response.source + ". " + + "Below is the result of the upload."); + log(""); + log(JSON.stringify(response)); + }, + function (errorResponse) { + log("WL.upload errorResponse = " + JSON.stringify(errorResponse)); + }, + function (progress) { + // progress events for the upload are raised here + } + ); + }, function (errorResponse) { + log("WL.fileDialog errorResponse = " + JSON.stringify(errorResponse)); + } + ); +} + +function getFiles() { + var files_path = "/me/skydrive/files"; + WL.api>({ path: files_path, method: "GET" }).then( + onGetFilesComplete, + function (response) { + log("Cannot get files and folders: " + + JSON.stringify(response.error).replace(/,/g, ",\n")); + } + ); +} + +// should have an interface that captures the fact that it only has type. +function onGetFilesComplete(response: Microsoft.Live.IObjectCollection) { + var items = response.data; + var foundFolder = 0; + for (var i = 0; i < items.length; i++) { + if (items[i].type === "folder") { + log("Found a folder with the following information: " + + JSON.stringify(items[i]).replace(/,/g, ",\n")); + foundFolder = 1; + break; + } + } + + if (foundFolder == 0) { + log("Unable to find any folders"); + } +} + +function registerUser() { + WL.api({ path: "/me", method: "GET" }).then( + function (response) { + fillRegistrationForm(response); + }, + function (response) { + log("API call failed: " + JSON.stringify(response.error).replace(/,/g, "\n")); + } + ); +} + +function fillRegistrationForm(user: Microsoft.Live.IUser) { + // NOTE: Assign these values to your form elements to streamline registration. + log("First name: " + user.first_name); + log("Last name: " + user.last_name); + log("Preferred email: " + user.emails.preferred); + log("Gender: " + user.gender); + log("Birthday: " + user.birth_month + "/" + user.birth_day + "/" + user.birth_year); +} + +function showUserContactInfo() { + WL.api({ path: "/me", method: "GET" }).then( + function (response) { + log("Addresses: " + JSON.stringify(response.addresses).replace(/,/g, "\n")); + log("Phone Numbers: " + JSON.stringify(response.phones).replace(/,/g, "\n")); + log("Email Addresses: " + JSON.stringify(response.emails).replace(/,/g, "\n")); + }, + function (response) { + log("API call failed: " + JSON.stringify(response.error).replace(/,/g, "\n")); + } + ); +} + +function enablePurchase(response) { + var date = new Date(); + var year = date.getFullYear(); + + WL.api({ path: "/me", method: "GET" }).then( + function (response) { + var user = response; + if (year - user.birth_year >= 18) { + log("Purchase enabled."); + } else { + log("Purchase disabled. You are only " + user.birth_year + " year(s) old."); + } + }, + function (response) { + log("API call failed: " + JSON.stringify(response.error).replace(/,/g, "\n")); + } + ); +} + +function createContact() { + var contact: Microsoft.Live.INewContact = { + first_name: "William", + last_name: "Flash" + }; + WL.api({ + path: "/me/contacts", + method: "POST", + body: contact + }).then( + function (response) { + log(JSON.stringify(response).replace(/,/g, ",\n")); + }, + function (response) { + log("Cannot create contact: " + + JSON.stringify(response.error).replace(/,/g, ",\n")); + } + ); +} + +function createEvent() { + var startTime = new Date(); + var endTime = new Date(startTime.getTime() + (60 * 60 * 1000)); + + log("Start time: " + startTime); + log("End time: " + endTime); + var newEvent: Microsoft.Live.INewEvent = { + name: "Family Dinner", + description: "Dinner with Cynthia's family", + start_time: startTime, + end_time: endTime, + location: "Coho Vineyard and Winery, 123 Main St., Redmond WA 98052", + is_all_day_event: false, + availability: "busy", + visibility: "public" + }; + + WL.api({ + path: "/me/events", + method: "POST", + body: newEvent + }).then( + function (response) { + log("Successfully created event. Response: " + + JSON.stringify(response).replace(/,/g, "\n")); + }, + function (response) { + log("Could not create event: " + + JSON.stringify(response.error).replace(/,/g, "\n")); + } + ); +} +//#endregion From http://isdk.dev.live.com/dev/isdk/Default.aspx diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index cc2de59be..0805e832a 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -109,7 +109,7 @@ declare module "mongodb" { // Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html // Last update: doc. version 1.3.13 (28.08.2013) export class ObjectID { - constructor (s: string); + constructor (s?: string); // Returns the ObjectID id as a 24 byte hex string representation public toHexString() : string; diff --git a/slickgrid/SlickGrid.d.ts b/slickgrid/SlickGrid.d.ts index 63fd76c97..b7810f467 100644 --- a/slickgrid/SlickGrid.d.ts +++ b/slickgrid/SlickGrid.d.ts @@ -475,7 +475,7 @@ declare module Slick { /** * If set to true, whenever this column is resized, the entire table view will rerender. **/ - rerenderOnReize?: boolean; + rerenderOnResize?: boolean; /** * If false, column can no longer be resized.