PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.0
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / assets / wpuf / vendor / clipboard / clipboard.js

clipboard.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.1.0, at assets/wpuf/vendor/clipboard/clipboard.js

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