PageSourceSearch

https://saturn.tlt.co.jp/pdocs/js/clipboard.js

js tlt.co.jp collected 2026-09-24 18:15:21 UTC 22,700 bytes, 736 lines download raw bytes

1/*!
2 * clipboard.js v1.5.9
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 && this.target) {
438                throw new Error('Multiple attributes declared, use either "target" or "text"');
439            } else if (this.text) {
440                this.selectFake();
441            } else if (this.target) {
442                this.selectTarget();
443            } else {
444                throw new Error('Missing required attributes, use either "target" or "text"');
445            }
446        };
447
448        ClipboardAction.prototype.selectFake = function selectFake() {
449            var _this = this;
450
451            var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
452
453            this.removeFake();
454
455            this.fakeHandler = document.body.addEventListener('click', function () {
456                return _this.removeFake();
457            });
458
459            this.fakeElem = document.createElement('textarea');
460            // Prevent zooming on iOS
461            this.fakeElem.style.fontSize = '12pt';
462            // Reset box model
463            this.fakeElem.style.border = '0';
464            this.fakeElem.style.padding = '0';
465            this.fakeElem.style.margin = '0';
466            // Move element out of screen horizontally
467            this.fakeElem.style.position = 'fixed';
468            this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
469            // Move element to the same position vertically
470            this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
471            this.fakeElem.setAttribute('readonly', '');
472            this.fakeElem.value = this.text;
473
474            document.body.appendChild(this.fakeElem);
475
476            this.selectedText = (0, _select2.default)(this.fakeElem);
477            this.copyText();
478        };
479
480        ClipboardAction.prototype.removeFake = function removeFake() {
481            if (this.fakeHandler) {
482                document.body.removeEventListener('click');
483                this.fakeHandler = null;
484            }
485
486            if (this.fakeElem) {
487                document.body.removeChild(this.fakeElem);
488                this.fakeElem = null;
489            }
490        };
491
492        ClipboardAction.prototype.selectTarget = function selectTarget() {
493            this.selectedText = (0, _select2.default)(this.target);
494            this.copyText();
495        };
496
497        ClipboardAction.prototype.copyText = function copyText() {
498            var succeeded = undefined;
499
500            try {
501                succeeded = document.execCommand(this.action);
502            } catch (err) {
503                succeeded = false;
504            }
505
506            this.handleResult(succeeded);
507        };
508
509        ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
510            if (succeeded) {
511                this.emitter.emit('success', {
512                    action: this.action,
513                    text: this.selectedText,
514                    trigger: this.trigger,
515                    clearSelection: this.clearSelection.bind(this)
516                });
517            } else {
518                this.emitter.emit('error', {
519                    action: this.action,
520                    trigger: this.trigger,
521                    clearSelection: this.clearSelection.bind(this)
522                });
523            }
524        };
525
526        ClipboardAction.prototype.clearSelection = function clearSelection() {
527            if (this.target) {
528                this.target.blur();
529            }
530
531            window.getSelection().removeAllRanges();
532        };
533
534        ClipboardAction.prototype.destroy = function destroy() {
535            this.removeFake();
536        };
537
538        _createClass(ClipboardAction, [{
539            key: 'action',
540            set: function set() {
541                var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
542
543                this._action = action;
544
545                if (this._action !== 'copy' && this._action !== 'cut') {
546                    throw new Error('Invalid "action" value, use either "copy" or "cut"');
547                }
548            },
549            get: function get() {
550                return this._action;
551            }
552        }, {
553            key: 'target',
554            set: function set(target) {
555                if (target !== undefined) {
556                    if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
557                        this._target = target;
558                    } else {
559                        throw new Error('Invalid "target" value, use a valid Element');
560                    }
561                }
562            },
563            get: function get() {
564                return this._target;
565            }
566        }]);
567
568        return ClipboardAction;
569    }();
570
571    module.exports = ClipboardAction;
572});
573
574},{"select":6}],9:[function(require,module,exports){
575(function (global, factory) {
576    if (typeof define === "function" && define.amd) {
577        define(['module', './clipboard-action', 'tiny-emitter', 'good-l
577istener'], factory);
578    } else if (typeof exports !== "undefined") {
579        factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
580    } else {
581        var mod = {
582            exports: {}
583        };
584        factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
585        global.clipboard = mod.exports;
586    }
587})(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
588    'use strict';
589
590    var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
591
592    var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
593
594    var _goodListener2 = _interopRequireDefault(_goodListener);
595
596    function _interopRequireDefault(obj) {
597        return obj && obj.__esModule ? obj : {
598            default: obj
599        };
600    }
601
602    function _classCallCheck(instance, Constructor) {
603        if (!(instance instanceof Constructor)) {
604            throw new TypeError("Cannot call a class as a function");
605        }
606    }
607
608    function _possibleConstructorReturn(self, call) {
609        if (!self) {
610            throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
611        }
612
613        return call && (typeof call === "object" || typeof call === "function") ? call : self;
614    }
615
616    function _inherits(subClass, superClass) {
617        if (typeof superClass !== "function" && superClass !== null) {
618            throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
619        }
620
621        subClass.prototype = Object.create(superClass && superClass.prototype, {
622            constructor: {
623                value: subClass,
624                enumerable: false,
625                writable: true,
626                configurable: true
627            }
628        });
629        if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
630    }
631
632    var Clipboard = function (_Emitter) {
633        _inherits(Clipboard, _Emitter);
634
635        /**
636         * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
637         * @param {Object} options
638         */
639
640        function Clipboard(trigger, options) {
641            _classCallCheck(this, Clipboard);
642
643            var _this = _possibleConstructorReturn(this, _Emitter.call(this));
644
645            _this.resolveOptions(options);
646            _this.listenClick(trigger);
647            return _this;
648        }
649
650        /**
651         * Defines if attributes would be resolved using internal setter functions
652         * or custom functions that were passed in the constructor.
653         * @param {Object} options
654         */
655
656
657        Clipboard.prototype.resolveOptions = function resolveOptions() {
658            var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
659
660            this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
661            this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
662            this.text = typeof options.text === 'function' ? options.text : this.defaultText;
663        };
664
665        Clipboard.prototype.listenClick = function listenClick(trigger) {
666            var _this2 = this;
667
668            this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
669                return _this2.onClick(e);
670            });
671        };
672
673        Clipboard.prototype.onClick = function onClick(e) {
674            var trigger = e.delegateTarget || e.currentTarget;
675
676            if (this.clipboardAction) {
677                this.clipboardAction = null;
678            }
679
680            this.clipboardAction = new _clipboardAction2.default({
681                action: this.action(trigger),
682                target: this.target(trigger),
683                text: this.text(trigger),
684                trigger: trigger,
685                emitter: this
686            });
687        };
688
689        Clipboard.prototype.defaultAction = function defaultAction(trigger) {
690            return getAttributeValue('action', trigger);
691        };
692
693        Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
694            var selector = getAttributeValue('target', trigger);
695
696            if (selector) {
697                return document.querySelector(selector);
698            }
699        };
700
701        Clipboard.prototype.defaultText = function defaultText(trigger) {
702            return getAttributeValue('text', trigger);
703        };
704
705        Clipboard.prototype.destroy = function destroy() {
706            this.listener.destroy();
707
708            if (this.clipboardAction) {
709                this.clipboardAction.destroy();
710                this.clipboardAction = null;
711            }
712        };
713
714        return Clipboard;
715    }(_tinyEmitter2.default);
716
717    /**
718     * Helper function to retrieve attribute value.
719     * @param {String} suffix
720     * @param {Element} element
721     */
722    function getAttributeValue(suffix, element) {
723        var attribute = 'data-clipboard-' + suffix;
724
725        if (!element.hasAttribute(attribute)) {
726            return;
727        }
728
729        return element.getAttribute(attribute);
730    }
731
732    module.exports = Clipboard;
733});
734
735},{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)
736});

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.