diff --git a/toastr/toastr-tests.ts b/toastr/toastr-tests.ts index 936d1da0f6..31a09e6098 100644 --- a/toastr/toastr-tests.ts +++ b/toastr/toastr-tests.ts @@ -1,66 +1,84 @@ -/// - -function test_basic() { - var t = []; - t.push(toastr.info('Are you the 6 fingered man?')); - t.push(toastr.warning('My name is Inigo Montoya. You Killed my father, prepare to die!')); - t.push(toastr.success('Have fun storming the castle!', 'Miracle Max Says')); - t.push(toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')); - toastr.clear(t[0]); // clear 1 - toastr.clear(); // clear all - - var msg = 'Do you think Rodents of Unusual Size really exist?'; - var title = 'Fireswamp Legends'; - var overrides = { timeOut: 250 }; - toastr.warning(msg, title, overrides); - toastr.options.onclick = function () { } -} - -declare var $; -function test_fromdemo() { - $('#showtoast').click(function () { - var shortCutFunction = $("#toastTypeGroup input:radio:checked").val(), - msg = $('#message').val(), - title = $('#title').val() || '', - $fadeIn = $('#fadeIn'), - $fadeOut = $('#fadeOut'), - $timeOut = $('#timeOut'), - $extendedTimeOut = $('#extendedTimeOut'), - toastIndex = 123; - toastr.options = { - debug: $('#debugInfo').prop('checked'), - tapToDismiss: $('#tapToDismiss').prop('checked'), - positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right' - } - if ($fadeIn.val().length) { - toastr.options.fadeIn = +$fadeIn.val() - } - if ($fadeOut.val().length) { - toastr.options.fadeOut = +$fadeOut.val() - } - if ($timeOut.val().length) { - toastr.options.timeOut = +$timeOut.val() - } - if ($extendedTimeOut.val().length) { - toastr.options.extendedTimeOut = +$extendedTimeOut.val() - } - var $toast = toastr[shortCutFunction](msg, title) - if ($toast.find('#okBtn').length) { - $toast.on('click', '#okBtn', function () { - alert('you clicked me. i was toast #' + toastIndex + '. goodbye!') - $toast.remove() - }) - } - if ($toast.find('#surpriseBtn').length) { - $toast.on('click', '#surpriseBtn', function () { - alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.') - }) - } - }); - $('#clearlasttoast').click(function() { - toastr.clear($toastlast); - }); - $('#cleartoasts').click(function () { - toastr.clear(); - }); +/// + +function test_basic() { + var t = []; + t.push(toastr.info('Are you the 6 fingered man?')); + t.push(toastr.warning('My name is Inigo Montoya. You Killed my father, prepare to die!')); + t.push(toastr.success('Have fun storming the castle!', 'Miracle Max Says')); + t.push(toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')); + toastr.clear(t[0]); // clear 1 + toastr.clear(); // clear all + + var msg = 'Do you think Rodents of Unusual Size really exist?'; + var title = 'Fireswamp Legends'; + var overrides = { timeOut: 250 }; + toastr.warning(msg, title, overrides); + toastr.options.onclick = function () { } +} + +declare var $; +function test_fromdemo() { + var i = -1, + toastCount = 0, + $toastlast, + getMessage = function () { + var msgs = ['My name is Inigo Montoya. You killed my father. Prepare to die!', + '
 This is a hyperlink
