Clipboard.js definitions.

This commit is contained in:
Andrey Kurosh
2016-01-15 17:14:10 +03:00
parent 7577a2f4c1
commit 4a4f44b4b0
2 changed files with 79 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
/// <reference path="clipboard-js.d.ts" />
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) { });
+59
View File
@@ -0,0 +1,59 @@
// Type definitions for clipboard.js 1.5.5
// Project: https://github.com/zenorocha/clipboard.js
// Definitions by: Andrei Kurosh <https://github.com/impworks>
// 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} <input> 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;
}