PageSourceSearch

https://isomerdesign.com/bower_components/clipboard.js-master/dist/clipboard.js

js isomerdesign.com collected 2026-10-02 06:25:40 UTC 22,399 bytes, 742 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.