From 2c1a75e3ec01c075484fa2daf43039f49580725d Mon Sep 17 00:00:00 2001 From: Anup Kattel Date: Fri, 26 Jun 2015 09:17:19 +0930 Subject: [PATCH] Updated definitions and tests for Bootbox. --- bootbox/bootbox-tests.ts | 52 +++++++++++++++++++++++++++++++--------- bootbox/bootbox.d.ts | 45 ++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/bootbox/bootbox-tests.ts b/bootbox/bootbox-tests.ts index 7cf6124cd..dbdfa252d 100644 --- a/bootbox/bootbox-tests.ts +++ b/bootbox/bootbox-tests.ts @@ -1,4 +1,4 @@ -// QUnit Tests for Bootbox 3.0 +// QUnit Tests for Bootbox 4.4.0 /// bootbox.alert("Are we ok?"); @@ -6,14 +6,13 @@ bootbox.alert("Are we ok with callback?", function () { console.log("Callback called!"); }); bootbox.alert({ + size: "medium", message: "Are we ok with callback and custom button?", callback: function () { console.log("Callback called!"); } }); -bootbox.confirm("Click ok to pass test"); - bootbox.confirm("Click cancel to pass test", function (result) { console.log(!result); }); @@ -24,28 +23,49 @@ bootbox.confirm({ } }); -bootbox.prompt("Are we ok?"); bootbox.prompt("Enter 'ok' to pass test", function (result) { console.log(result); }); bootbox.prompt({ + title: "Wassup?", + message: "Enter 'ok' to pass test", callback: function (result) { + console.log(result); + } +}); +bootbox.prompt({ + size: "large", + title: "Wassup?", message: "Enter 'ok' to pass test", callback: function (result) { console.log(result); } }); -bootbox.dialog("Test Dialog"); - - -bootbox.dialog("Test Dialog", function (result) { - return result; -}); bootbox.dialog({ message: "Test Dialog", callback: function (result) { } }); +// Testing the return object of the call. Using the pointer to disable the animation on success callback. +var bBox : JQuery; + +bBox = bootbox.dialog({ + message: "Test Dialog", + buttons: { + cancel: { + label: "Cancel" + }, + confirm: { + label: "Continue", + callback: function () { + bBox.removeClass("fade"); + console.log("Outer callback."); + } + } + }, + animate: true, +}); + var bdo: BootboxDialogOptions; var sampleButton: BootboxButton = { label: 'ButtonLabelToUse', @@ -74,4 +94,14 @@ bootbox.setDefaults({ show: true }) -bootbox.hideAll(); \ No newline at end of file +bootbox.hideAll(); + +var localeOptions: BootboxLocaleValues = { + OK: 'Hus', + CANCEL: 'Nai', + CONFIRM: 'Pakka' +} + +bootbox.addLocale("Nepali", localeOptions); +bootbox.setLocale("Nepali"); +bootbox.removeLocale("Nepali"); \ No newline at end of file diff --git a/bootbox/bootbox.d.ts b/bootbox/bootbox.d.ts index b9f3db22b..bc4f40f0f 100644 --- a/bootbox/bootbox.d.ts +++ b/bootbox/bootbox.d.ts @@ -1,22 +1,25 @@ -// Type definitions for Bootbox 4.0.0 +// Type definitions for Bootbox 4.4.0 // Project: https://github.com/makeusabrew/bootbox -// Definitions by: Vincent Bortone , Kon Pik +// Definitions by: Vincent Bortone , Kon Pik , Anup Kattel // Definitions: https://github.com/borisyankov/DefinitelyTyped - +/// interface BootboxAlertOptions { + size?: string; message: string; callback?: () => any; } interface BootboxConfirmOptions { + size?: string; message: string; - callback?: (result: boolean) => any; + callback: (result: boolean) => any; } interface BootboxPromptOptions { - message: string; - callback?: (result: string) => any; + size?: string; + message?: string; + callback: (result: string) => any; } interface BootboxButton { @@ -28,13 +31,15 @@ interface BootboxButton { interface BootboxDialogOptions { message: string | Element; title?: string | Element; + locale?: string; callback?: (result: boolean) => any; + onEscape?: () => any | boolean; show?: boolean; - onEscape?: () => any; backdrop?: boolean; closeButton?: boolean; animate?: boolean; className?: string; + size?: string; buttons?: Object; // complex object where each key is of type BootboxButton } @@ -47,17 +52,27 @@ interface BootboxDefaultOptions { className?: string; } +interface BootboxLocaleValues { + OK: string; + CANCEL: string; + CONFIRM: string; +} + interface BootboxStatic { - alert(message: string, callback?: () => void): void; - alert(options: BootboxAlertOptions): void; - confirm(message: string, callback?: (result: boolean) => void): void; - confirm(options: BootboxConfirmOptions): void; - prompt(message: string, callback?: (result: string) => void): void; - prompt(options: BootboxPromptOptions): void; - dialog(message: string, callback?: (result: string) => void): void; - dialog(options: BootboxDialogOptions): void; + alert(message: string, callback?: () => void): JQuery; + alert(options: BootboxAlertOptions): JQuery; + confirm(message: string, callback: (result: boolean) => void): JQuery; + confirm(options: BootboxConfirmOptions): JQuery; + prompt(message: string, callback: (result: string) => void): JQuery; + prompt(options: BootboxPromptOptions): JQuery; + dialog(message: string, callback?: (result: string) => void): JQuery; + dialog(options: BootboxDialogOptions): JQuery; setDefaults(options: BootboxDefaultOptions): void; hideAll(): void; + + addLocale(name: string, values: BootboxLocaleValues): void; + removeLocale(name: string): void; + setLocale(name: string): void; } declare var bootbox: BootboxStatic;