From f044ddb2c3f80c93737b575e256833fe405c0010 Mon Sep 17 00:00:00 2001 From: Steven Robertson Date: Mon, 3 Oct 2016 18:20:58 +0100 Subject: [PATCH] Create typings for jquery-alertable (#11642) --- jquery-alertable/jquery-alertable-tests.ts | 79 ++++++++++++++++++++++ jquery-alertable/jquery-alertable.d.ts | 29 ++++++++ 2 files changed, 108 insertions(+) create mode 100644 jquery-alertable/jquery-alertable-tests.ts create mode 100644 jquery-alertable/jquery-alertable.d.ts diff --git a/jquery-alertable/jquery-alertable-tests.ts b/jquery-alertable/jquery-alertable-tests.ts new file mode 100644 index 0000000000..df28c8a81b --- /dev/null +++ b/jquery-alertable/jquery-alertable-tests.ts @@ -0,0 +1,79 @@ +/// +/// + +// +// Examples from https://github.com/claviska/jquery-alertable +// + +function example_alerts_tests() { + + // Basic example + $.alertable.alert('Howdy!'); + + // Example with action when the modal is dismissed + $.alertable.alert('Howdy!').always(function() { + // Modal was dismissed + }); +} + +function example_confirmations_tests() { + + // Basic example + $.alertable.confirm('You sure?').then(function() { + // OK was selected + }); + + // Example with then/always + $.alertable.confirm('You sure?').then(function() { + // OK was selected + }, function() { + // Cancel was selected + }).always(function() { + // Modal was dismissed + }); +} + +function example_prompts_tests() { + + // Basic example + $.alertable.prompt('How many?').then(function(data) { + // Prompt was submitted + }); + + // Example with then/always + $.alertable.prompt('How many?').then(function(data) { + // Prompt was submitted + }, function() { + // Prompt was canceled + }).always(function() { + // Modal was dismissed + }); +} + +function options_tests() { + $.alertable.alert('Howdy!', { + container: 'body', + html: false, + cancelButton: '', + okButton: '', + overlay: '
', + prompt: '', + modal: `
+
+
+
+
`, + hide: () => $(this.modal).add(this.overlay).fadeOut(100), + show: () => $(this.modal).add(this.overlay).fadeIn(100) + }); + + $.alertable.confirm('You sure?', { + container: 'body' + }); + + $.alertable.prompt('How many?', { + container: 'body' + }); + + $.alertable.defaults.container = 'body'; +} diff --git a/jquery-alertable/jquery-alertable.d.ts b/jquery-alertable/jquery-alertable.d.ts new file mode 100644 index 0000000000..93e219ef18 --- /dev/null +++ b/jquery-alertable/jquery-alertable.d.ts @@ -0,0 +1,29 @@ +// Type definitions for jquery-alertable 1.0.2 +// Project: https://github.com/claviska/jquery-alertable +// Definitions by: Steven Robertson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +interface JQueryStatic { + alertable: Alertable; +} + +interface Alertable { + alert(message: string, options?: AlertableOptions): JQueryPromise; + confirm(message: string, options?: AlertableOptions): JQueryPromise; + prompt(message: string, options?: AlertableOptions): JQueryPromise; + defaults: AlertableOptions; +} + +interface AlertableOptions { + container?: string; + html?: boolean; + cancelButton?: string; + okButton?: string; + overlay?: string; + prompt?: string; + modal?: string; + hide?: Function; + show?: Function; +}