Merge pull request #341 from nestalk/master

Fix toastr test and add jsdoc comments
This commit is contained in:
Diullei Gomes
2013-02-25 15:28:38 -08:00
2 changed files with 231 additions and 113 deletions

View File

@@ -1,66 +1,84 @@
/// <reference path="toastr.d.ts" />
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();
});
/// <reference path="toastr.d.ts" />
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!',
'<div><input class="input-small" value="textbox"/>&nbsp;<a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="surpriseBtn" class="btn" style="margin: 0 8px 0 8px">Surprise me</button></div>',
'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();
});
}

196
toastr/toastr.d.ts vendored
View File

@@ -1,49 +1,149 @@
// Type definitions for Toastr 1.0
// Project: https://github.com/CodeSeven/toastr
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
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 <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
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;