From 31feeb55656bd1f37d385097b0e8236d1eb091c1 Mon Sep 17 00:00:00 2001 From: Natan Vivo Date: Thu, 17 Jan 2013 13:05:31 -0200 Subject: [PATCH 1/7] Initial definitions for 2 new jquery plugins. --- jquery.contextMenu/jquery.contextMenu.d.ts | 33 +++++++++++++++++++ .../jquery.simplePagination.d.ts | 27 +++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 jquery.contextMenu/jquery.contextMenu.d.ts create mode 100644 jquery.simplePagination/jquery.simplePagination.d.ts diff --git a/jquery.contextMenu/jquery.contextMenu.d.ts b/jquery.contextMenu/jquery.contextMenu.d.ts new file mode 100644 index 000000000..926c4e1b6 --- /dev/null +++ b/jquery.contextMenu/jquery.contextMenu.d.ts @@ -0,0 +1,33 @@ +// Type definitions for jQuery contextMenu 1.5.25 +// Project: http://medialize.github.com/jQuery-contextMenu/ +// Definitions by: Natan Vivo +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface JQueryContextMenuOptions { + selector: string; + appendTo?: string; + trigger?: string; + autoHide?: bool; + delay?: number; + determinePosition?: (menu) => void; + position?: (opt, x, y) => void; + positionSubmenu?: (menu) => void; + zIndex?: number; + animation?: { + duration?: number; + show?: string; + hide?: string; + }; + events?: { + show?: () => void; + hide?: () => void; + }; + callback?: (...args: any[]) => any; + items: any; +}; + +interface JQueryStatic { + contextMenu(options?: JQueryContextMenuOptions): JQuery; +} diff --git a/jquery.simplePagination/jquery.simplePagination.d.ts b/jquery.simplePagination/jquery.simplePagination.d.ts new file mode 100644 index 000000000..3ca1d3d88 --- /dev/null +++ b/jquery.simplePagination/jquery.simplePagination.d.ts @@ -0,0 +1,27 @@ +// Type definitions for jQuery simplePagination.js v1.4 +// Project: https://github.com/flaviusmatis/simplePagination.js +// Definitions by: Natan Vivo +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface SimplePaginationOptions { + items?: number; + itemsOnPage?: number; + pages?: number; + displayedPages?: number; + edges?: number; + currentPage?: number; + hrefTextPrefix?: string; + hrefTextSuffix?: string; + prevText?: string; + nextText?: string; + cssStyle?: string; + selectOnClick?: bool; + onPageClick?: (interger) => void; + onInit?: () => void; +}; + +interface JQuery { + pagination(options?: SimplePaginationOptions): JQuery; +} From cadfdb95a3e91413b209ee0e07ec9a94209149c1 Mon Sep 17 00:00:00 2001 From: Ken Smith Date: Thu, 17 Jan 2013 08:36:00 -0800 Subject: [PATCH 2/7] A few minor updates to the Sammy definitions. Haven't tried to fix the Sammy tests yet. --- sammyjs/sammyjs.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sammyjs/sammyjs.d.ts b/sammyjs/sammyjs.d.ts index 6d12f577f..f8b5ae147 100644 --- a/sammyjs/sammyjs.d.ts +++ b/sammyjs/sammyjs.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// +/// module Sammy { export function (): Sammy.Application; @@ -101,7 +101,7 @@ module Sammy { route(verb: string, path: string, callback: Function): Application; route(verb: string, path: RegExp, callback: Function): Application; run(start_url?: string): Application; - runRoute(verb: string, path: string, params: any, target: any): any; + runRoute(verb: string, path?: string, params?: any, target?: any): any; setLocation(new_location: string): string; setLocationProxy(new_proxy: DataLocationProxy): void; swap(content: any, callback: Function): string; @@ -136,6 +136,7 @@ module Sammy { loadPartials(partials); notFound(): any; partial(location: string, data: any, callback: Function, partials): RenderContext; + params: Object; redirect(...params: any[]): void; render(location: string, data: any, callback: Function, partials): RenderContext; renderEach(location: any, name?: string, data?: any, callback?: Function): RenderContext; From 4ce31ba6f101d00a4b568bdd26d2cb7cb274ce73 Mon Sep 17 00:00:00 2001 From: Ken Smith Date: Thu, 17 Jan 2013 08:54:54 -0800 Subject: [PATCH 3/7] Added first pass at WebRTC definitions. --- webrtc/MediaStream.d.ts | 136 +++++++++++++++++++++ webrtc/RTCPeerConnection.d.ts | 221 ++++++++++++++++++++++++++++++++++ webrtc/readme.md | 14 +++ 3 files changed, 371 insertions(+) create mode 100644 webrtc/MediaStream.d.ts create mode 100644 webrtc/RTCPeerConnection.d.ts create mode 100644 webrtc/readme.md diff --git a/webrtc/MediaStream.d.ts b/webrtc/MediaStream.d.ts new file mode 100644 index 000000000..7d6b3759b --- /dev/null +++ b/webrtc/MediaStream.d.ts @@ -0,0 +1,136 @@ +// Type definitions take from http://dev.w3.org/2011/webrtc/editor/getusermedia.html + +interface MediaStreamConstraints { + audio: bool; + video: bool; +} +declare var MediaStreamConstraints: { + prototype: MediaStreamConstraints; + new (): MediaStreamConstraints; +} + +interface MediaTrackConstraints { + mandatory: MediaTrackConstraintSet; + optional: MediaTrackConstraint[]; +} +declare var MediaTrackConstraints: { + prototype: MediaTrackConstraints; + new (): MediaTrackConstraints; +} + +// ks - Not defined in the source doc. +interface MediaTrackConstraintSet { +} +declare var MediaTrackConstraintSet: { + prototype: MediaTrackConstraintSet; + new (): MediaTrackConstraintSet; +} + +// ks - Not defined in the source doc. +interface MediaTrackConstraint { +} +declare var MediaTrackConstraint: { + prototype: MediaTrackConstraint; + new (): MediaTrackConstraints; +} + +interface Navigator { + getUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void ); + webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void ); +} + +interface EventHandler { (event: Event): void; } + +interface NavigatorUserMediaSuccessCallback { (stream: LocalMediaStream): void; } + +interface NavigatorUserMediaError { + PERMISSION_DENIED: number; // = 1; + code: number; +} +declare var NavigatorUserMediaError: { + prototype: NavigatorUserMediaError; + new (): NavigatorUserMediaError; + PERMISSION_DENIED: number; // = 1; +} + +interface NavigatorUserMediaErrorCallback { (error: NavigatorUserMediaError): void; } + +interface MediaStreamTrackList { + length: number; + item: MediaStreamTrack; + add(track: MediaStreamTrack): void; + remove(track: MediaStreamTrack): void; + onaddtrack: (event: Event) => void; + onremovetrack: (event: Event) => void; +} +declare var MediaStreamTrackList: { + prototype: MediaStreamTrackList; + new (): MediaStreamTrackList; +} +declare var webkitMediaStreamTrackList: { + prototype: MediaStreamTrackList; + new (): MediaStreamTrackList; +} + +interface MediaStream { + label: string; + audioTracks: MediaStreamTrackList; + videoTracks: MediaStreamTrackList; + ended: bool; + onended: (event: Event) => void; +} +declare var MediaStream: { + prototype: MediaStream; + new (): MediaStream; + new (trackContainers: MediaStream[]): MediaStream; + new (trackContainers: MediaStreamTrackList[]): MediaStream; + new (trackContainers: MediaStreamTrack[]): MediaStream; +} +declare var webkitMediaStream: { + prototype: MediaStream; + new (): MediaStream; + new (trackContainers: MediaStream[]): MediaStream; + new (trackContainers: MediaStreamTrackList[]): MediaStream; + new (trackContainers: MediaStreamTrack[]): MediaStream; +} + +interface LocalMediaStream extends MediaStream { + stop(): void; +} + +interface MediaStreamTrack { + kind: string; + label: string; + enabled: bool; + LIVE: number; // = 0; + MUTED: number; // = 1; + ENDED: number; // = 2; + readyState: number; + onmute: (event: Event) => void; + onunmute: (event: Event) => void; + onended: (event: Event) => void; +} +var MediaStramTrack: { + prototype: MediaStreamTrack; + new (): MediaStreamTrack; + LIVE: number; // = 0; + MUTED: number; // = 1; + ENDED: number; // = 2; +} + +interface URL { + createObjectURL(stream: MediaStream): string; +} +var URL: { + prototype: MediaStreamTrack; + new (): URL; + createObjectURL(stream: MediaStream): string; +} + +interface WebkitURL extends URL { +} +var webkitURL: { + prototype: WebkitURL; + new (): URL; + createObjectURL(stream: MediaStream): string; +} diff --git a/webrtc/RTCPeerConnection.d.ts b/webrtc/RTCPeerConnection.d.ts new file mode 100644 index 000000000..7276b60aa --- /dev/null +++ b/webrtc/RTCPeerConnection.d.ts @@ -0,0 +1,221 @@ +/// + +// These are TypeScript definitions to support static typing in TypeScript when interacting with WebRtc. +// Definitions taken from http://dev.w3.org/2011/webrtc/editor/webrtc.html + +interface RTCConfiguration { + iceServers: RTCIceServer[]; +} +var RTCConfiguration: { + prototype: RTCConfiguration; + new (): RTCConfiguration; +} + +interface RTCIceServer { + url: string; + credential?: string; +} +var RTCIceServer: { + prototype: RTCIceServer; + new (): RTCIceServer; +} + +interface webkitRTCPeerConnection extends RTCPeerConnection { +} +var webkitRTCPeerConnection: { + prototype: webkitRTCPeerConnection; + new (settings: RTCPeerConnectionConfig, constraints?:MediaConstraints): webkitRTCPeerConnection; +} + +interface IceState { +} +var IceState: { + prototype: IceState; + new (): IceState; +} + +// ks 12/20/12 - There's more here that doesn't seem to be documented very well yet. +interface MediaConstraints { + mandatory: MediaOfferConstraints; +} + +interface MediaOfferConstraints { + OfferToReceiveAudio: bool; + OfferToReceiveVideo: bool; +} + +interface RTCSessionDescription { + type?: RTCSdpType; + sdp?: string; +} +var RTCSessionDescription: { + prototype: RTCSessionDescription; + new (descriptionInitDict?: RTCSessionDescriptionInit): RTCSessionDescription; +} + +interface RTCSessionDescriptionInit { + type: RTCSdpType; + sdp: string; +} +var RTCSessionDescriptionInit: { + prototype: RTCSessionDescriptionInit; + new (): RTCSessionDescriptionInit; +} + +interface SdpType { +} + +interface RTCPeerState { +} + +interface RTCDataChannelInit { + reliable: bool; +} + +enum RTCSdpType { + offer, + pranswer, + answer +} + +enum RTCDataChannelState { + connecting, + open, + closing, + closed +} + +interface RTCDataChannel extends EventTarget { + label: string; + reliable: bool; + readyState: RTCDataChannelState; + bufferedAmount: number; + onopen: (event: Event)=> void; + onerror: (event: Event)=> void; + onclose: (event: Event)=> void; + close(): void; + onmessage: (event: Event)=> void; + binaryType: string; + send(data: string); + send(data: ArrayBuffer); + send(data: Blob); +} +declare var RTCDataChannel: { + prototype: RTCDataChannel; + new (): RTCDataChannel; +} + +interface RTCDataChannelEvent extends Event { + constructor (eventInitDict: RTCDataChannelEventInit); + channel: RTCDataChannel; +} +var RTCDataChannelEvent: { + prototype: RTCDataChannelEvent; + new (eventInitDict: RTCDataChannelEventInit); +} + +interface RTCIceCandidateEvent extends Event{ + candidate: RTCIceCandidate; +} + +interface RTCMediaStreamEvent extends Event { + stream: MediaStream; +} + +interface EventInit { +} + +interface RTCDataChannelEventInit extends EventInit { + channel: RTCDataChannel; +} + +interface RTCVoidCallback { + (): void; +} +interface RTCSessionDescriptionCallback { + (sdp: RTCSessionDescription): void; +} +interface RTCPeerConnectionErrorCallback { + (errorInformation: string): void; +} + +// This should be an enum +interface RTCGatheringState { + string; +} + +// This should be an enum +interface RTCIceState { + string; +} + +interface RTCPeerConnection { + createOffer(successCallback: RTCSessionDescriptionCallback, failureCallback?: RTCPeerConnectionErrorCallback, constraints?: MediaConstraints): void; + createAnswer(successCallback: RTCSessionDescriptionCallback, failureCallback?: RTCPeerConnectionErrorCallback, constraints?: MediaConstraints): void; + setLocalDescription(description: RTCSessionDescription, successCallback?: RTCVoidCallback, failureCallback?: RTCPeerConnectionErrorCallback): void; + localDescription: RTCSessionDescription; + setRemoteDescription(description: RTCSessionDescription, successCallback?: RTCVoidCallback, failureCallback?: RTCPeerConnectionErrorCallback): void; + remoteDescription: RTCSessionDescription; + readyState: RTCPeerState; + updateIce(configuration?: RTCConfiguration, constraints?: MediaConstraints): void; + addIceCandidate(candidate: RTCIceCandidate): void; + iceGatheringState: RTCGatheringState; + iceState: RTCIceState; + localStreams: MediaStream[]; + remoteStreams: MediaStream[]; + createDataChannel(label?: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel; + ondatachannel: (event: Event)=> void; + addStream(stream: MediaStream, constraints?: MediaConstraints): void; + removeStream(stream: MediaStream): void; + close(): void; + onnegotiationneeded: (event: Event)=> void; + onconnecting: (event: Event)=> void; + onopen: (event: Event)=> void; + onaddstream: (event: RTCMediaStreamEvent)=> void; + onremovestream: (event: RTCMediaStreamEvent)=> void; + onstatechange: (event: Event)=> void; + onicechange: (event: Event)=> void; + onicecandidate: (event: RTCIceCandidateEvent)=> void; + onidentityresult: (event: Event)=> void; +} +var RTCPeerConnection: { + prototype: RTCPeerConnection; + new (configuration: RTCConfiguration, constraints?: MediaConstraints): RTCPeerConnection; +} + +interface RTCIceCandidate { + candidate?: string; + sdpMid?: string; + sdpMLineIndex?: number; +} +var RTCIceCandidate: { + prototype: RTCIceCandidate; + new (candidateInitDict?: RTCIceCandidate); +} + +interface RTCIceCandidateInit { + candidate: string; + sdpMid: string; + sdpMLineIndex: number; +} +var RTCIceCandidateInit:{ + prototype: RTCIceCandidateInit; + new (): RTCIceCandidateInit; +} + +interface PeerConnectionIceEvent { + peer: RTCPeerConnection; + candidate: RTCIceCandidate; +} +var PeerConnectionIceEvent: { + prototype: PeerConnectionIceEvent; + new (): PeerConnectionIceEvent; +} + +interface RTCPeerConnectionConfig { + iceServers: RTCIceServer[]; +} +var RTCPeerConnectionConfig: { + prototype: RTCPeerConnectionConfig; + new (): RTCPeerConnectionConfig; +} diff --git a/webrtc/readme.md b/webrtc/readme.md new file mode 100644 index 000000000..1cc42b2d7 --- /dev/null +++ b/webrtc/readme.md @@ -0,0 +1,14 @@ +# WebRTC Definition Notes + +## The WebRTC specification + +The WebRTC specification is currently a work in progress, but it has been implemented at a basic level in recent versions of Chrome, Opera and (to a lesser extent) Firefox. +The latest version of the specification can be found at http://dev.w3.org/2011/webrtc/editor/webrtc.html. + +This particular set of definitions has been annotated with the vendor-specific prefixes for Chrome (e.g., `webitkit`), +but anyone who wants, feel free to add the Mozilla-specific prefixes. + +### Adding the reference to your project + + /// + /// \ No newline at end of file From 779a0a075e8f6dc7473d2a96708e5c98f5fd7506 Mon Sep 17 00:00:00 2001 From: Ken Smith Date: Thu, 17 Jan 2013 09:48:27 -0800 Subject: [PATCH 4/7] Added basic tests. --- webrtc/MediaStream-tests.ts | 32 +++++++++++++++++++ webrtc/MediaStream.d.ts | 4 +-- webrtc/RTCPeerConnection-tests.ts | 51 +++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 webrtc/MediaStream-tests.ts create mode 100644 webrtc/RTCPeerConnection-tests.ts diff --git a/webrtc/MediaStream-tests.ts b/webrtc/MediaStream-tests.ts new file mode 100644 index 000000000..290e2ff3c --- /dev/null +++ b/webrtc/MediaStream-tests.ts @@ -0,0 +1,32 @@ +/// +var mediaStreamConstraints: MediaStreamConstraints = { audio: true, video: true }; + +var mediaTrackConstraintSet: MediaTrackConstraintSet = {}; +var mediaTrackConstraintArray: MediaTrackConstraint[] = []; +var mediaTrackConstraints: MediaTrackConstraints = { mandatory: mediaTrackConstraintSet, optional: mediaTrackConstraintArray } + +navigator.getUserMedia(mediaStreamConstraints, + stream => { + console.log('label:' + stream.label); + console.log('ended:' + stream.ended); + stream.onended = event => console.log('Stream ended'); + var objectUrl = URL.createObjectURL(stream); + var wkObjectUrl = webkitURL.createObjectURL(stream); + }, + error => { + console.log('Error message: ' + error.message); + console.log('Error name: ' + error.name); + }); + +navigator.webkitGetUserMedia(mediaStreamConstraints, + stream => { + console.log('label:' + stream.label); + console.log('ended:' + stream.ended); + stream.onended = event => console.log('Stream ended'); + var objectUrl = URL.createObjectURL(stream); + var wkObjectUrl = webkitURL.createObjectURL(stream); + }, + error => { + console.log('Error message: ' + error.message); + console.log('Error name: ' + error.name); + }); \ No newline at end of file diff --git a/webrtc/MediaStream.d.ts b/webrtc/MediaStream.d.ts index 7d6b3759b..23aee0987 100644 --- a/webrtc/MediaStream.d.ts +++ b/webrtc/MediaStream.d.ts @@ -35,8 +35,8 @@ declare var MediaTrackConstraint: { } interface Navigator { - getUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void ); - webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void ); + getUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: LocalMediaStream) => void , errorCallback: (error: Error) => void ); + webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: LocalMediaStream) => void , errorCallback: (error: Error) => void ); } interface EventHandler { (event: Event): void; } diff --git a/webrtc/RTCPeerConnection-tests.ts b/webrtc/RTCPeerConnection-tests.ts new file mode 100644 index 000000000..d7b5a07f7 --- /dev/null +++ b/webrtc/RTCPeerConnection-tests.ts @@ -0,0 +1,51 @@ +/// +/// + +var config: RTCConfiguration = { iceServers: [{ url: "stun.l.google.com:19302" }] }; +var constraints: MediaConstraints = { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true } }; + +var peerConnection: RTCPeerConnection = new RTCPeerConnection(config, constraints); + +navigator.getUserMedia({ audio: true, video: true }, + stream => { + peerConnection.addStream(stream); + }, + error => { + console.log('Error message: ' + error.message); + console.log('Error name: ' + error.name); + }); + +peerConnection.onaddstream = ev => console.log(ev.type); +peerConnection.ondatachannel = ev => console.log(ev.type); +peerConnection.onicechange = ev => console.log(ev.type); +peerConnection.onnegotiationneeded = ev => console.log(ev.type); +peerConnection.onopen = ev => console.log(ev.type); +peerConnection.onicecandidate = ev => console.log(ev.type); +peerConnection.onremovestream = ev => console.log(ev.type); +peerConnection.onstatechange = ev => console.log(ev.type); + +peerConnection.createOffer( + offer => { + peerConnection.setLocalDescription(offer, + () => console.log("set local description"), + error => console.log("Error setting local description: " + error)); + }, + error => console.log("Error creating offer: " + error)); + +var type: RTCSdpType = RTCSdpType.offer; +var offer: RTCSessionDescriptionInit = { type: type, sdp: "some sdp" }; +var sessionDescription = new RTCSessionDescription(offer); + +peerConnection.setRemoteDescription(sessionDescription, () => { + peerConnection.createAnswer( + answer => { + peerConnection.setLocalDescription(answer, + () => console.log('Set local description'), + error => console.log("Error setting local description from created answer: " + error + "; answer.sdp=" + answer.sdp)); + }, + error => console.log("Error creating answer: " + error)); +}, +error => console.log('Error setting remote description: ' + error + "; offer.sdp=" + offer.sdp)); + +var wkPeerConnection: webkitRTCPeerConnection = new webkitRTCPeerConnection(config, constraints); + From c11d0c91e08fcb0f8d1ae1a9ea0047b16e189507 Mon Sep 17 00:00:00 2001 From: Vincent Bortone Date: Fri, 18 Jan 2013 03:28:00 -0500 Subject: [PATCH 5/7] Initial implementation of Bootbox.js --- bootbox/bootbox-tests.ts | 1 + bootbox/bootbox.d.ts | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 bootbox/bootbox-tests.ts create mode 100644 bootbox/bootbox.d.ts diff --git a/bootbox/bootbox-tests.ts b/bootbox/bootbox-tests.ts new file mode 100644 index 000000000..ced7b4bb6 --- /dev/null +++ b/bootbox/bootbox-tests.ts @@ -0,0 +1 @@ +// Tests for Bootbox \ No newline at end of file diff --git a/bootbox/bootbox.d.ts b/bootbox/bootbox.d.ts new file mode 100644 index 000000000..b56c60f45 --- /dev/null +++ b/bootbox/bootbox.d.ts @@ -0,0 +1,49 @@ +// Type definitions for Bootbox 3.0.0 +// Project: https://github.com/makeusabrew/bootbox +// Definitions by: Vincent Bortone +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +interface BootboxLocale { + OK: string; + CANCEL: string; + CONFIRM: string; +} + +interface BootboxIcons { + OK: any; + CANCEL: any; + CONFIRM: any; +} + +interface BootboxHandler { + label: string; + class: string; + callback: () => void; + callback: (result: bool) => void; + callback: (result: string) => void; +} + +interface BootboxOption { + header: string; + headerCloseButton: bool; +} + +interface BootboxStatic { + alert(message: string, customButtonText?: string, callback?: () => void): void; + confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void; + prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void; + dialog(message: string, handlers?: BootboxHandler[], options?: any): void; + dialog(message: string, handler?: BootboxHandler): void; + hideAll(): void; + animate(shouldAnimate: bool): void; + backdrop(backdropValue: string): void; + classes(customCssClasses: string): void; + setIcons(icons: BootboxIcons): void; + setLocale(localeName: string): void; + addLocale(localeName: string, translations: BootboxLocale) : void; +} + +declare var bootbox : BootboxStatic; \ No newline at end of file From 5aa600bcad86e4189b6fec7b7a6a1e8ebea0258e Mon Sep 17 00:00:00 2001 From: Vincent Bortone Date: Fri, 18 Jan 2013 15:32:56 -0500 Subject: [PATCH 6/7] Update interface and add tests --- bootbox/bootbox-tests.ts | 79 ++++++++++++++++++++++++++++++++- bootbox/bootbox.d.ts | 94 ++++++++++++++++++++-------------------- 2 files changed, 124 insertions(+), 49 deletions(-) diff --git a/bootbox/bootbox-tests.ts b/bootbox/bootbox-tests.ts index ced7b4bb6..c8eb86d0f 100644 --- a/bootbox/bootbox-tests.ts +++ b/bootbox/bootbox-tests.ts @@ -1 +1,78 @@ -// Tests for Bootbox \ No newline at end of file +// QUnit Tests for Bootbox 3.0 +/// +/// + +test("Bootbox alert with message", function () { + ok(bootbox.alert("Are we ok?"), "Passed!"); +}); + +test("Bootbox alert with message and custom text in button", function () { + ok(bootbox.alert("Are we ok with Test button?", "Test"), "Passed!"); +}); + +asyncTest("Bootbox alert with message and callback", function() { + bootbox.alert("Are we ok with callback?", function() { + ok(true, "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox alert with message and callback and custom text", function() { + bootbox.alert("Are we ok with callback and custom button?", "Test", function() { + ok(true, "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox confirm (ok) with message and callback", function() { + bootbox.confirm("Click ok to pass test", function(result) { + ok(result, "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox confirm (cancel) with message and callback", function() { + bootbox.confirm("Click cancel to pass test", function(result) { + ok(!result, "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox confirm (confirm?) with message and callback and custom text", function() { + bootbox.confirm("Click confirm to pass test", "Cancel?", "Confirm?", function(result) { + ok(result, "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox confirm (cancel?) with message and callback and custom text", function() { + bootbox.confirm("Click cancel to pass test", "Cancel?", "Confirm?", function(result) { + ok(!result, "Callback called!"); + start(); + }); +}); + +test("Bootbox prompt with message", function () { + ok(bootbox.prompt("Are we ok?"), "Passed!"); +}); + +asyncTest("Bootbox prompt with message and callback", function() { + bootbox.prompt("Enter 'ok' to pass test", function(result) { + equal(result.toLowerCase(), "ok", "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox prompt with message and callback and custom text", function() { + bootbox.prompt("Enter 'ok' to pass test", "Cancel?", "Confirm?", function(result) { + equal(result.toLowerCase(), "ok", "Callback called!"); + start(); + }); +}); + +asyncTest("Bootbox prompt with message and callback and custom text and default value", function() { + bootbox.prompt("Keep default value and click ok", "Cancel?", "Confirm?", function(result) { + equal(result, "Test Value", "Callback called!"); + start(); + }, "Test Value"); +}); diff --git a/bootbox/bootbox.d.ts b/bootbox/bootbox.d.ts index b56c60f45..1798be10e 100644 --- a/bootbox/bootbox.d.ts +++ b/bootbox/bootbox.d.ts @@ -1,49 +1,47 @@ -// Type definitions for Bootbox 3.0.0 -// Project: https://github.com/makeusabrew/bootbox -// Definitions by: Vincent Bortone -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -/// -/// - -interface BootboxLocale { - OK: string; - CANCEL: string; - CONFIRM: string; -} - -interface BootboxIcons { - OK: any; - CANCEL: any; - CONFIRM: any; -} - -interface BootboxHandler { - label: string; - class: string; - callback: () => void; - callback: (result: bool) => void; - callback: (result: string) => void; -} - -interface BootboxOption { - header: string; - headerCloseButton: bool; -} - -interface BootboxStatic { - alert(message: string, customButtonText?: string, callback?: () => void): void; - confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void; - prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void; - dialog(message: string, handlers?: BootboxHandler[], options?: any): void; - dialog(message: string, handler?: BootboxHandler): void; - hideAll(): void; - animate(shouldAnimate: bool): void; - backdrop(backdropValue: string): void; - classes(customCssClasses: string): void; - setIcons(icons: BootboxIcons): void; - setLocale(localeName: string): void; - addLocale(localeName: string, translations: BootboxLocale) : void; -} - +// Type definitions for Bootbox 3.0.0 +// Project: https://github.com/makeusabrew/bootbox +// Definitions by: Vincent Bortone +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface BootboxLocale { + OK: string; + CANCEL: string; + CONFIRM: string; +} + +interface BootboxIcons { + OK: any; + CANCEL: any; + CONFIRM: any; +} + +interface BootboxHandler { + label: string; + class: string; + callback: (result?: any) => void; +} + +interface BootboxOption { + header: string; + headerCloseButton: bool; +} + +interface BootboxStatic { + alert(message: string, callback: () => void): void; + alert(message: string, customButtonText?: string, callback?: () => void): void; + confirm(message: string, callback: (result: bool) => void): void; + confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void; + prompt(message: string, callback: (result: string) => void, defaultValue?: string): void; + prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void; + dialog(message: string, handlers?: BootboxHandler[], options?: any): void; + dialog(message: string, handler?: BootboxHandler): void; + hideAll(): void; + animate(shouldAnimate: bool): void; + backdrop(backdropValue: string): void; + classes(customCssClasses: string): void; + setIcons(icons: BootboxIcons): void; + setLocale(localeName: string): void; + addLocale(localeName: string, translations: BootboxLocale) : void; +} + declare var bootbox : BootboxStatic; \ No newline at end of file From f248f8b477124deb23fcdc6f00c7cc7e4e605e6c Mon Sep 17 00:00:00 2001 From: Vincent Bortone Date: Fri, 18 Jan 2013 16:05:44 -0500 Subject: [PATCH 7/7] Conformed tests to readme.md --- bootbox/bootbox-tests.ts | 110 +++++++++++++++++++-------------------- bootbox/bootbox.d.ts | 5 +- 2 files changed, 56 insertions(+), 59 deletions(-) diff --git a/bootbox/bootbox-tests.ts b/bootbox/bootbox-tests.ts index c8eb86d0f..66922ab2e 100644 --- a/bootbox/bootbox-tests.ts +++ b/bootbox/bootbox-tests.ts @@ -1,78 +1,74 @@ // QUnit Tests for Bootbox 3.0 /// -/// -test("Bootbox alert with message", function () { - ok(bootbox.alert("Are we ok?"), "Passed!"); +bootbox.alert("Are we ok?"); +bootbox.alert("Are we ok with Test button?", "Test"); +bootbox.alert("Are we ok with callback?", function() { + console.log("Callback called!"); +}); +bootbox.alert("Are we ok with callback and custom button?", "Test", function() { + console.log("Callback called!"); }); -test("Bootbox alert with message and custom text in button", function () { - ok(bootbox.alert("Are we ok with Test button?", "Test"), "Passed!"); +bootbox.confirm("Click ok to pass test", function(result) { + console.log(result); }); -asyncTest("Bootbox alert with message and callback", function() { - bootbox.alert("Are we ok with callback?", function() { - ok(true, "Callback called!"); - start(); - }); +bootbox.confirm("Click cancel to pass test", function(result) { + console.log(!result); }); -asyncTest("Bootbox alert with message and callback and custom text", function() { - bootbox.alert("Are we ok with callback and custom button?", "Test", function() { - ok(true, "Callback called!"); - start(); - }); +bootbox.confirm("Click confirm to pass test", "Cancel?", "Confirm?", function(result) { + console.log(result); }); -asyncTest("Bootbox confirm (ok) with message and callback", function() { - bootbox.confirm("Click ok to pass test", function(result) { - ok(result, "Callback called!"); - start(); - }); +bootbox.confirm("Click cancel to pass test", "Cancel?", "Confirm?", function(result) { + console.log(!result); }); -asyncTest("Bootbox confirm (cancel) with message and callback", function() { - bootbox.confirm("Click cancel to pass test", function(result) { - ok(!result, "Callback called!"); - start(); - }); +bootbox.prompt("Are we ok?"); + +bootbox.prompt("Enter 'ok' to pass test", function(result) { + console.log(result); }); -asyncTest("Bootbox confirm (confirm?) with message and callback and custom text", function() { - bootbox.confirm("Click confirm to pass test", "Cancel?", "Confirm?", function(result) { - ok(result, "Callback called!"); - start(); - }); +bootbox.prompt("Enter 'ok' to pass test", "Cancel?", "Confirm?", function(result) { + console.log(result); }); -asyncTest("Bootbox confirm (cancel?) with message and callback and custom text", function() { - bootbox.confirm("Click cancel to pass test", "Cancel?", "Confirm?", function(result) { - ok(!result, "Callback called!"); - start(); - }); -}); +bootbox.prompt("Keep default value and click ok", "Cancel?", "Confirm?", function(result) { + console.log(result); +}, "Test Value"); -test("Bootbox prompt with message", function () { - ok(bootbox.prompt("Are we ok?"), "Passed!"); -}); +bootbox.dialog("Test Dialog"); +var handler = { + label: "OK", + class: "MyClass", + callback: function () { + console.log("Test Dialog"); + } +}; -asyncTest("Bootbox prompt with message and callback", function() { - bootbox.prompt("Enter 'ok' to pass test", function(result) { - equal(result.toLowerCase(), "ok", "Callback called!"); - start(); - }); -}); +var option = { + header: "header", + headerCloseButton: true +}; -asyncTest("Bootbox prompt with message and callback and custom text", function() { - bootbox.prompt("Enter 'ok' to pass test", "Cancel?", "Confirm?", function(result) { - equal(result.toLowerCase(), "ok", "Callback called!"); - start(); - }); -}); +bootbox.dialog("Test Dialog", handler); +bootbox.dialog("Test Dialog", [handler], option); -asyncTest("Bootbox prompt with message and callback and custom text and default value", function() { - bootbox.prompt("Keep default value and click ok", "Cancel?", "Confirm?", function(result) { - equal(result, "Test Value", "Callback called!"); - start(); - }, "Test Value"); -}); +bootbox.hideAll(); +bootbox.animate(false); +bootbox.backdrop("backdrop"); +bootbox.classes("myClass"); + +var icons: BootboxIcons = { + OK: "OK Icon", + CANCEL: "Cancel Icon", + CONFIRM: "Confirm Icon" +}; +bootbox.setIcons(icons); + +bootbox.setLocale("en"); + +bootbox.addLocale("klingon", { OK: "luq", CANCEL: "qIl", CONFIRM: "Confirm" }); \ No newline at end of file diff --git a/bootbox/bootbox.d.ts b/bootbox/bootbox.d.ts index 1798be10e..cea0a0ba4 100644 --- a/bootbox/bootbox.d.ts +++ b/bootbox/bootbox.d.ts @@ -33,8 +33,9 @@ interface BootboxStatic { confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void; prompt(message: string, callback: (result: string) => void, defaultValue?: string): void; prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void; - dialog(message: string, handlers?: BootboxHandler[], options?: any): void; - dialog(message: string, handler?: BootboxHandler): void; + dialog(message: string, handlers: BootboxHandler[], options?: any): void; + dialog(message: string, handler: BootboxHandler): void; + dialog(message: string): void; hideAll(): void; animate(shouldAnimate: bool): void; backdrop(backdropValue: string): void;