vendor/assets/javascripts/clipboard.js in clipboard-rails-1.5.8 vs vendor/assets/javascripts/clipboard.js in clipboard-rails-1.5.9
- old
+ new
@@ -1,7 +1,7 @@
/*!
- * clipboard.js v1.5.8
+ * clipboard.js v1.5.9
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/
(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){
@@ -348,408 +348,389 @@
};
module.exports = E;
},{}],8:[function(require,module,exports){
-'use strict';
+(function (global, factory) {
+ if (typeof define === "function" && define.amd) {
+ define(['module', 'select'], factory);
+ } else if (typeof exports !== "undefined") {
+ factory(module, require('select'));
+ } else {
+ var mod = {
+ exports: {}
+ };
+ factory(mod, global.select);
+ global.clipboardAction = mod.exports;
+ }
+})(this, function (module, _select) {
+ 'use strict';
-exports.__esModule = true;
+ var _select2 = _interopRequireDefault(_select);
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
-
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
-
-var _select = require('select');
-
-var _select2 = _interopRequireDefault(_select);
-
-/**
- * Inner class which performs selection from either `text` or `target`
- * properties and then executes copy or cut operations.
- */
-
-var ClipboardAction = (function () {
- /**
- * @param {Object} options
- */
-
- function ClipboardAction(options) {
- _classCallCheck(this, ClipboardAction);
-
- this.resolveOptions(options);
- this.initSelection();
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : {
+ default: obj
+ };
}
- /**
- * Defines base properties passed from constructor.
- * @param {Object} options
- */
-
- ClipboardAction.prototype.resolveOptions = function resolveOptions() {
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
-
- this.action = options.action;
- this.emitter = options.emitter;
- this.target = options.target;
- this.text = options.text;
- this.trigger = options.trigger;
-
- this.selectedText = '';
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
+ return typeof obj;
+ } : function (obj) {
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
- /**
- * Decides which selection strategy is going to be applied based
- * on the existence of `text` and `target` properties.
- */
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- ClipboardAction.prototype.initSelection = function initSelection() {
- if (this.text && this.target) {
- throw new Error('Multiple attributes declared, use either "target" or "text"');
- } else if (this.text) {
- this.selectFake();
- } else if (this.target) {
- this.selectTarget();
- } else {
- throw new Error('Missing required attributes, use either "target" or "text"');
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
}
- };
- /**
- * Creates a fake textarea element, sets its value from `text` property,
- * and makes a selection on it.
- */
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
- ClipboardAction.prototype.selectFake = function selectFake() {
- var _this = this;
+ var ClipboardAction = function () {
+ /**
+ * @param {Object} options
+ */
- var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
+ function ClipboardAction(options) {
+ _classCallCheck(this, ClipboardAction);
- this.removeFake();
+ this.resolveOptions(options);
+ this.initSelection();
+ }
- this.fakeHandler = document.body.addEventListener('click', function () {
- return _this.removeFake();
- });
+ /**
+ * Defines base properties passed from constructor.
+ * @param {Object} options
+ */
- this.fakeElem = document.createElement('textarea');
- // Prevent zooming on iOS
- this.fakeElem.style.fontSize = '12pt';
- // Reset box model
- this.fakeElem.style.border = '0';
- this.fakeElem.style.padding = '0';
- this.fakeElem.style.margin = '0';
- // Move element out of screen horizontally
- this.fakeElem.style.position = 'absolute';
- this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
- // Move element to the same position vertically
- this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
- this.fakeElem.setAttribute('readonly', '');
- this.fakeElem.value = this.text;
- document.body.appendChild(this.fakeElem);
+ ClipboardAction.prototype.resolveOptions = function resolveOptions() {
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
- this.selectedText = _select2['default'](this.fakeElem);
- this.copyText();
- };
+ this.action = options.action;
+ this.emitter = options.emitter;
+ this.target = options.target;
+ this.text = options.text;
+ this.trigger = options.trigger;
- /**
- * Only removes the fake element after another click event, that way
- * a user can hit `Ctrl+C` to copy because selection still exists.
- */
+ this.selectedText = '';
+ };
- ClipboardAction.prototype.removeFake = function removeFake() {
- if (this.fakeHandler) {
- document.body.removeEventListener('click');
- this.fakeHandler = null;
- }
+ ClipboardAction.prototype.initSelection = function initSelection() {
+ if (this.text && this.target) {
+ throw new Error('Multiple attributes declared, use either "target" or "text"');
+ } else if (this.text) {
+ this.selectFake();
+ } else if (this.target) {
+ this.selectTarget();
+ } else {
+ throw new Error('Missing required attributes, use either "target" or "text"');
+ }
+ };
- if (this.fakeElem) {
- document.body.removeChild(this.fakeElem);
- this.fakeElem = null;
- }
- };
+ ClipboardAction.prototype.selectFake = function selectFake() {
+ var _this = this;
- /**
- * Selects the content from element passed on `target` property.
- */
+ var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
- ClipboardAction.prototype.selectTarget = function selectTarget() {
- this.selectedText = _select2['default'](this.target);
- this.copyText();
- };
+ this.removeFake();
- /**
- * Executes the copy operation based on the current selection.
- */
+ this.fakeHandler = document.body.addEventListener('click', function () {
+ return _this.removeFake();
+ });
- ClipboardAction.prototype.copyText = function copyText() {
- var succeeded = undefined;
+ this.fakeElem = document.createElement('textarea');
+ // Prevent zooming on iOS
+ this.fakeElem.style.fontSize = '12pt';
+ // Reset box model
+ this.fakeElem.style.border = '0';
+ this.fakeElem.style.padding = '0';
+ this.fakeElem.style.margin = '0';
+ // Move element out of screen horizontally
+ this.fakeElem.style.position = 'fixed';
+ this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
+ // Move element to the same position vertically
+ this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
+ this.fakeElem.setAttribute('readonly', '');
+ this.fakeElem.value = this.text;
- try {
- succeeded = document.execCommand(this.action);
- } catch (err) {
- succeeded = false;
- }
+ document.body.appendChild(this.fakeElem);
- this.handleResult(succeeded);
- };
+ this.selectedText = (0, _select2.default)(this.fakeElem);
+ this.copyText();
+ };
- /**
- * Fires an event based on the copy operation result.
- * @param {Boolean} succeeded
- */
+ ClipboardAction.prototype.removeFake = function removeFake() {
+ if (this.fakeHandler) {
+ document.body.removeEventListener('click');
+ this.fakeHandler = null;
+ }
- ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
- if (succeeded) {
- this.emitter.emit('success', {
- action: this.action,
- text: this.selectedText,
- trigger: this.trigger,
- clearSelection: this.clearSelection.bind(this)
- });
- } else {
- this.emitter.emit('error', {
- action: this.action,
- trigger: this.trigger,
- clearSelection: this.clearSelection.bind(this)
- });
- }
- };
+ if (this.fakeElem) {
+ document.body.removeChild(this.fakeElem);
+ this.fakeElem = null;
+ }
+ };
- /**
- * Removes current selection and focus from `target` element.
- */
+ ClipboardAction.prototype.selectTarget = function selectTarget() {
+ this.selectedText = (0, _select2.default)(this.target);
+ this.copyText();
+ };
- ClipboardAction.prototype.clearSelection = function clearSelection() {
- if (this.target) {
- this.target.blur();
- }
+ ClipboardAction.prototype.copyText = function copyText() {
+ var succeeded = undefined;
- window.getSelection().removeAllRanges();
- };
+ try {
+ succeeded = document.execCommand(this.action);
+ } catch (err) {
+ succeeded = false;
+ }
- /**
- * Sets the `action` to be performed which can be either 'copy' or 'cut'.
- * @param {String} action
- */
+ this.handleResult(succeeded);
+ };
- /**
- * Destroy lifecycle.
- */
+ ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
+ if (succeeded) {
+ this.emitter.emit('success', {
+ action: this.action,
+ text: this.selectedText,
+ trigger: this.trigger,
+ clearSelection: this.clearSelection.bind(this)
+ });
+ } else {
+ this.emitter.emit('error', {
+ action: this.action,
+ trigger: this.trigger,
+ clearSelection: this.clearSelection.bind(this)
+ });
+ }
+ };
- ClipboardAction.prototype.destroy = function destroy() {
- this.removeFake();
- };
+ ClipboardAction.prototype.clearSelection = function clearSelection() {
+ if (this.target) {
+ this.target.blur();
+ }
- _createClass(ClipboardAction, [{
- key: 'action',
- set: function set() {
- var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
+ window.getSelection().removeAllRanges();
+ };
- this._action = action;
+ ClipboardAction.prototype.destroy = function destroy() {
+ this.removeFake();
+ };
- if (this._action !== 'copy' && this._action !== 'cut') {
- throw new Error('Invalid "action" value, use either "copy" or "cut"');
- }
- },
+ _createClass(ClipboardAction, [{
+ key: 'action',
+ set: function set() {
+ var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
- /**
- * Gets the `action` property.
- * @return {String}
- */
- get: function get() {
- return this._action;
- }
+ this._action = action;
- /**
- * Sets the `target` property using an element
- * that will be have its content copied.
- * @param {Element} target
- */
- }, {
- key: 'target',
- set: function set(target) {
- if (target !== undefined) {
- if (target && typeof target === 'object' && target.nodeType === 1) {
- this._target = target;
- } else {
- throw new Error('Invalid "target" value, use a valid Element');
+ if (this._action !== 'copy' && this._action !== 'cut') {
+ throw new Error('Invalid "action" value, use either "copy" or "cut"');
}
+ },
+ get: function get() {
+ return this._action;
}
- },
+ }, {
+ key: 'target',
+ set: function set(target) {
+ if (target !== undefined) {
+ if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
+ this._target = target;
+ } else {
+ throw new Error('Invalid "target" value, use a valid Element');
+ }
+ }
+ },
+ get: function get() {
+ return this._target;
+ }
+ }]);
- /**
- * Gets the `target` property.
- * @return {String|HTMLElement}
- */
- get: function get() {
- return this._target;
- }
- }]);
+ return ClipboardAction;
+ }();
- return ClipboardAction;
-})();
+ module.exports = ClipboardAction;
+});
-exports['default'] = ClipboardAction;
-module.exports = exports['default'];
-
},{"select":6}],9:[function(require,module,exports){
-'use strict';
+(function (global, factory) {
+ if (typeof define === "function" && define.amd) {
+ define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
+ } else if (typeof exports !== "undefined") {
+ factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
+ } else {
+ var mod = {
+ exports: {}
+ };
+ factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
+ global.clipboard = mod.exports;
+ }
+})(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
+ 'use strict';
-exports.__esModule = true;
+ var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+ var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ var _goodListener2 = _interopRequireDefault(_goodListener);
-function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : {
+ default: obj
+ };
+ }
-var _clipboardAction = require('./clipboard-action');
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
-var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
+ function _possibleConstructorReturn(self, call) {
+ if (!self) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
-var _tinyEmitter = require('tiny-emitter');
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
+ }
-var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
+ function _inherits(subClass, superClass) {
+ if (typeof superClass !== "function" && superClass !== null) {
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
+ }
-var _goodListener = require('good-listener');
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
+ constructor: {
+ value: subClass,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
+ }
-var _goodListener2 = _interopRequireDefault(_goodListener);
+ var Clipboard = function (_Emitter) {
+ _inherits(Clipboard, _Emitter);
-/**
- * Base class which takes one or more elements, adds event listeners to them,
- * and instantiates a new `ClipboardAction` on each click.
- */
+ /**
+ * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
+ * @param {Object} options
+ */
-var Clipboard = (function (_Emitter) {
- _inherits(Clipboard, _Emitter);
+ function Clipboard(trigger, options) {
+ _classCallCheck(this, Clipboard);
- /**
- * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
- * @param {Object} options
- */
+ var _this = _possibleConstructorReturn(this, _Emitter.call(this));
- function Clipboard(trigger, options) {
- _classCallCheck(this, Clipboard);
+ _this.resolveOptions(options);
+ _this.listenClick(trigger);
+ return _this;
+ }
- _Emitter.call(this);
+ /**
+ * Defines if attributes would be resolved using internal setter functions
+ * or custom functions that were passed in the constructor.
+ * @param {Object} options
+ */
- this.resolveOptions(options);
- this.listenClick(trigger);
- }
- /**
- * Helper function to retrieve attribute value.
- * @param {String} suffix
- * @param {Element} element
- */
+ Clipboard.prototype.resolveOptions = function resolveOptions() {
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
- /**
- * Defines if attributes would be resolved using internal setter functions
- * or custom functions that were passed in the constructor.
- * @param {Object} options
- */
+ this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
+ this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
+ this.text = typeof options.text === 'function' ? options.text : this.defaultText;
+ };
- Clipboard.prototype.resolveOptions = function resolveOptions() {
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
+ Clipboard.prototype.listenClick = function listenClick(trigger) {
+ var _this2 = this;
- this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
- this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
- this.text = typeof options.text === 'function' ? options.text : this.defaultText;
- };
+ this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
+ return _this2.onClick(e);
+ });
+ };
- /**
- * Adds a click event listener to the passed trigger.
- * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
- */
+ Clipboard.prototype.onClick = function onClick(e) {
+ var trigger = e.delegateTarget || e.currentTarget;
- Clipboard.prototype.listenClick = function listenClick(trigger) {
- var _this = this;
+ if (this.clipboardAction) {
+ this.clipboardAction = null;
+ }
- this.listener = _goodListener2['default'](trigger, 'click', function (e) {
- return _this.onClick(e);
- });
- };
+ this.clipboardAction = new _clipboardAction2.default({
+ action: this.action(trigger),
+ target: this.target(trigger),
+ text: this.text(trigger),
+ trigger: trigger,
+ emitter: this
+ });
+ };
- /**
- * Defines a new `ClipboardAction` on each click event.
- * @param {Event} e
- */
+ Clipboard.prototype.defaultAction = function defaultAction(trigger) {
+ return getAttributeValue('action', trigger);
+ };
- Clipboard.prototype.onClick = function onClick(e) {
- var trigger = e.delegateTarget || e.currentTarget;
+ Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
+ var selector = getAttributeValue('target', trigger);
- if (this.clipboardAction) {
- this.clipboardAction = null;
- }
+ if (selector) {
+ return document.querySelector(selector);
+ }
+ };
- this.clipboardAction = new _clipboardAction2['default']({
- action: this.action(trigger),
- target: this.target(trigger),
- text: this.text(trigger),
- trigger: trigger,
- emitter: this
- });
- };
+ Clipboard.prototype.defaultText = function defaultText(trigger) {
+ return getAttributeValue('text', trigger);
+ };
- /**
- * Default `action` lookup function.
- * @param {Element} trigger
- */
+ Clipboard.prototype.destroy = function destroy() {
+ this.listener.destroy();
- Clipboard.prototype.defaultAction = function defaultAction(trigger) {
- return getAttributeValue('action', trigger);
- };
+ if (this.clipboardAction) {
+ this.clipboardAction.destroy();
+ this.clipboardAction = null;
+ }
+ };
- /**
- * Default `target` lookup function.
- * @param {Element} trigger
- */
+ return Clipboard;
+ }(_tinyEmitter2.default);
- Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
- var selector = getAttributeValue('target', trigger);
-
- if (selector) {
- return document.querySelector(selector);
- }
- };
-
/**
- * Default `text` lookup function.
- * @param {Element} trigger
+ * Helper function to retrieve attribute value.
+ * @param {String} suffix
+ * @param {Element} element
*/
+ function getAttributeValue(suffix, element) {
+ var attribute = 'data-clipboard-' + suffix;
- Clipboard.prototype.defaultText = function defaultText(trigger) {
- return getAttributeValue('text', trigger);
- };
-
- /**
- * Destroy lifecycle.
- */
-
- Clipboard.prototype.destroy = function destroy() {
- this.listener.destroy();
-
- if (this.clipboardAction) {
- this.clipboardAction.destroy();
- this.clipboardAction = null;
+ if (!element.hasAttribute(attribute)) {
+ return;
}
- };
- return Clipboard;
-})(_tinyEmitter2['default']);
-
-exports['default'] = Clipboard;
-function getAttributeValue(suffix, element) {
- var attribute = 'data-clipboard-' + suffix;
-
- if (!element.hasAttribute(attribute)) {
- return;
+ return element.getAttribute(attribute);
}
- return element.getAttribute(attribute);
-}
-module.exports = exports['default'];
+ module.exports = Clipboard;
+});
},{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)
-});
\ No newline at end of file
+});