scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
1 | /*! |
1 | /*! |
|
2 | * clipboard.js v1.6.1 |
2 | * clipboard.js v1.7.1 |
|
3 | * https://zenorocha.github.io/clipboard.js |
3 | * https://zenorocha.github.io/clipboard.js |
|
4 | * |
4 | * |
|
5 | * Licensed MIT © Zeno Rocha |
5 | * Licensed MIT © Zeno Rocha |
|
6 | */ |
6 | */ |
|
7 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
7 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
|
8 | var DOCUMENT_NODE_TYPE = 9; |
8 | var DOCUMENT_NODE_TYPE = 9; |
|
9 | |
9 | |
|
10 | /** |
10 | /** |
|
11 | * A polyfill for Element.matches() |
11 | * A polyfill for Element.matches() |
|
12 | */ |
12 | */ |
|
13 | if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
13 | if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
14 | var proto = Element.prototype; |
14 | var proto = Element.prototype; |
|
15 | |
15 | |
|
16 | proto.matches = proto.matchesSelector || |
16 | proto.matches = proto.matchesSelector || |
|
17 | proto.mozMatchesSelector || |
17 | proto.mozMatchesSelector || |
|
18 | proto.msMatchesSelector || |
18 | proto.msMatchesSelector || |
|
19 | proto.oMatchesSelector || |
19 | proto.oMatchesSelector || |
|
20 | proto.webkitMatchesSelector; |
20 | proto.webkitMatchesSelector; |
|
21 | } |
21 | } |
|
22 | |
22 | |
|
23 | /** |
23 | /** |
|
24 | * Finds the closest parent that matches a selector. |
24 | * Finds the closest parent that matches a selector. |
|
25 | * |
25 | * |
|
26 | * @param {Element} element |
26 | * @param {Element} element |
|
27 | * @param {String} selector |
27 | * @param {String} selector |
|
28 | * @return {Function} |
28 | * @return {Function} |
|
29 | */ |
29 | */ |
|
30 | function closest (element, selector) { |
30 | function closest (element, selector) { |
|
31 | while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
31 | while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
- | 32 | if (typeof element.matches === 'function' && |
||
32 | if (element.matches(selector)) return element; |
33 | element.matches(selector)) { |
|
- | 34 | return element; |
||
- | 35 | } |
||
33 | element = element.parentNode; |
36 | element = element.parentNode; |
|
34 | } |
37 | } |
|
35 | } |
38 | } |
|
36 | |
39 | |
|
37 | module.exports = closest; |
40 | module.exports = closest; |
|
38 | |
41 | |
|
39 | },{}],2:[function(require,module,exports){ |
42 | },{}],2:[function(require,module,exports){ |
|
40 | var closest = require('./closest'); |
43 | var closest = require('./closest'); |
|
41 | |
44 | |
|
42 | /** |
45 | /** |
|
43 | * Delegates event to a selector. |
46 | * Delegates event to a selector. |
|
44 | * |
47 | * |
|
45 | * @param {Element} element |
48 | * @param {Element} element |
|
46 | * @param {String} selector |
49 | * @param {String} selector |
|
47 | * @param {String} type |
50 | * @param {String} type |
|
48 | * @param {Function} callback |
51 | * @param {Function} callback |
|
49 | * @param {Boolean} useCapture |
52 | * @param {Boolean} useCapture |
|
50 | * @return {Object} |
53 | * @return {Object} |
|
51 | */ |
54 | */ |
|
52 | function delegate(element, selector, type, callback, useCapture) { |
55 | function delegate(element, selector, type, callback, useCapture) { |
|
53 | var listenerFn = listener.apply(this, arguments); |
56 | var listenerFn = listener.apply(this, arguments); |
|
54 | |
57 | |
|
55 | element.addEventListener(type, listenerFn, useCapture); |
58 | element.addEventListener(type, listenerFn, useCapture); |
|
56 | |
59 | |
|
57 | return { |
60 | return { |
|
58 | destroy: function() { |
61 | destroy: function() { |
|
59 | element.removeEventListener(type, listenerFn, useCapture); |
62 | element.removeEventListener(type, listenerFn, useCapture); |
|
60 | } |
63 | } |
|
61 | } |
64 | } |
|
62 | } |
65 | } |
|
63 | |
66 | |
|
64 | /** |
67 | /** |
|
65 | * Finds closest match and invokes callback. |
68 | * Finds closest match and invokes callback. |
|
66 | * |
69 | * |
|
67 | * @param {Element} element |
70 | * @param {Element} element |
|
68 | * @param {String} selector |
71 | * @param {String} selector |
|
69 | * @param {String} type |
72 | * @param {String} type |
|
70 | * @param {Function} callback |
73 | * @param {Function} callback |
|
71 | * @return {Function} |
74 | * @return {Function} |
|
72 | */ |
75 | */ |
|
73 | function listener(element, selector, type, callback) { |
76 | function listener(element, selector, type, callback) { |
|
74 | return function(e) { |
77 | return function(e) { |
|
75 | e.delegateTarget = closest(e.target, selector); |
78 | e.delegateTarget = closest(e.target, selector); |
|
76 | |
79 | |
|
77 | if (e.delegateTarget) { |
80 | if (e.delegateTarget) { |
|
78 | callback.call(element, e); |
81 | callback.call(element, e); |
|
79 | } |
82 | } |
|
80 | } |
83 | } |
|
81 | } |
84 | } |
|
82 | |
85 | |
|
83 | module.exports = delegate; |
86 | module.exports = delegate; |
|
84 | |
87 | |
|
85 | },{"./closest":1}],3:[function(require,module,exports){ |
88 | },{"./closest":1}],3:[function(require,module,exports){ |
|
86 | /** |
89 | /** |
|
87 | * Check if argument is a HTML element. |
90 | * Check if argument is a HTML element. |
|
88 | * |
91 | * |
|
89 | * @param {Object} value |
92 | * @param {Object} value |
|
90 | * @return {Boolean} |
93 | * @return {Boolean} |
|
91 | */ |
94 | */ |
|
92 | exports.node = function(value) { |
95 | exports.node = function(value) { |
|
93 | return value !== undefined |
96 | return value !== undefined |
|
94 | && value instanceof HTMLElement |
97 | && value instanceof HTMLElement |
|
95 | && value.nodeType === 1; |
98 | && value.nodeType === 1; |
|
96 | }; |
99 | }; |
|
97 | |
100 | |
|
98 | /** |
101 | /** |
|
99 | * Check if argument is a list of HTML elements. |
102 | * Check if argument is a list of HTML elements. |
|
100 | * |
103 | * |
|
101 | * @param {Object} value |
104 | * @param {Object} value |
|
102 | * @return {Boolean} |
105 | * @return {Boolean} |
|
103 | */ |
106 | */ |
|
104 | exports.nodeList = function(value) { |
107 | exports.nodeList = function(value) { |
|
105 | var type = Object.prototype.toString.call(value); |
108 | var type = Object.prototype.toString.call(value); |
|
106 | |
109 | |
|
107 | return value !== undefined |
110 | return value !== undefined |
|
108 | && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
111 | && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
|
109 | && ('length' in value) |
112 | && ('length' in value) |
|
110 | && (value.length === 0 || exports.node(value[0])); |
113 | && (value.length === 0 || exports.node(value[0])); |
|
111 | }; |
114 | }; |
|
112 | |
115 | |
|
113 | /** |
116 | /** |
|
114 | * Check if argument is a string. |
117 | * Check if argument is a string. |
|
115 | * |
118 | * |
|
116 | * @param {Object} value |
119 | * @param {Object} value |
|
117 | * @return {Boolean} |
120 | * @return {Boolean} |
|
118 | */ |
121 | */ |
|
119 | exports.string = function(value) { |
122 | exports.string = function(value) { |
|
120 | return typeof value === 'string' |
123 | return typeof value === 'string' |
|
121 | || value instanceof String; |
124 | || value instanceof String; |
|
122 | }; |
125 | }; |
|
123 | |
126 | |
|
124 | /** |
127 | /** |
|
125 | * Check if argument is a function. |
128 | * Check if argument is a function. |
|
126 | * |
129 | * |
|
127 | * @param {Object} value |
130 | * @param {Object} value |
|
128 | * @return {Boolean} |
131 | * @return {Boolean} |
|
129 | */ |
132 | */ |
|
130 | exports.fn = function(value) { |
133 | exports.fn = function(value) { |
|
131 | var type = Object.prototype.toString.call(value); |
134 | var type = Object.prototype.toString.call(value); |
|
132 | |
135 | |
|
133 | return type === '[object Function]'; |
136 | return type === '[object Function]'; |
|
134 | }; |
137 | }; |
|
135 | |
138 | |
|
136 | },{}],4:[function(require,module,exports){ |
139 | },{}],4:[function(require,module,exports){ |
|
137 | var is = require('./is'); |
140 | var is = require('./is'); |
|
138 | var delegate = require('delegate'); |
141 | var delegate = require('delegate'); |
|
139 | |
142 | |
|
140 | /** |
143 | /** |
|
141 | * Validates all params and calls the right |
144 | * Validates all params and calls the right |
|
142 | * listener function based on its target type. |
145 | * listener function based on its target type. |
|
143 | * |
146 | * |
|
144 | * @param {String|HTMLElement|HTMLCollection|NodeList} target |
147 | * @param {String|HTMLElement|HTMLCollection|NodeList} target |
|
145 | * @param {String} type |
148 | * @param {String} type |
|
146 | * @param {Function} callback |
149 | * @param {Function} callback |
|
147 | * @return {Object} |
150 | * @return {Object} |
|
148 | */ |
151 | */ |
|
149 | function listen(target, type, callback) { |
152 | function listen(target, type, callback) { |
|
150 | if (!target && !type && !callback) { |
153 | if (!target && !type && !callback) { |
|
151 | throw new Error('Missing required arguments'); |
154 | throw new Error('Missing required arguments'); |
|
152 | } |
155 | } |
|
153 | |
156 | |
|
154 | if (!is.string(type)) { |
157 | if (!is.string(type)) { |
|
155 | throw new TypeError('Second argument must be a String'); |
158 | throw new TypeError('Second argument must be a String'); |
|
156 | } |
159 | } |
|
157 | |
160 | |
|
158 | if (!is.fn(callback)) { |
161 | if (!is.fn(callback)) { |
|
159 | throw new TypeError('Third argument must be a Function'); |
162 | throw new TypeError('Third argument must be a Function'); |
|
160 | } |
163 | } |
|
161 | |
164 | |
|
162 | if (is.node(target)) { |
165 | if (is.node(target)) { |
|
163 | return listenNode(target, type, callback); |
166 | return listenNode(target, type, callback); |
|
164 | } |
167 | } |
|
165 | else if (is.nodeList(target)) { |
168 | else if (is.nodeList(target)) { |
|
166 | return listenNodeList(target, type, callback); |
169 | return listenNodeList(target, type, callback); |
|
167 | } |
170 | } |
|
168 | else if (is.string(target)) { |
171 | else if (is.string(target)) { |
|
169 | return listenSelector(target, type, callback); |
172 | return listenSelector(target, type, callback); |
|
170 | } |
173 | } |
|
171 | else { |
174 | else { |
|
172 | throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
175 | throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
|
173 | } |
176 | } |
|
174 | } |
177 | } |
|
175 | |
178 | |
|
176 | /** |
179 | /** |
|
177 | * Adds an event listener to a HTML element |
180 | * Adds an event listener to a HTML element |
|
178 | * and returns a remove listener function. |
181 | * and returns a remove listener function. |
|
179 | * |
182 | * |
|
180 | * @param {HTMLElement} node |
183 | * @param {HTMLElement} node |
|
181 | * @param {String} type |
184 | * @param {String} type |
|
182 | * @param {Function} callback |
185 | * @param {Function} callback |
|
183 | * @return {Object} |
186 | * @return {Object} |
|
184 | */ |
187 | */ |
|
185 | function listenNode(node, type, callback) { |
188 | function listenNode(node, type, callback) { |
|
186 | node.addEventListener(type, callback); |
189 | node.addEventListener(type, callback); |
|
187 | |
190 | |
|
188 | return { |
191 | return { |
|
189 | destroy: function() { |
192 | destroy: function() { |
|
190 | node.removeEventListener(type, callback); |
193 | node.removeEventListener(type, callback); |
|
191 | } |
194 | } |
|
192 | } |
195 | } |
|
193 | } |
196 | } |
|
194 | |
197 | |
|
195 | /** |
198 | /** |
|
196 | * Add an event listener to a list of HTML elements |
199 | * Add an event listener to a list of HTML elements |
|
197 | * and returns a remove listener function. |
200 | * and returns a remove listener function. |
|
198 | * |
201 | * |
|
199 | * @param {NodeList|HTMLCollection} nodeList |
202 | * @param {NodeList|HTMLCollection} nodeList |
|
200 | * @param {String} type |
203 | * @param {String} type |
|
201 | * @param {Function} callback |
204 | * @param {Function} callback |
|
202 | * @return {Object} |
205 | * @return {Object} |
|
203 | */ |
206 | */ |
|
204 | function listenNodeList(nodeList, type, callback) { |
207 | function listenNodeList(nodeList, type, callback) { |
|
205 | Array.prototype.forEach.call(nodeList, function(node) { |
208 | Array.prototype.forEach.call(nodeList, function(node) { |
|
206 | node.addEventListener(type, callback); |
209 | node.addEventListener(type, callback); |
|
207 | }); |
210 | }); |
|
208 | |
211 | |
|
209 | return { |
212 | return { |
|
210 | destroy: function() { |
213 | destroy: function() { |
|
211 | Array.prototype.forEach.call(nodeList, function(node) { |
214 | Array.prototype.forEach.call(nodeList, function(node) { |
|
212 | node.removeEventListener(type, callback); |
215 | node.removeEventListener(type, callback); |
|
213 | }); |
216 | }); |
|
214 | } |
217 | } |
|
215 | } |
218 | } |
|
216 | } |
219 | } |
|
217 | |
220 | |
|
218 | /** |
221 | /** |
|
219 | * Add an event listener to a selector |
222 | * Add an event listener to a selector |
|
220 | * and returns a remove listener function. |
223 | * and returns a remove listener function. |
|
221 | * |
224 | * |
|
222 | * @param {String} selector |
225 | * @param {String} selector |
|
223 | * @param {String} type |
226 | * @param {String} type |
|
224 | * @param {Function} callback |
227 | * @param {Function} callback |
|
225 | * @return {Object} |
228 | * @return {Object} |
|
226 | */ |
229 | */ |
|
227 | function listenSelector(selector, type, callback) { |
230 | function listenSelector(selector, type, callback) { |
|
228 | return delegate(document.body, selector, type, callback); |
231 | return delegate(document.body, selector, type, callback); |
|
229 | } |
232 | } |
|
230 | |
233 | |
|
231 | module.exports = listen; |
234 | module.exports = listen; |
|
232 | |
235 | |
|
233 | },{"./is":3,"delegate":2}],5:[function(require,module,exports){ |
236 | },{"./is":3,"delegate":2}],5:[function(require,module,exports){ |
|
234 | function select(element) { |
237 | function select(element) { |
|
235 | var selectedText; |
238 | var selectedText; |
|
236 | |
239 | |
|
237 | if (element.nodeName === 'SELECT') { |
240 | if (element.nodeName === 'SELECT') { |
|
238 | element.focus(); |
241 | element.focus(); |
|
239 | |
242 | |
|
240 | selectedText = element.value; |
243 | selectedText = element.value; |
|
241 | } |
244 | } |
|
242 | else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
245 | else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
|
243 | var isReadOnly = element.hasAttribute('readonly'); |
246 | var isReadOnly = element.hasAttribute('readonly'); |
|
244 | |
247 | |
|
245 | if (!isReadOnly) { |
248 | if (!isReadOnly) { |
|
246 | element.setAttribute('readonly', ''); |
249 | element.setAttribute('readonly', ''); |
|
247 | } |
250 | } |
|
248 | |
251 | |
|
249 | element.select(); |
252 | element.select(); |
|
250 | element.setSelectionRange(0, element.value.length); |
253 | element.setSelectionRange(0, element.value.length); |
|
251 | |
254 | |
|
252 | if (!isReadOnly) { |
255 | if (!isReadOnly) { |
|
253 | element.removeAttribute('readonly'); |
256 | element.removeAttribute('readonly'); |
|
254 | } |
257 | } |
|
255 | |
258 | |
|
256 | selectedText = element.value; |
259 | selectedText = element.value; |
|
257 | } |
260 | } |
|
258 | else { |
261 | else { |
|
259 | if (element.hasAttribute('contenteditable')) { |
262 | if (element.hasAttribute('contenteditable')) { |
|
260 | element.focus(); |
263 | element.focus(); |
|
261 | } |
264 | } |
|
262 | |
265 | |
|
263 | var selection = window.getSelection(); |
266 | var selection = window.getSelection(); |
|
264 | var range = document.createRange(); |
267 | var range = document.createRange(); |
|
265 | |
268 | |
|
266 | range.selectNodeContents(element); |
269 | range.selectNodeContents(element); |
|
267 | selection.removeAllRanges(); |
270 | selection.removeAllRanges(); |
|
268 | selection.addRange(range); |
271 | selection.addRange(range); |
|
269 | |
272 | |
|
270 | selectedText = selection.toString(); |
273 | selectedText = selection.toString(); |
|
271 | } |
274 | } |
|
272 | |
275 | |
|
273 | return selectedText; |
276 | return selectedText; |
|
274 | } |
277 | } |
|
275 | |
278 | |
|
276 | module.exports = select; |
279 | module.exports = select; |
|
277 | |
280 | |
|
278 | },{}],6:[function(require,module,exports){ |
281 | },{}],6:[function(require,module,exports){ |
|
279 | function E () { |
282 | function E () { |
|
280 | // Keep this empty so it's easier to inherit from |
283 | // Keep this empty so it's easier to inherit from |
|
281 | // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
284 | // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
|
282 | } |
285 | } |
|
283 | |
286 | |
|
284 | E.prototype = { |
287 | E.prototype = { |
|
285 | on: function (name, callback, ctx) { |
288 | on: function (name, callback, ctx) { |
|
286 | var e = this.e || (this.e = {}); |
289 | var e = this.e || (this.e = {}); |
|
287 | |
290 | |
|
288 | (e[name] || (e[name] = [])).push({ |
291 | (e[name] || (e[name] = [])).push({ |
|
289 | fn: callback, |
292 | fn: callback, |
|
290 | ctx: ctx |
293 | ctx: ctx |
|
291 | }); |
294 | }); |
|
292 | |
295 | |
|
293 | return this; |
296 | return this; |
|
294 | }, |
297 | }, |
|
295 | |
298 | |
|
296 | once: function (name, callback, ctx) { |
299 | once: function (name, callback, ctx) { |
|
297 | var self = this; |
300 | var self = this; |
|
298 | function listener () { |
301 | function listener () { |
|
299 | self.off(name, listener); |
302 | self.off(name, listener); |
|
300 | callback.apply(ctx, arguments); |
303 | callback.apply(ctx, arguments); |
|
301 | }; |
304 | }; |
|
302 | |
305 | |
|
303 | listener._ = callback |
306 | listener._ = callback |
|
304 | return this.on(name, listener, ctx); |
307 | return this.on(name, listener, ctx); |
|
305 | }, |
308 | }, |
|
306 | |
309 | |
|
307 | emit: function (name) { |
310 | emit: function (name) { |
|
308 | var data = [].slice.call(arguments, 1); |
311 | var data = [].slice.call(arguments, 1); |
|
309 | var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
312 | var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
|
310 | var i = 0; |
313 | var i = 0; |
|
311 | var len = evtArr.length; |
314 | var len = evtArr.length; |
|
312 | |
315 | |
|
313 | for (i; i < len; i++) { |
316 | for (i; i < len; i++) { |
|
314 | evtArr[i].fn.apply(evtArr[i].ctx, data); |
317 | evtArr[i].fn.apply(evtArr[i].ctx, data); |
|
315 | } |
318 | } |
|
316 | |
319 | |
|
317 | return this; |
320 | return this; |
|
318 | }, |
321 | }, |
|
319 | |
322 | |
|
320 | off: function (name, callback) { |
323 | off: function (name, callback) { |
|
321 | var e = this.e || (this.e = {}); |
324 | var e = this.e || (this.e = {}); |
|
322 | var evts = e[name]; |
325 | var evts = e[name]; |
|
323 | var liveEvents = []; |
326 | var liveEvents = []; |
|
324 | |
327 | |
|
325 | if (evts && callback) { |
328 | if (evts && callback) { |
|
326 | for (var i = 0, len = evts.length; i < len; i++) { |
329 | for (var i = 0, len = evts.length; i < len; i++) { |
|
327 | if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
330 | if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
|
328 | liveEvents.push(evts[i]); |
331 | liveEvents.push(evts[i]); |
|
329 | } |
332 | } |
|
330 | } |
333 | } |
|
331 | |
334 | |
|
332 | // Remove event from queue to prevent memory leak |
335 | // Remove event from queue to prevent memory leak |
|
333 | // Suggested by https://github.com/lazd |
336 | // Suggested by https://github.com/lazd |
|
334 | // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
337 | // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
|
335 | |
338 | |
|
336 | (liveEvents.length) |
339 | (liveEvents.length) |
|
337 | ? e[name] = liveEvents |
340 | ? e[name] = liveEvents |
|
338 | : delete e[name]; |
341 | : delete e[name]; |
|
339 | |
342 | |
|
340 | return this; |
343 | return this; |
|
341 | } |
344 | } |
|
342 | }; |
345 | }; |
|
343 | |
346 | |
|
344 | module.exports = E; |
347 | module.exports = E; |
|
345 | |
348 | |
|
346 | },{}],7:[function(require,module,exports){ |
349 | },{}],7:[function(require,module,exports){ |
|
347 | (function (global, factory) { |
350 | (function (global, factory) { |
|
348 | if (typeof define === "function" && define.amd) { |
351 | if (typeof define === "function" && define.amd) { |
|
349 | define(['module', 'select'], factory); |
352 | define(['module', 'select'], factory); |
|
350 | } else if (typeof exports !== "undefined") { |
353 | } else if (typeof exports !== "undefined") { |
|
351 | factory(module, require('select')); |
354 | factory(module, require('select')); |
|
352 | } else { |
355 | } else { |
|
353 | var mod = { |
356 | var mod = { |
|
354 | exports: {} |
357 | exports: {} |
|
355 | }; |
358 | }; |
|
356 | factory(mod, global.select); |
359 | factory(mod, global.select); |
|
357 | global.clipboardAction = mod.exports; |
360 | global.clipboardAction = mod.exports; |
|
358 | } |
361 | } |
|
359 | })(this, function (module, _select) { |
362 | })(this, function (module, _select) { |
|
360 | 'use strict'; |
363 | 'use strict'; |
|
361 | |
364 | |
|
362 | var _select2 = _interopRequireDefault(_select); |
365 | var _select2 = _interopRequireDefault(_select); |
|
363 | |
366 | |
|
364 | function _interopRequireDefault(obj) { |
367 | function _interopRequireDefault(obj) { |
|
365 | return obj && obj.__esModule ? obj : { |
368 | return obj && obj.__esModule ? obj : { |
|
366 | default: obj |
369 | default: obj |
|
367 | }; |
370 | }; |
|
368 | } |
371 | } |
|
369 | |
372 | |
|
370 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
373 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
|
371 | return typeof obj; |
374 | return typeof obj; |
|
372 | } : function (obj) { |
375 | } : function (obj) { |
|
373 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
376 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
|
374 | }; |
377 | }; |
|
375 | |
378 | |
|
376 | function _classCallCheck(instance, Constructor) { |
379 | function _classCallCheck(instance, Constructor) { |
|
377 | if (!(instance instanceof Constructor)) { |
380 | if (!(instance instanceof Constructor)) { |
|
378 | throw new TypeError("Cannot call a class as a function"); |
381 | throw new TypeError("Cannot call a class as a function"); |
|
379 | } |
382 | } |
|
380 | } |
383 | } |
|
381 | |
384 | |
|
382 | var _createClass = function () { |
385 | var _createClass = function () { |
|
383 | function defineProperties(target, props) { |
386 | function defineProperties(target, props) { |
|
384 | for (var i = 0; i < props.length; i++) { |
387 | for (var i = 0; i < props.length; i++) { |
|
385 | var descriptor = props[i]; |
388 | var descriptor = props[i]; |
|
386 | descriptor.enumerable = descriptor.enumerable || false; |
389 | descriptor.enumerable = descriptor.enumerable || false; |
|
387 | descriptor.configurable = true; |
390 | descriptor.configurable = true; |
|
388 | if ("value" in descriptor) descriptor.writable = true; |
391 | if ("value" in descriptor) descriptor.writable = true; |
|
389 | Object.defineProperty(target, descriptor.key, descriptor); |
392 | Object.defineProperty(target, descriptor.key, descriptor); |
|
390 | } |
393 | } |
|
391 | } |
394 | } |
|
392 | |
395 | |
|
393 | return function (Constructor, protoProps, staticProps) { |
396 | return function (Constructor, protoProps, staticProps) { |
|
394 | if (protoProps) defineProperties(Constructor.prototype, protoProps); |
397 | if (protoProps) defineProperties(Constructor.prototype, protoProps); |
|
395 | if (staticProps) defineProperties(Constructor, staticProps); |
398 | if (staticProps) defineProperties(Constructor, staticProps); |
|
396 | return Constructor; |
399 | return Constructor; |
|
397 | }; |
400 | }; |
|
398 | }(); |
401 | }(); |
|
399 | |
402 | |
|
400 | var ClipboardAction = function () { |
403 | var ClipboardAction = function () { |
|
401 | /** |
404 | /** |
|
402 | * @param {Object} options |
405 | * @param {Object} options |
|
403 | */ |
406 | */ |
|
404 | function ClipboardAction(options) { |
407 | function ClipboardAction(options) { |
|
405 | _classCallCheck(this, ClipboardAction); |
408 | _classCallCheck(this, ClipboardAction); |
|
406 | |
409 | |
|
407 | this.resolveOptions(options); |
410 | this.resolveOptions(options); |
|
408 | this.initSelection(); |
411 | this.initSelection(); |
|
409 | } |
412 | } |
|
410 | |
413 | |
|
411 | /** |
414 | /** |
|
412 | * Defines base properties passed from constructor. |
415 | * Defines base properties passed from constructor. |
|
413 | * @param {Object} options |
416 | * @param {Object} options |
|
414 | */ |
417 | */ |
|
415 | |
418 | |
|
416 | |
419 | |
|
417 | _createClass(ClipboardAction, [{ |
420 | _createClass(ClipboardAction, [{ |
|
418 | key: 'resolveOptions', |
421 | key: 'resolveOptions', |
|
419 | value: function resolveOptions() { |
422 | value: function resolveOptions() { |
|
420 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
423 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
421 | |
424 | |
|
422 | this.action = options.action; |
425 | this.action = options.action; |
|
- | 426 | this.container = options.container; |
||
423 | this.emitter = options.emitter; |
427 | this.emitter = options.emitter; |
|
424 | this.target = options.target; |
428 | this.target = options.target; |
|
425 | this.text = options.text; |
429 | this.text = options.text; |
|
426 | this.trigger = options.trigger; |
430 | this.trigger = options.trigger; |
|
427 | |
431 | |
|
428 | this.selectedText = ''; |
432 | this.selectedText = ''; |
|
429 | } |
433 | } |
|
430 | }, { |
434 | }, { |
|
431 | key: 'initSelection', |
435 | key: 'initSelection', |
|
432 | value: function initSelection() { |
436 | value: function initSelection() { |
|
433 | if (this.text) { |
437 | if (this.text) { |
|
434 | this.selectFake(); |
438 | this.selectFake(); |
|
435 | } else if (this.target) { |
439 | } else if (this.target) { |
|
436 | this.selectTarget(); |
440 | this.selectTarget(); |
|
437 | } |
441 | } |
|
438 | } |
442 | } |
|
439 | }, { |
443 | }, { |
|
440 | key: 'selectFake', |
444 | key: 'selectFake', |
|
441 | value: function selectFake() { |
445 | value: function selectFake() { |
|
442 | var _this = this; |
446 | var _this = this; |
|
443 | |
447 | |
|
444 | var isRTL = document.documentElement.getAttribute('dir') == 'rtl'; |
448 | var isRTL = document.documentElement.getAttribute('dir') == 'rtl'; |
|
445 | |
449 | |
|
446 | this.removeFake(); |
450 | this.removeFake(); |
|
447 | |
451 | |
|
448 | this.fakeHandlerCallback = function () { |
452 | this.fakeHandlerCallback = function () { |
|
449 | return _this.removeFake(); |
453 | return _this.removeFake(); |
|
450 | }; |
454 | }; |
|
451 | this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true; |
455 | this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true; |
|
452 | |
456 | |
|
453 | this.fakeElem = document.createElement('textarea'); |
457 | this.fakeElem = document.createElement('textarea'); |
|
454 | // Prevent zooming on iOS |
458 | // Prevent zooming on iOS |
|
455 | this.fakeElem.style.fontSize = '12pt'; |
459 | this.fakeElem.style.fontSize = '12pt'; |
|
456 | // Reset box model |
460 | // Reset box model |
|
457 | this.fakeElem.style.border = '0'; |
461 | this.fakeElem.style.border = '0'; |
|
458 | this.fakeElem.style.padding = '0'; |
462 | this.fakeElem.style.padding = '0'; |
|
459 | this.fakeElem.style.margin = '0'; |
463 | this.fakeElem.style.margin = '0'; |
|
460 | // Move element out of screen horizontally |
464 | // Move element out of screen horizontally |
|
461 | this.fakeElem.style.position = 'absolute'; |
465 | this.fakeElem.style.position = 'absolute'; |
|
462 | this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; |
466 | this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; |
|
463 | // Move element to the same position vertically |
467 | // Move element to the same position vertically |
|
464 | var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
468 | var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
|
465 | this.fakeElem.style.top = yPosition + 'px'; |
469 | this.fakeElem.style.top = yPosition + 'px'; |
|
466 | |
470 | |
|
467 | this.fakeElem.setAttribute('readonly', ''); |
471 | this.fakeElem.setAttribute('readonly', ''); |
|
468 | this.fakeElem.value = this.text; |
472 | this.fakeElem.value = this.text; |
|
469 | |
473 | |
|
470 | document.body.appendChild(this.fakeElem); |
474 | this.container.appendChild(this.fakeElem); |
|
471 | |
475 | |
|
472 | this.selectedText = (0, _select2.default)(this.fakeElem); |
476 | this.selectedText = (0, _select2.default)(this.fakeElem); |
|
473 | this.copyText(); |
477 | this.copyText(); |
|
474 | } |
478 | } |
|
475 | }, { |
479 | }, { |
|
476 | key: 'removeFake', |
480 | key: 'removeFake', |
|
477 | value: function removeFake() { |
481 | value: function removeFake() { |
|
478 | if (this.fakeHandler) { |
482 | if (this.fakeHandler) { |
|
479 | document.body.removeEventListener('click', this.fakeHandlerCallback); |
483 | this.container.removeEventListener('click', this.fakeHandlerCallback); |
|
480 | this.fakeHandler = null; |
484 | this.fakeHandler = null; |
|
481 | this.fakeHandlerCallback = null; |
485 | this.fakeHandlerCallback = null; |
|
482 | } |
486 | } |
|
483 | |
487 | |
|
484 | if (this.fakeElem) { |
488 | if (this.fakeElem) { |
|
485 | document.body.removeChild(this.fakeElem); |
489 | this.container.removeChild(this.fakeElem); |
|
486 | this.fakeElem = null; |
490 | this.fakeElem = null; |
|
487 | } |
491 | } |
|
488 | } |
492 | } |
|
489 | }, { |
493 | }, { |
|
490 | key: 'selectTarget', |
494 | key: 'selectTarget', |
|
491 | value: function selectTarget() { |
495 | value: function selectTarget() { |
|
492 | this.selectedText = (0, _select2.default)(this.target); |
496 | this.selectedText = (0, _select2.default)(this.target); |
|
493 | this.copyText(); |
497 | this.copyText(); |
|
494 | } |
498 | } |
|
495 | }, { |
499 | }, { |
|
496 | key: 'copyText', |
500 | key: 'copyText', |
|
497 | value: function copyText() { |
501 | value: function copyText() { |
|
498 | var succeeded = void 0; |
502 | var succeeded = void 0; |
|
499 | |
503 | |
|
500 | try { |
504 | try { |
|
501 | succeeded = document.execCommand(this.action); |
505 | succeeded = document.execCommand(this.action); |
|
502 | } catch (err) { |
506 | } catch (err) { |
|
503 | succeeded = false; |
507 | succeeded = false; |
|
504 | } |
508 | } |
|
505 | |
509 | |
|
506 | this.handleResult(succeeded); |
510 | this.handleResult(succeeded); |
|
507 | } |
511 | } |
|
508 | }, { |
512 | }, { |
|
509 | key: 'handleResult', |
513 | key: 'handleResult', |
|
510 | value: function handleResult(succeeded) { |
514 | value: function handleResult(succeeded) { |
|
511 | this.emitter.emit(succeeded ? 'success' : 'error', { |
515 | this.emitter.emit(succeeded ? 'success' : 'error', { |
|
512 | action: this.action, |
516 | action: this.action, |
|
513 | text: this.selectedText, |
517 | text: this.selectedText, |
|
514 | trigger: this.trigger, |
518 | trigger: this.trigger, |
|
515 | clearSelection: this.clearSelection.bind(this) |
519 | clearSelection: this.clearSelection.bind(this) |
|
516 | }); |
520 | }); |
|
517 | } |
521 | } |
|
518 | }, { |
522 | }, { |
|
519 | key: 'clearSelection', |
523 | key: 'clearSelection', |
|
520 | value: function clearSelection() { |
524 | value: function clearSelection() { |
|
521 | if (this.target) { |
525 | if (this.trigger) { |
|
522 | this.target.blur(); |
526 | this.trigger.focus(); |
|
523 | } |
527 | } |
|
524 | |
528 | |
|
525 | window.getSelection().removeAllRanges(); |
529 | window.getSelection().removeAllRanges(); |
|
526 | } |
530 | } |
|
527 | }, { |
531 | }, { |
|
528 | key: 'destroy', |
532 | key: 'destroy', |
|
529 | value: function destroy() { |
533 | value: function destroy() { |
|
530 | this.removeFake(); |
534 | this.removeFake(); |
|
531 | } |
535 | } |
|
532 | }, { |
536 | }, { |
|
533 | key: 'action', |
537 | key: 'action', |
|
534 | set: function set() { |
538 | set: function set() { |
|
535 | var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; |
539 | var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; |
|
536 | |
540 | |
|
537 | this._action = action; |
541 | this._action = action; |
|
538 | |
542 | |
|
539 | if (this._action !== 'copy' && this._action !== 'cut') { |
543 | if (this._action !== 'copy' && this._action !== 'cut') { |
|
540 | throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
544 | throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
|
541 | } |
545 | } |
|
542 | }, |
546 | }, |
|
543 | get: function get() { |
547 | get: function get() { |
|
544 | return this._action; |
548 | return this._action; |
|
545 | } |
549 | } |
|
546 | }, { |
550 | }, { |
|
547 | key: 'target', |
551 | key: 'target', |
|
548 | set: function set(target) { |
552 | set: function set(target) { |
|
549 | if (target !== undefined) { |
553 | if (target !== undefined) { |
|
550 | if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) { |
554 | if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) { |
|
551 | if (this.action === 'copy' && target.hasAttribute('disabled')) { |
555 | if (this.action === 'copy' && target.hasAttribute('disabled')) { |
|
552 | throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
556 | throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
|
553 | } |
557 | } |
|
554 | |
558 | |
|
555 | if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
559 | if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
|
556 | throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
560 | throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
|
557 | } |
561 | } |
|
558 | |
562 | |
|
559 | this._target = target; |
563 | this._target = target; |
|
560 | } else { |
564 | } else { |
|
561 | throw new Error('Invalid "target" value, use a valid Element'); |
565 | throw new Error('Invalid "target" value, use a valid Element'); |
|
562 | } |
566 | } |
|
563 | } |
567 | } |
|
564 | }, |
568 | }, |
|
565 | get: function get() { |
569 | get: function get() { |
|
566 | return this._target; |
570 | return this._target; |
|
567 | } |
571 | } |
|
568 | }]); |
572 | }]); |
|
569 | |
573 | |
|
570 | return ClipboardAction; |
574 | return ClipboardAction; |
|
571 | }(); |
575 | }(); |
|
572 | |
576 | |
|
573 | module.exports = ClipboardAction; |
577 | module.exports = ClipboardAction; |
|
574 | }); |
578 | }); |
|
575 | |
579 | |
|
576 | },{"select":5}],8:[function(require,module,exports){ |
580 | },{"select":5}],8:[function(require,module,exports){ |
|
577 | (function (global, factory) { |
581 | (function (global, factory) { |
|
578 | if (typeof define === "function" && define.amd) { |
582 | if (typeof define === "function" && define.amd) { |
|
579 | define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory); |
583 | define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory); |
|
580 | } else if (typeof exports !== "undefined") { |
584 | } else if (typeof exports !== "undefined") { |
|
581 | factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener')); |
585 | factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener')); |
|
582 | } else { |
586 | } else { |
|
583 | var mod = { |
587 | var mod = { |
|
584 | exports: {} |
588 | exports: {} |
|
585 | }; |
589 | }; |
|
586 | factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener); |
590 | factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener); |
|
587 | global.clipboard = mod.exports; |
591 | global.clipboard = mod.exports; |
|
588 | } |
592 | } |
|
589 | })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) { |
593 | })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) { |
|
590 | 'use strict'; |
594 | 'use strict'; |
|
591 | |
595 | |
|
592 | var _clipboardAction2 = _interopRequireDefault(_clipboardAction); |
596 | var _clipboardAction2 = _interopRequireDefault(_clipboardAction); |
|
593 | |
597 | |
|
594 | var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter); |
598 | var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter); |
|
595 | |
599 | |
|
596 | var _goodListener2 = _interopRequireDefault(_goodListener); |
600 | var _goodListener2 = _interopRequireDefault(_goodListener); |
|
597 | |
601 | |
|
598 | function _interopRequireDefault(obj) { |
602 | function _interopRequireDefault(obj) { |
|
599 | return obj && obj.__esModule ? obj : { |
603 | return obj && obj.__esModule ? obj : { |
|
600 | default: obj |
604 | default: obj |
|
601 | }; |
605 | }; |
|
602 | } |
606 | } |
|
- | 607 | |
||
- | 608 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
||
- | 609 | return typeof obj; |
||
- | 610 | } : function (obj) { |
||
- | 611 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
||
- | 612 | }; |
||
603 | |
613 | |
|
604 | function _classCallCheck(instance, Constructor) { |
614 | function _classCallCheck(instance, Constructor) { |
|
605 | if (!(instance instanceof Constructor)) { |
615 | if (!(instance instanceof Constructor)) { |
|
606 | throw new TypeError("Cannot call a class as a function"); |
616 | throw new TypeError("Cannot call a class as a function"); |
|
607 | } |
617 | } |
|
608 | } |
618 | } |
|
609 | |
619 | |
|
610 | var _createClass = function () { |
620 | var _createClass = function () { |
|
611 | function defineProperties(target, props) { |
621 | function defineProperties(target, props) { |
|
612 | for (var i = 0; i < props.length; i++) { |
622 | for (var i = 0; i < props.length; i++) { |
|
613 | var descriptor = props[i]; |
623 | var descriptor = props[i]; |
|
614 | descriptor.enumerable = descriptor.enumerable || false; |
624 | descriptor.enumerable = descriptor.enumerable || false; |
|
615 | descriptor.configurable = true; |
625 | descriptor.configurable = true; |
|
616 | if ("value" in descriptor) descriptor.writable = true; |
626 | if ("value" in descriptor) descriptor.writable = true; |
|
617 | Object.defineProperty(target, descriptor.key, descriptor); |
627 | Object.defineProperty(target, descriptor.key, descriptor); |
|
618 | } |
628 | } |
|
619 | } |
629 | } |
|
620 | |
630 | |
|
621 | return function (Constructor, protoProps, staticProps) { |
631 | return function (Constructor, protoProps, staticProps) { |
|
622 | if (protoProps) defineProperties(Constructor.prototype, protoProps); |
632 | if (protoProps) defineProperties(Constructor.prototype, protoProps); |
|
623 | if (staticProps) defineProperties(Constructor, staticProps); |
633 | if (staticProps) defineProperties(Constructor, staticProps); |
|
624 | return Constructor; |
634 | return Constructor; |
|
625 | }; |
635 | }; |
|
626 | }(); |
636 | }(); |
|
627 | |
637 | |
|
628 | function _possibleConstructorReturn(self, call) { |
638 | function _possibleConstructorReturn(self, call) { |
|
629 | if (!self) { |
639 | if (!self) { |
|
630 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
640 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
|
631 | } |
641 | } |
|
632 | |
642 | |
|
633 | return call && (typeof call === "object" || typeof call === "function") ? call : self; |
643 | return call && (typeof call === "object" || typeof call === "function") ? call : self; |
|
634 | } |
644 | } |
|
635 | |
645 | |
|
636 | function _inherits(subClass, superClass) { |
646 | function _inherits(subClass, superClass) { |
|
637 | if (typeof superClass !== "function" && superClass !== null) { |
647 | if (typeof superClass !== "function" && superClass !== null) { |
|
638 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); |
648 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); |
|
639 | } |
649 | } |
|
640 | |
650 | |
|
641 | subClass.prototype = Object.create(superClass && superClass.prototype, { |
651 | subClass.prototype = Object.create(superClass && superClass.prototype, { |
|
642 | constructor: { |
652 | constructor: { |
|
643 | value: subClass, |
653 | value: subClass, |
|
644 | enumerable: false, |
654 | enumerable: false, |
|
645 | writable: true, |
655 | writable: true, |
|
646 | configurable: true |
656 | configurable: true |
|
647 | } |
657 | } |
|
648 | }); |
658 | }); |
|
649 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; |
659 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; |
|
650 | } |
660 | } |
|
651 | |
661 | |
|
652 | var Clipboard = function (_Emitter) { |
662 | var Clipboard = function (_Emitter) { |
|
653 | _inherits(Clipboard, _Emitter); |
663 | _inherits(Clipboard, _Emitter); |
|
654 | |
664 | |
|
655 | /** |
665 | /** |
|
656 | * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
666 | * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
657 | * @param {Object} options |
667 | * @param {Object} options |
|
658 | */ |
668 | */ |
|
659 | function Clipboard(trigger, options) { |
669 | function Clipboard(trigger, options) { |
|
660 | _classCallCheck(this, Clipboard); |
670 | _classCallCheck(this, Clipboard); |
|
661 | |
671 | |
|
662 | var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); |
672 | var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); |
|
663 | |
673 | |
|
664 | _this.resolveOptions(options); |
674 | _this.resolveOptions(options); |
|
665 | _this.listenClick(trigger); |
675 | _this.listenClick(trigger); |
|
666 | return _this; |
676 | return _this; |
|
667 | } |
677 | } |
|
668 | |
678 | |
|
669 | /** |
679 | /** |
|
670 | * Defines if attributes would be resolved using internal setter functions |
680 | * Defines if attributes would be resolved using internal setter functions |
|
671 | * or custom functions that were passed in the constructor. |
681 | * or custom functions that were passed in the constructor. |
|
672 | * @param {Object} options |
682 | * @param {Object} options |
|
673 | */ |
683 | */ |
|
674 | |
684 | |
|
675 | |
685 | |
|
676 | _createClass(Clipboard, [{ |
686 | _createClass(Clipboard, [{ |
|
677 | key: 'resolveOptions', |
687 | key: 'resolveOptions', |
|
678 | value: function resolveOptions() { |
688 | value: function resolveOptions() { |
|
679 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
689 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
680 | |
690 | |
|
681 | this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
691 | this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
|
682 | this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
692 | this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
|
683 | this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
693 | this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
|
- | 694 | this.container = _typeof(options.container) === 'object' ? options.container : document.body; |
||
684 | } |
695 | } |
|
685 | }, { |
696 | }, { |
|
686 | key: 'listenClick', |
697 | key: 'listenClick', |
|
687 | value: function listenClick(trigger) { |
698 | value: function listenClick(trigger) { |
|
688 | var _this2 = this; |
699 | var _this2 = this; |
|
689 | |
700 | |
|
690 | this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { |
701 | this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { |
|
691 | return _this2.onClick(e); |
702 | return _this2.onClick(e); |
|
692 | }); |
703 | }); |
|
693 | } |
704 | } |
|
694 | }, { |
705 | }, { |
|
695 | key: 'onClick', |
706 | key: 'onClick', |
|
696 | value: function onClick(e) { |
707 | value: function onClick(e) { |
|
697 | var trigger = e.delegateTarget || e.currentTarget; |
708 | var trigger = e.delegateTarget || e.currentTarget; |
|
698 | |
709 | |
|
699 | if (this.clipboardAction) { |
710 | if (this.clipboardAction) { |
|
700 | this.clipboardAction = null; |
711 | this.clipboardAction = null; |
|
701 | } |
712 | } |
|
702 | |
713 | |
|
703 | this.clipboardAction = new _clipboardAction2.default({ |
714 | this.clipboardAction = new _clipboardAction2.default({ |
|
704 | action: this.action(trigger), |
715 | action: this.action(trigger), |
|
705 | target: this.target(trigger), |
716 | target: this.target(trigger), |
|
706 | text: this.text(trigger), |
717 | text: this.text(trigger), |
|
- | 718 | container: this.container, |
||
707 | trigger: trigger, |
719 | trigger: trigger, |
|
708 | emitter: this |
720 | emitter: this |
|
709 | }); |
721 | }); |
|
710 | } |
722 | } |
|
711 | }, { |
723 | }, { |
|
712 | key: 'defaultAction', |
724 | key: 'defaultAction', |
|
713 | value: function defaultAction(trigger) { |
725 | value: function defaultAction(trigger) { |
|
714 | return getAttributeValue('action', trigger); |
726 | return getAttributeValue('action', trigger); |
|
715 | } |
727 | } |
|
716 | }, { |
728 | }, { |
|
717 | key: 'defaultTarget', |
729 | key: 'defaultTarget', |
|
718 | value: function defaultTarget(trigger) { |
730 | value: function defaultTarget(trigger) { |
|
719 | var selector = getAttributeValue('target', trigger); |
731 | var selector = getAttributeValue('target', trigger); |
|
720 | |
732 | |
|
721 | if (selector) { |
733 | if (selector) { |
|
722 | return document.querySelector(selector); |
734 | return document.querySelector(selector); |
|
723 | } |
735 | } |
|
724 | } |
736 | } |
|
725 | }, { |
737 | }, { |
|
726 | key: 'defaultText', |
738 | key: 'defaultText', |
|
727 | value: function defaultText(trigger) { |
739 | value: function defaultText(trigger) { |
|
728 | return getAttributeValue('text', trigger); |
740 | return getAttributeValue('text', trigger); |
|
729 | } |
741 | } |
|
730 | }, { |
742 | }, { |
|
731 | key: 'destroy', |
743 | key: 'destroy', |
|
732 | value: function destroy() { |
744 | value: function destroy() { |
|
733 | this.listener.destroy(); |
745 | this.listener.destroy(); |
|
734 | |
746 | |
|
735 | if (this.clipboardAction) { |
747 | if (this.clipboardAction) { |
|
736 | this.clipboardAction.destroy(); |
748 | this.clipboardAction.destroy(); |
|
737 | this.clipboardAction = null; |
749 | this.clipboardAction = null; |
|
738 | } |
750 | } |
|
739 | } |
751 | } |
|
740 | }], [{ |
752 | }], [{ |
|
741 | key: 'isSupported', |
753 | key: 'isSupported', |
|
742 | value: function isSupported() { |
754 | value: function isSupported() { |
|
743 | var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
755 | var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
|
744 | |
756 | |
|
745 | var actions = typeof action === 'string' ? [action] : action; |
757 | var actions = typeof action === 'string' ? [action] : action; |
|
746 | var support = !!document.queryCommandSupported; |
758 | var support = !!document.queryCommandSupported; |
|
747 | |
759 | |
|
748 | actions.forEach(function (action) { |
760 | actions.forEach(function (action) { |
|
749 | support = support && !!document.queryCommandSupported(action); |
761 | support = support && !!document.queryCommandSupported(action); |
|
750 | }); |
762 | }); |
|
751 | |
763 | |
|
752 | return support; |
764 | return support; |
|
753 | } |
765 | } |
|
754 | }]); |
766 | }]); |
|
755 | |
767 | |
|
756 | return Clipboard; |
768 | return Clipboard; |
|
757 | }(_tinyEmitter2.default); |
769 | }(_tinyEmitter2.default); |
|
758 | |
770 | |
|
759 | /** |
771 | /** |
|
760 | * Helper function to retrieve attribute value. |
772 | * Helper function to retrieve attribute value. |
|
761 | * @param {String} suffix |
773 | * @param {String} suffix |
|
762 | * @param {Element} element |
774 | * @param {Element} element |
|
763 | */ |
775 | */ |
|
764 | function getAttributeValue(suffix, element) { |
776 | function getAttributeValue(suffix, element) { |
|
765 | var attribute = 'data-clipboard-' + suffix; |
777 | var attribute = 'data-clipboard-' + suffix; |
|
766 | |
778 | |
|
767 | if (!element.hasAttribute(attribute)) { |
779 | if (!element.hasAttribute(attribute)) { |
|
768 | return; |
780 | return; |
|
769 | } |
781 | } |
|
770 | |
782 | |
|
771 | return element.getAttribute(attribute); |
783 | return element.getAttribute(attribute); |
|
772 | } |
784 | } |
|
773 | |
785 | |
|
774 | module.exports = Clipboard; |
786 | module.exports = Clipboard; |
|
775 | }); |
787 | }); |
|
776 | |
788 | |
|
777 | },{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8) |
789 | },{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8) |
|
778 | }); |
790 | }); |
|
779 | |
791 | |
|
780 |
|
792 |
|
|
781 | |
793 | |
|
782 | |
794 | |
|
783 | |
795 | |