update-clipboard.js

This commit is contained in:
Kaoru Hagihara
2016-03-05 23:59:53 +09:00
parent 9f0f926a12
commit 724c7d3b5c
2 changed files with 55 additions and 45 deletions
+12 -6
View File
@@ -1,22 +1,28 @@
/// <reference path="clipboard.d.ts" />
var cb1 = new clipboard.Clipboard('.btn');
var cb2 = new clipboard.Clipboard('.btn', {
var cb1 = new Clipboard('.btn');
var cb2 = new Clipboard(document.getElementById('id'), {
action: elem => 'copy'
});
var cb3 = new clipboard.Clipboard('.btn', {
var cb3 = new Clipboard(document.querySelectorAll('query'), {
text: elem => null
});
var cb4 = new clipboard.Clipboard('.btn', {
var cb4 = new Clipboard('.btn', {
target: elem => null
});
var cb5 = new clipboard.Clipboard('.btn', {
var cb5 = new Clipboard('.btn', {
action: elem => 'copy',
target: elem => null
});
cb1.destroy();
cb2.on('success', function(e) { });
cb2.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
e.clearSelection();
});
cb2.on('error', function(e) { });
+43 -39
View File
@@ -1,52 +1,56 @@
// Type definitions for clipboard.js 1.5.5
// Type definitions for clipboard.js 1.5.9
// Project: https://github.com/zenorocha/clipboard.js
// Definitions by: Andrei Kurosh <https://github.com/impworks>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module clipboard {
declare class Clipboard {
constructor(selector: (string | Element | NodeListOf<Element>), options?: ClipboardOptions);
export class Clipboard {
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: ClipboardEvent) => void): this;
on(type: "error", handler: (e: ClipboardEvent) => void): this;
on(type: string, handler: (e: ClipboardEvent) => void): this;
/**
* 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): void;
on(type: "error", handler: (e: Event) => void): void;
on(type: string, handler: (e: Event) => void): void;
/**
* Clears all event bindings.
*/
destroy(): void;
}
/**
* Clears all event bindings.
*/
destroy(): void;
}
interface ClipboardOptions {
/**
* Overwrites default command ('cut' or 'copy').
* @param {Element} elem Current element
* @returns {String} Only 'cut' or 'copy'.
*/
action?: (elem: Element) => string;
interface IOptions {
/**
* Overwrites default command ('cut' or 'copy').
* @param {Element} elem Current element
* @returns {String} Only 'cut' or 'copy'.
*/
action?: (elem: Element) => string;
/**
* Overwrites default target input element.
* @param {Element} elem Current element
* @returns {Element} <input> element to use.
*/
target?: (elem: Element) => Element;
/**
* Overwrites default target input element.
* @param {Element} elem Current element
* @returns {Element} <input> element to use.
*/
target?: (elem: Element) => Element;
/**
* Returns the explicit text to copy.
* @param {Element} elem Current element
* @returns {String} Text to be copied.
*/
text?: (elem: Element) => string;
}
/**
* Returns the explicit text to copy.
* @param {Element} elem Current element
* @returns {String} Text to be copied.
*/
text?: (elem: Element) => string;
}
interface ClipboardEvent {
action: string;
text: string;
trigger: Element;
clearSelection(): void;
}
declare module 'clipboard' {
export = clipboard;
}
export = Clipboard;
}