From 45aa4909630cba1fc8f01d6d4045ba0c60df5c73 Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Thu, 23 Jan 2014 15:02:32 -0500 Subject: [PATCH 1/3] Create messenger.d.ts --- messenger/messenger.d.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 messenger/messenger.d.ts diff --git a/messenger/messenger.d.ts b/messenger/messenger.d.ts new file mode 100644 index 000000000..b874eb356 --- /dev/null +++ b/messenger/messenger.d.ts @@ -0,0 +1,27 @@ +// Type definitions for Messenger.js 1.2.1 +// Project: https://github.com/HubSpot/messenger +// Definitions by: Derek Cicerone +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface IMessenger { + (): Messenger; + options: MessengerOptions; +} + +interface Messenger { + post(message: Message): void; + hideAll(): void; +} + +interface Message { + message: string; + hideAfter?: number; + showCloseButton?: boolean; + type?: string; +} + +interface MessengerOptions { + theme?: string; +} + +declare var Messenger: IMessenger; From 2d4c46b54b67f7acbc9bff110c0e4f3ca213ee3c Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Mon, 27 Jan 2014 21:39:29 -0500 Subject: [PATCH 2/3] Create messenger-tests.ts * this close to the surface area that we use - i don't feel comfortable adding more info without having actual usage --- messenger/messenger-tests.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 messenger/messenger-tests.ts diff --git a/messenger/messenger-tests.ts b/messenger/messenger-tests.ts new file mode 100644 index 000000000..1f560e6e2 --- /dev/null +++ b/messenger/messenger-tests.ts @@ -0,0 +1,14 @@ +/// + +var message = Messenger().post({ + message: "message", + hideAfter: 5, + showCloseButton: true, + type: "error" +}); +message.update({ + type: "error", + message: "Error calculating position" +}); + +Messenger().hideAll(); From c88f7109834f50966a102e7d49365c65538db6ec Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Mon, 27 Jan 2014 21:40:20 -0500 Subject: [PATCH 3/3] Update messenger.d.ts * adding documentation and missing stuff --- messenger/messenger.d.ts | 96 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/messenger/messenger.d.ts b/messenger/messenger.d.ts index b874eb356..3aacf2f88 100644 --- a/messenger/messenger.d.ts +++ b/messenger/messenger.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Messenger.js 1.2.1 +// Type definitions for Messenger.js 1.4.0 // Project: https://github.com/HubSpot/messenger // Definitions by: Derek Cicerone // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -9,18 +9,110 @@ interface IMessenger { } interface Messenger { - post(message: Message): void; + /** + * Posts a message. + */ + post(options: MessageOptions): Message; + + /** + * Hides all messages. + */ hideAll(): void; } interface Message { + /** + * Show the message, if it's hidden. + */ + show(): void; + + /** + * Hide the message, if it's hidden. + */ + hide(): void; + + /** + * If the message is associated with an ajax request or is counting down to retry, cancel it. + */ + cancel(): void; + + /** + * Update the message with the provided options. + */ + update(options: MessageOptions): void; +} + +interface MessageOptions { + /** + * The text of the message. + */ message: string; + + /** + * Hide the message after the provided number of seconds. + */ hideAfter?: number; + + /** + * Hide the message if Backbone client-side navigation occurs. + */ + hideOnNavigate?: boolean; + + /** + * A unique id. If supplied, only one message with that ID will be shown at a time. + */ + id?: string; + + /** + * Should a close button be added to the message? + */ showCloseButton?: boolean; + + /** + * Hide the newer message if there is an id collision, as opposed to the older message. + */ + singleton?: boolean; + + /** + * What theme class should be applied to the message? Defaults to the theme set for Messenger in general. + */ + theme?: string; + + /** + * "info", "error" or "success" are understood by the provided themes. You can also pass your own string, and that class will be added. + */ type?: string; } interface MessengerOptions { + + /** + * Extra classes to be appended to the container. + */ + extraClasses?: string; + + /** + * The maximum number of messages to show at once. + */ + maxMessages?: number; + + /** + * Default options for created messages. + */ + messageDefaults?: MessageOptions; + + /** + * Which locations should be tried when inserting the message container into the page. + * The default is ['body']. It accepts a list to allow you to try a variety of places + * when deciding what the optimal location is on any given page. This should generally + * not need to be changed unless you are inserting the messages into the flow of the + * document, rather than using messenger-fixed. + */ + parentLocations?: string[]; + + /** + * What theme are you using? Some themes have associated javascript, specifing this allows that js to run. + */ theme?: string; }