mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add definitions for jquery-toastmessage-plugin (#14625)
* Add definitions for jquery-toastmessage-plugin * Add tslint.json * enable strict null checks * Fix linting errors * target module "commonjs" to pass Travis test (even though no modules are used) * add 'lib' to taconfig.json to pass Travis test * add 'dom' to lib in tsconfig.json
This commit is contained in:
parent
9af10f325e
commit
795687164e
57
jquery-toastmessage-plugin/index.d.ts
vendored
Normal file
57
jquery-toastmessage-plugin/index.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
// Type definitions for jquery-toastmessage-plugin 0.2
|
||||
// Project: https://github.com/akquinet/jquery-toastmessage-plugin
|
||||
// Definitions by: Joe Skeen <https://github.com/joeskeen/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="jquery" />
|
||||
|
||||
declare interface JQuery {
|
||||
toastmessage: JQueryToastmessage.ToastmessageStatic;
|
||||
}
|
||||
|
||||
/** jQuery Toastmessage (http://akquinet.github.io/jquery-toastmessage-plugin/) */
|
||||
declare namespace JQueryToastmessage {
|
||||
interface ToastmessageStatic {
|
||||
/* shows a toast message of the specified type */
|
||||
(command: ShowToastCommand, message: string): JQuery;
|
||||
/** shows a custom toast */
|
||||
(command: 'showToast', toastOpts: ToastOptions): JQuery;
|
||||
/** removes the specified toast and returns it */
|
||||
(command: 'removeToast', toast: JQuery, closeOpts?: ToastOptions): void;
|
||||
/** configures the default toast options */
|
||||
(toastOpts: ToastOptions): void;
|
||||
}
|
||||
|
||||
type ShowToastCommand = 'showNoticeToast' | 'showSuccessToast' | 'showWarningToast' | 'showErrorToast';
|
||||
type ToastType = 'notice' | 'warning' | 'error' | 'success';
|
||||
type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'middle-left' | 'middle-center' | 'middle-right';
|
||||
|
||||
interface ToastOptions {
|
||||
/** in effect duration in miliseconds @default 600 */
|
||||
inEffectDuration?: number;
|
||||
/**
|
||||
* time in miliseconds before the item has to disappear @default 3000 */
|
||||
stayTime?: number;
|
||||
/** content of the item @default '' */
|
||||
text?: string;
|
||||
/** should the toast item sticky or not? @default false */
|
||||
sticky?: boolean;
|
||||
/** the type of toast @default 'notice' */
|
||||
type?: ToastType;
|
||||
/**
|
||||
* Position of the toast container holding different toast.
|
||||
* Position can be set only once at the very first call,
|
||||
* changing the position after the first call does nothing
|
||||
* @default 'top-right'
|
||||
*/
|
||||
position?: ToastPosition;
|
||||
/**
|
||||
* text which will be shown as close button,
|
||||
* set to '' when you want to introduce an image via css
|
||||
* @default ''
|
||||
*/
|
||||
closeText?: string;
|
||||
/** callback function when the toastmessage is closed @default null */
|
||||
close?: () => void;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
/// <reference path="./index.d.ts" />
|
||||
|
||||
|
||||
/* code examples from documentation */
|
||||
|
||||
$().toastmessage('showNoticeToast', 'some message here');
|
||||
$().toastmessage('showSuccessToast', "some message here");
|
||||
$().toastmessage('showWarningToast', "some message here");
|
||||
$().toastmessage('showErrorToast', "some message here");
|
||||
|
||||
// user configured toastmessage:
|
||||
const toastObject = $().toastmessage('showToast', {
|
||||
text : 'Hello World',
|
||||
sticky : true,
|
||||
position : 'top-right',
|
||||
type : 'success',
|
||||
close : function () {console.log("toast is closed ...");}
|
||||
});
|
||||
|
||||
$().toastmessage('removeToast', toastObject);
|
||||
|
||||
// reconfiguring the toasts as sticky
|
||||
$().toastmessage({sticky : true});
|
||||
|
||||
// saving the newly created toast into a variable
|
||||
var myToast = $().toastmessage('showNoticeToast', 'some message here');
|
||||
|
||||
// removing the toast
|
||||
$().toastmessage('removeToast', myToast);
|
||||
|
||||
// user configuration of all toastmessages to come:
|
||||
$().toastmessage({
|
||||
text : 'Hello World',
|
||||
sticky : true,
|
||||
position : 'top-right',
|
||||
type : 'success',
|
||||
close : function () {console.log("toast is closed ...");}
|
||||
});
|
||||
|
||||
$().toastmessage({
|
||||
inEffectDuration: 600, // in effect duration in miliseconds
|
||||
stayTime: 3000, // time in miliseconds before the item has to disappear
|
||||
text: '', // content of the item
|
||||
sticky: false, // should the toast item sticky or not?
|
||||
type: 'notice', // notice, warning, error, success
|
||||
position: 'top-right', // top-left, top-center, top-right, middle-left, middle-center, middle-right
|
||||
// Position of the toast container holding different toast.
|
||||
// Position can be set only once at the very first call,
|
||||
// changing the position after the first call does nothing
|
||||
closeText: '', // text which will be shown as close button,
|
||||
// set to '' when you want to introduce an image via css
|
||||
close: undefined // callback function when the toastmessage is closed
|
||||
});
|
||||
|
||||
/* code examples from tests */
|
||||
|
||||
$('.toast-container').remove();
|
||||
|
||||
$().toastmessage('showSuccessToast', "SUCCESS");
|
||||
$().toastmessage('showNoticeToast', "NOTICE");
|
||||
$().toastmessage('showWarningToast', "WARNING");
|
||||
$().toastmessage('showErrorToast', "ERROR");
|
||||
$().toastmessage({
|
||||
sticky : true,
|
||||
position : 'top-right',
|
||||
closeText: ''
|
||||
});
|
||||
$().toastmessage('showToast', {
|
||||
text : 'Success Dialog',
|
||||
type : 'success'
|
||||
});
|
||||
$().toastmessage('showToast', {
|
||||
text : 'Success Dialog',
|
||||
sticky : true,
|
||||
position : 'top-right',
|
||||
type : 'success',
|
||||
closeText: '',
|
||||
close : () => {}
|
||||
});
|
||||
var toast = $().toastmessage('showToast', {
|
||||
text : 'Success Dialog',
|
||||
sticky : true,
|
||||
position : 'top-right',
|
||||
type : 'success',
|
||||
closeText: '',
|
||||
close : () => {}
|
||||
});
|
||||
$().toastmessage('removeToast', toast, { close : () => {} });
|
||||
20
jquery-toastmessage-plugin/tsconfig.json
Normal file
20
jquery-toastmessage-plugin/tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"lib": ["es6", "dom"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"jquery-toastmessage-plugin-tests.ts"
|
||||
]
|
||||
}
|
||||
1
jquery-toastmessage-plugin/tslint.json
Normal file
1
jquery-toastmessage-plugin/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user