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