Tests & compilation fixes.

This commit is contained in:
Andrey Kurosh
2016-01-15 17:24:43 +03:00
parent 4a4f44b4b0
commit c4193a4d81
2 changed files with 9 additions and 14 deletions

View File

@@ -1,14 +1,16 @@
/// <reference path="clipboard-js.d.ts" />
/// <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', {
target: elem => null
});
var cb5 = new clipboardjs.Clipboard('.btn', {
action: elem => 'copy',
target: elem => null
});

View File

@@ -6,22 +6,21 @@
declare module clipboardjs {
export class Clipboard {
constructor (selector: string, options?: ITargetOptions);
constructor (selector: string, options?: ITextOptions);
constructor(selector: string, options?: IOptions);
/**
* 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);
on(type: "success", handler: (e: Event) => void): void;
on(type: "error", handler: (e: Event) => void): void;
on(type: string, handler: (e: Event) => void): void;
/**
* Clears all event bindings.
*/
destroy();
destroy(): void;
}
interface IOptions {
@@ -31,20 +30,14 @@ declare module clipboardjs {
* @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