From 4a4f44b4b040c32086655200635314f7a45112de Mon Sep 17 00:00:00 2001 From: Andrey Kurosh Date: Fri, 15 Jan 2016 17:14:10 +0300 Subject: [PATCH 1/3] Clipboard.js definitions. --- clipboard.js/clipboard.js-tests.ts | 20 ++++++++++ clipboard.js/clipboard.js.d.ts | 59 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 clipboard.js/clipboard.js-tests.ts create mode 100644 clipboard.js/clipboard.js.d.ts 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 From c4193a4d81b914dd8f233583131dc57fbb136d91 Mon Sep 17 00:00:00 2001 From: Andrey Kurosh Date: Fri, 15 Jan 2016 17:24:43 +0300 Subject: [PATCH 2/3] Tests & compilation fixes. --- clipboard.js/clipboard.js-tests.ts | 6 ++++-- clipboard.js/clipboard.js.d.ts | 17 +++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/clipboard.js/clipboard.js-tests.ts b/clipboard.js/clipboard.js-tests.ts index 5adbeda27..962bf34e0 100644 --- a/clipboard.js/clipboard.js-tests.ts +++ b/clipboard.js/clipboard.js-tests.ts @@ -1,14 +1,16 @@ -/// +/// 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 }); diff --git a/clipboard.js/clipboard.js.d.ts b/clipboard.js/clipboard.js.d.ts index 26b1a9201..6a8af8519 100644 --- a/clipboard.js/clipboard.js.d.ts +++ b/clipboard.js/clipboard.js.d.ts @@ -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} element to use. */ target?: (elem: Element) => Element; - } - interface ITextOptions extends IOptions { /** * Returns the explicit text to copy. * @param {Element} elem Current element From 9d3c0e31928a196677b1371a350a363cf1357317 Mon Sep 17 00:00:00 2001 From: Andrey Kurosh Date: Wed, 20 Jan 2016 10:54:00 +0300 Subject: [PATCH 3/3] Renamed to match npm module's name. --- clipboard.js/clipboard.js-tests.ts | 22 ------------------- clipboard/clipboard-tests.ts | 22 +++++++++++++++++++ .../clipboard.d.ts | 6 ++--- 3 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 clipboard.js/clipboard.js-tests.ts create mode 100644 clipboard/clipboard-tests.ts rename clipboard.js/clipboard.js.d.ts => clipboard/clipboard.d.ts (94%) diff --git a/clipboard.js/clipboard.js-tests.ts b/clipboard.js/clipboard.js-tests.ts deleted file mode 100644 index 962bf34e0..000000000 --- a/clipboard.js/clipboard.js-tests.ts +++ /dev/null @@ -1,22 +0,0 @@ -/// - -var cb1 = new clipboardjs.Clipboard('.btn'); -var cb2 = new clipboardjs.Clipboard('.btn', { - action: elem => 'copy' -}); -var cb3 = new clipboardjs.Clipboard('.btn', { - text: elem => null -}); -var cb4 = new clipboardjs.Clipboard('.btn', { - target: elem => null -}); -var cb5 = 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/clipboard-tests.ts b/clipboard/clipboard-tests.ts new file mode 100644 index 000000000..de6e9fc1a --- /dev/null +++ b/clipboard/clipboard-tests.ts @@ -0,0 +1,22 @@ +/// + +var cb1 = new clipboard.Clipboard('.btn'); +var cb2 = new clipboard.Clipboard('.btn', { + action: elem => 'copy' +}); +var cb3 = new clipboard.Clipboard('.btn', { + text: elem => null +}); +var cb4 = new clipboard.Clipboard('.btn', { + target: elem => null +}); +var cb5 = new clipboard.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/clipboard.d.ts similarity index 94% rename from clipboard.js/clipboard.js.d.ts rename to clipboard/clipboard.d.ts index 6a8af8519..ddba32b06 100644 --- a/clipboard.js/clipboard.js.d.ts +++ b/clipboard/clipboard.d.ts @@ -3,7 +3,7 @@ // Definitions by: Andrei Kurosh // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module clipboardjs { +declare module clipboard { export class Clipboard { constructor(selector: string, options?: IOptions); @@ -47,6 +47,6 @@ declare module clipboardjs { } } -declare module 'clipboardjs' { - export = clipboardjs; +declare module 'clipboard' { + export = clipboard; } \ No newline at end of file