UNPKG

press-plus

Version:
41 lines (37 loc) 941 B
class Clipboard { options: { text: string | Function; }; callbacks: Map<string, Function>; constructor(selector: string, options: { text: string | Function, [key: string]: any}) { this.options = options; this.callbacks = new Map(); this.onClick(); } on(type: string, callback: any) { this.callbacks.set(type, callback); } onClick() { if (wx) { const { text } = this.options; const dataText: string = text instanceof Function ? text() : text; wx.setClipboardData({ data: dataText, success: () => { const successCb = this.callbacks.get('success'); if (successCb) { successCb(); } }, fail: (error: any) => { console.log(error); const errorCb = this.callbacks.get('error'); if (errorCb) { errorCb(); } }, }); } } } export { Clipboard };