', + 'Are you the six fingered man?', + 'Inconceivable!', + 'I do not think that means what you think it means.', + 'Have fun storming the castle!' + ]; + i++; + if (i === msgs.length) { + i = 0; + } + + return msgs[i]; + }; + $('#showtoast').click(function () { + var shortCutFunction = $("#toastTypeGroup input:radio:checked").val(), + msg = $('#message').val(), + title = $('#title').val() || '', + $fadeIn = $('#fadeIn'), + $fadeOut = $('#fadeOut'), + $timeOut = $('#timeOut'), + $extendedTimeOut = $('#extendedTimeOut'), + toastIndex = 123; + toastr.options = { + debug: $('#debugInfo').prop('checked'), + tapToDismiss: $('#tapToDismiss').prop('checked'), + positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right' + } + if ($fadeIn.val().length) { + toastr.options.fadeIn = +$fadeIn.val() + } + if ($fadeOut.val().length) { + toastr.options.fadeOut = +$fadeOut.val() + } + if ($timeOut.val().length) { + toastr.options.timeOut = +$timeOut.val() + } + if ($extendedTimeOut.val().length) { + toastr.options.extendedTimeOut = +$extendedTimeOut.val() + } + var $toast = toastr[shortCutFunction](msg, title) + if ($toast.find('#okBtn').length) { + $toast.on('click', '#okBtn', function () { + alert('you clicked me. i was toast #' + toastIndex + '. goodbye!') + $toast.remove() + }) + } + if ($toast.find('#surpriseBtn').length) { + $toast.on('click', '#surpriseBtn', function () { + alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.') + }) + } + }); + $('#clearlasttoast').click(function () { + toastr.clear($toastlast); + }); + $('#cleartoasts').click(function () { + toastr.clear(); + }); } \ No newline at end of file diff --git a/toastr/toastr.d.ts b/toastr/toastr.d.ts index 8645032bf1..f1a0387042 100644 --- a/toastr/toastr.d.ts +++ b/toastr/toastr.d.ts @@ -1,49 +1,149 @@ -// Type definitions for Toastr 1.0 -// Project: https://github.com/CodeSeven/toastr -// Definitions by: Boris Yankov -// Definitions: https://github.com/borisyankov/DefinitelyTyped - - -/// - -interface ToastrOptions { - tapToDismiss?: bool; - toastClass?: string; - containerId?: string; - debug?: bool; - fadeIn?: number; - fadeOut?: number; - extendedTimeOut?: number; - iconClasses?: { - error: string; - info: string; - success: string; - warning: string; - }; - iconClass?: string; - positionClass?: string; - timeOut?: number; - titleClass?: string; - messageClass?: string; - - onclick?: () => void; -} - -interface ToastrDisplayMethod { - (message: string): JQuery; - (message: string, title: string): JQuery; - (message: string, title: string, overrides: ToastrOptions): JQuery; -} - -interface Toastr { - clear(): void; - clear(toast: JQuery): void; - error: ToastrDisplayMethod; - info: ToastrDisplayMethod; - options: ToastrOptions; - success: ToastrDisplayMethod; - warning: ToastrDisplayMethod; - version: string; -} - +// Type definitions for Toastr 1.0 +// Project: https://github.com/CodeSeven/toastr +// Definitions by: Boris Yankov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +/// + +interface ToastrOptions { + /** + * Should clicking on toast dismiss it? + */ + tapToDismiss?: bool; + /** + * CSS class the toast element will be given + */ + toastClass?: string; + /** + * Id toast container will be given + */ + containerId?: string; + /** + * Should debug details be outputted to the console + */ + debug?: bool; + /** + * Time in milliseconds the toast should take to fade in + */ + fadeIn?: number; + /** + * Time in milliseconds the toast should take to fade out + */ + fadeOut?: number; + /** + * Time in milliseconds the toast should be displayed after mouse over + */ + extendedTimeOut?: number; + iconClasses?: { + /** + * Icon to use on error toasts + */ + error: string; + /** + * Icon to use on info toasts + */ + info: string; + /** + * Icon to use on success toasts + */ + success: string; + /** + * Icon to use on warning toasts + */ + warning: string; + }; + /** + * Icon to use for toast + */ + iconClass?: string; + /** + * Where toast should be displayed + */ + positionClass?: string; + /** + * Time in milliseconds that the toast should be displayed + */ + timeOut?: number; + /** + * CSS class the title element will be given + */ + titleClass?: string; + /** + * CSS class the message element will be given + */ + messageClass?: string; + + /** + * Function to execute on toast click + */ + onclick?: () => void; +} + +interface ToastrDisplayMethod { + /** + * Create a toast + * + * @param message Message to display in toast + */ + (message: string): JQuery; + /** + * Create a toast + * + * @param message Message to display in toast + * @param title Title to display on toast + */ + (message: string, title: string): JQuery; + /** + * Create a toast + * + * @param message Message to display in toast + * @param title Title to display on toast + * @param overrides Option values for toast + */ + (message: string, title: string, overrides: ToastrOptions): JQuery; +} + +interface Toastr { + /** + * Clear toasts + */ + clear: { + /** + * Clear all toasts + */ + (): void; + /** + * Clear specific toast + * + * @param toast Toast to clear + */ + (toast: JQuery): void; + }; + /** + * Create an error toast + */ + error: ToastrDisplayMethod; + /** + * Create an info toast + */ + info: ToastrDisplayMethod; + /** + * Create an options object + */ + options: ToastrOptions; + /** + * Create a success toast + */ + success: ToastrDisplayMethod; + /** + * Create a warning toast + */ + warning: ToastrDisplayMethod; + /** + * Get toastr version + */ + version: string; +} + declare var toastr: Toastr; \ No newline at end of file