diff --git a/bootbox/bootbox-tests.ts b/bootbox/bootbox-tests.ts new file mode 100644 index 000000000..66922ab2e --- /dev/null +++ b/bootbox/bootbox-tests.ts @@ -0,0 +1,74 @@ +// QUnit Tests for Bootbox 3.0 +/// + +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!"); +}); + +bootbox.confirm("Click ok to pass test", function(result) { + console.log(result); +}); + +bootbox.confirm("Click cancel to pass test", function(result) { + console.log(!result); +}); + +bootbox.confirm("Click confirm to pass test", "Cancel?", "Confirm?", function(result) { + console.log(result); +}); + +bootbox.confirm("Click cancel to pass test", "Cancel?", "Confirm?", function(result) { + console.log(!result); +}); + +bootbox.prompt("Are we ok?"); + +bootbox.prompt("Enter 'ok' to pass test", function(result) { + console.log(result); +}); + +bootbox.prompt("Enter 'ok' to pass test", "Cancel?", "Confirm?", function(result) { + console.log(result); +}); + +bootbox.prompt("Keep default value and click ok", "Cancel?", "Confirm?", function(result) { + console.log(result); +}, "Test Value"); + +bootbox.dialog("Test Dialog"); +var handler = { + label: "OK", + class: "MyClass", + callback: function () { + console.log("Test Dialog"); + } +}; + +var option = { + header: "header", + headerCloseButton: true +}; + +bootbox.dialog("Test Dialog", handler); +bootbox.dialog("Test Dialog", [handler], option); + +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 new file mode 100644 index 000000000..cea0a0ba4 --- /dev/null +++ b/bootbox/bootbox.d.ts @@ -0,0 +1,48 @@ +// 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; + dialog(message: string): 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