diff --git a/clipboard.js/clipboard.js-tests.ts b/clipboard.js/clipboard.js-tests.ts new file mode 100644 index 000000000..5adbeda27 --- /dev/null +++ b/clipboard.js/clipboard.js-tests.ts @@ -0,0 +1,20 @@ +/// + +var cb1 = new clipboardjs.Clipboard('.btn'); +var cb2 = new clipboardjs.Clipboard('.btn', { + action: elem => 'copy' +}); +var cb3 = new clipboardjs.Clipboard('.btn', { + action: elem => 'copy', + text: elem => null +}); +var cb4 = new clipboardjs.Clipboard('.btn', { + action: elem => 'copy', + target: elem => null +}); + +cb1.destroy(); + +cb2.on('success', function(e) { }); +cb2.on('error', function(e) { }); + diff --git a/clipboard.js/clipboard.js.d.ts b/clipboard.js/clipboard.js.d.ts new file mode 100644 index 000000000..26b1a9201 --- /dev/null +++ b/clipboard.js/clipboard.js.d.ts @@ -0,0 +1,59 @@ +// Type definitions for clipboard.js 1.5.5 +// Project: https://github.com/zenorocha/clipboard.js +// Definitions by: Andrei Kurosh +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module clipboardjs { + + export class Clipboard { + constructor (selector: string, options?: ITargetOptions); + constructor (selector: string, options?: ITextOptions); + + /** + * Subscribes to events that indicate the result of a copy/cut operation. + * @param type {String} Event type ('success' or 'error'). + * @param handler Callback function. + */ + on(type: "success", handler: (e: Event) => void); + on(type: "error", handler: (e: Event) => void); + on(type: string, handler: (e: Event) => void); + + /** + * Clears all event bindings. + */ + destroy(); + } + + interface IOptions { + /** + * Overwrites default command ('cut' or 'copy'). + * @param {Element} elem Current element + * @returns {String} Only 'cut' or 'copy'. + */ + action?: (elem: Element) => string; + } + + // Two different interfaces, because 'target' and 'text' attributes cannot be used together. + + interface ITargetOptions extends IOptions { + /** + * Overwrites default target input element. + * @param {Element} elem Current element + * @returns {Element} element to use. + */ + target?: (elem: Element) => Element; + } + + interface ITextOptions extends IOptions { + /** + * Returns the explicit text to copy. + * @param {Element} elem Current element + * @returns {String} Text to be copied. + */ + text?: (elem: Element) => string; + } +} + +declare module 'clipboardjs' { + export = clipboardjs; +} \ No newline at end of file