mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Merge pull request #703 from realityking/babel7
Upgrade babel to version 7
This commit is contained in:
commit
5ea83e4473
6
.babelrc
6
.babelrc
@ -1,11 +1,9 @@
|
|||||||
{
|
{
|
||||||
"presets": [
|
"presets": [
|
||||||
[
|
[
|
||||||
"env",
|
"@babel/env",
|
||||||
{
|
{
|
||||||
"targets": {
|
"forceAllTransforms": true,
|
||||||
"uglify": true
|
|
||||||
},
|
|
||||||
"modules": false
|
"modules": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
140
dist/clipboard.js
vendored
140
dist/clipboard.js
vendored
@ -513,12 +513,13 @@ var src_select = __webpack_require__(0);
|
|||||||
var select_default = /*#__PURE__*/__webpack_require__.n(src_select);
|
var select_default = /*#__PURE__*/__webpack_require__.n(src_select);
|
||||||
|
|
||||||
// CONCATENATED MODULE: ./src/clipboard-action.js
|
// CONCATENATED MODULE: ./src/clipboard-action.js
|
||||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||||
|
|
||||||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
|
||||||
|
|
||||||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -526,7 +527,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|||||||
* properties and then executes copy or cut operations.
|
* properties and then executes copy or cut operations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var clipboard_action_ClipboardAction = function () {
|
var clipboard_action_ClipboardAction = /*#__PURE__*/function () {
|
||||||
/**
|
/**
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
*/
|
*/
|
||||||
@ -536,7 +537,6 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
this.resolveOptions(options);
|
this.resolveOptions(options);
|
||||||
this.initSelection();
|
this.initSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines base properties passed from constructor.
|
* Defines base properties passed from constructor.
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
@ -544,27 +544,24 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
|
|
||||||
|
|
||||||
_createClass(ClipboardAction, [{
|
_createClass(ClipboardAction, [{
|
||||||
key: 'resolveOptions',
|
key: "resolveOptions",
|
||||||
value: function resolveOptions() {
|
value: function resolveOptions() {
|
||||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||||
|
|
||||||
this.action = options.action;
|
this.action = options.action;
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.emitter = options.emitter;
|
this.emitter = options.emitter;
|
||||||
this.target = options.target;
|
this.target = options.target;
|
||||||
this.text = options.text;
|
this.text = options.text;
|
||||||
this.trigger = options.trigger;
|
this.trigger = options.trigger;
|
||||||
|
|
||||||
this.selectedText = '';
|
this.selectedText = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decides which selection strategy is going to be applied based
|
* Decides which selection strategy is going to be applied based
|
||||||
* on the existence of `text` and `target` properties.
|
* on the existence of `text` and `target` properties.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'initSelection',
|
key: "initSelection",
|
||||||
value: function initSelection() {
|
value: function initSelection() {
|
||||||
if (this.text) {
|
if (this.text) {
|
||||||
this.selectFake();
|
this.selectFake();
|
||||||
@ -572,56 +569,50 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
this.selectTarget();
|
this.selectTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a fake textarea element, sets its value from `text` property,
|
* Creates a fake textarea element, sets its value from `text` property,
|
||||||
* and makes a selection on it.
|
* and makes a selection on it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'selectFake',
|
key: "selectFake",
|
||||||
value: function selectFake() {
|
value: function selectFake() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||||
|
|
||||||
this.removeFake();
|
this.removeFake();
|
||||||
|
|
||||||
this.fakeHandlerCallback = function () {
|
this.fakeHandlerCallback = function () {
|
||||||
return _this.removeFake();
|
return _this.removeFake();
|
||||||
};
|
};
|
||||||
this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
|
|
||||||
|
|
||||||
this.fakeElem = document.createElement('textarea');
|
this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
|
||||||
// Prevent zooming on iOS
|
this.fakeElem = document.createElement('textarea'); // Prevent zooming on iOS
|
||||||
this.fakeElem.style.fontSize = '12pt';
|
|
||||||
// Reset box model
|
this.fakeElem.style.fontSize = '12pt'; // Reset box model
|
||||||
|
|
||||||
this.fakeElem.style.border = '0';
|
this.fakeElem.style.border = '0';
|
||||||
this.fakeElem.style.padding = '0';
|
this.fakeElem.style.padding = '0';
|
||||||
this.fakeElem.style.margin = '0';
|
this.fakeElem.style.margin = '0'; // Move element out of screen horizontally
|
||||||
// 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
|
|
||||||
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
|
||||||
this.fakeElem.style.top = yPosition + 'px';
|
|
||||||
|
|
||||||
|
this.fakeElem.style.position = 'absolute';
|
||||||
|
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
|
||||||
|
|
||||||
|
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
||||||
|
this.fakeElem.style.top = "".concat(yPosition, "px");
|
||||||
this.fakeElem.setAttribute('readonly', '');
|
this.fakeElem.setAttribute('readonly', '');
|
||||||
this.fakeElem.value = this.text;
|
this.fakeElem.value = this.text;
|
||||||
|
|
||||||
this.container.appendChild(this.fakeElem);
|
this.container.appendChild(this.fakeElem);
|
||||||
|
|
||||||
this.selectedText = select_default()(this.fakeElem);
|
this.selectedText = select_default()(this.fakeElem);
|
||||||
this.copyText();
|
this.copyText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only removes the fake element after another click event, that way
|
* Only removes the fake element after another click event, that way
|
||||||
* a user can hit `Ctrl+C` to copy because selection still exists.
|
* a user can hit `Ctrl+C` to copy because selection still exists.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'removeFake',
|
key: "removeFake",
|
||||||
value: function removeFake() {
|
value: function removeFake() {
|
||||||
if (this.fakeHandler) {
|
if (this.fakeHandler) {
|
||||||
this.container.removeEventListener('click', this.fakeHandlerCallback);
|
this.container.removeEventListener('click', this.fakeHandlerCallback);
|
||||||
@ -634,26 +625,24 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
this.fakeElem = null;
|
this.fakeElem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects the content from element passed on `target` property.
|
* Selects the content from element passed on `target` property.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'selectTarget',
|
key: "selectTarget",
|
||||||
value: function selectTarget() {
|
value: function selectTarget() {
|
||||||
this.selectedText = select_default()(this.target);
|
this.selectedText = select_default()(this.target);
|
||||||
this.copyText();
|
this.copyText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the copy operation based on the current selection.
|
* Executes the copy operation based on the current selection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'copyText',
|
key: "copyText",
|
||||||
value: function copyText() {
|
value: function copyText() {
|
||||||
var succeeded = void 0;
|
var succeeded;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
succeeded = document.execCommand(this.action);
|
succeeded = document.execCommand(this.action);
|
||||||
@ -663,14 +652,13 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
|
|
||||||
this.handleResult(succeeded);
|
this.handleResult(succeeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires an event based on the copy operation result.
|
* Fires an event based on the copy operation result.
|
||||||
* @param {Boolean} succeeded
|
* @param {Boolean} succeeded
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'handleResult',
|
key: "handleResult",
|
||||||
value: function handleResult(succeeded) {
|
value: function handleResult(succeeded) {
|
||||||
this.emitter.emit(succeeded ? 'success' : 'error', {
|
this.emitter.emit(succeeded ? 'success' : 'error', {
|
||||||
action: this.action,
|
action: this.action,
|
||||||
@ -679,29 +667,27 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
clearSelection: this.clearSelection.bind(this)
|
clearSelection: this.clearSelection.bind(this)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves focus away from `target` and back to the trigger, removes current selection.
|
* Moves focus away from `target` and back to the trigger, removes current selection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'clearSelection',
|
key: "clearSelection",
|
||||||
value: function clearSelection() {
|
value: function clearSelection() {
|
||||||
if (this.trigger) {
|
if (this.trigger) {
|
||||||
this.trigger.focus();
|
this.trigger.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
|
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
|
||||||
* @param {String} action
|
* @param {String} action
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'destroy',
|
key: "destroy",
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy lifecycle.
|
* Destroy lifecycle.
|
||||||
@ -710,17 +696,15 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
this.removeFake();
|
this.removeFake();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'action',
|
key: "action",
|
||||||
set: function set() {
|
set: function set() {
|
||||||
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
|
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
|
||||||
|
|
||||||
this._action = action;
|
this._action = action;
|
||||||
|
|
||||||
if (this._action !== 'copy' && this._action !== 'cut') {
|
if (this._action !== 'copy' && this._action !== 'cut') {
|
||||||
throw new Error('Invalid "action" value, use either "copy" or "cut"');
|
throw new Error('Invalid "action" value, use either "copy" or "cut"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the `action` property.
|
* Gets the `action` property.
|
||||||
* @return {String}
|
* @return {String}
|
||||||
@ -729,7 +713,6 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
get: function get() {
|
get: function get() {
|
||||||
return this._action;
|
return this._action;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the `target` property using an element
|
* Sets the `target` property using an element
|
||||||
* that will be have its content copied.
|
* that will be have its content copied.
|
||||||
@ -737,10 +720,10 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'target',
|
key: "target",
|
||||||
set: function set(target) {
|
set: function set(target) {
|
||||||
if (target !== undefined) {
|
if (target !== undefined) {
|
||||||
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
|
if (target && _typeof(target) === 'object' && target.nodeType === 1) {
|
||||||
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
||||||
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
||||||
}
|
}
|
||||||
@ -755,7 +738,6 @@ var clipboard_action_ClipboardAction = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the `target` property.
|
* Gets the `target` property.
|
||||||
* @return {String|HTMLElement}
|
* @return {String|HTMLElement}
|
||||||
@ -779,16 +761,27 @@ var listen = __webpack_require__(2);
|
|||||||
var listen_default = /*#__PURE__*/__webpack_require__.n(listen);
|
var listen_default = /*#__PURE__*/__webpack_require__.n(listen);
|
||||||
|
|
||||||
// CONCATENATED MODULE: ./src/clipboard.js
|
// CONCATENATED MODULE: ./src/clipboard.js
|
||||||
var clipboard_typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); }
|
||||||
|
|
||||||
var clipboard_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 clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
function clipboard_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); } }
|
||||||
|
|
||||||
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 clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) clipboard_defineProperties(Constructor, staticProps); return Constructor; }
|
||||||
|
|
||||||
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||||
|
|
||||||
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||||
|
|
||||||
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
||||||
|
|
||||||
|
function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||||
|
|
||||||
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||||
|
|
||||||
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
||||||
|
|
||||||
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -798,23 +791,28 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|||||||
* and instantiates a new `ClipboardAction` on each click.
|
* and instantiates a new `ClipboardAction` on each click.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var clipboard_Clipboard = function (_Emitter) {
|
var clipboard_Clipboard = /*#__PURE__*/function (_Emitter) {
|
||||||
_inherits(Clipboard, _Emitter);
|
_inherits(Clipboard, _Emitter);
|
||||||
|
|
||||||
|
var _super = _createSuper(Clipboard);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
*/
|
*/
|
||||||
function Clipboard(trigger, options) {
|
function Clipboard(trigger, options) {
|
||||||
|
var _this;
|
||||||
|
|
||||||
clipboard_classCallCheck(this, Clipboard);
|
clipboard_classCallCheck(this, Clipboard);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
|
_this = _super.call(this);
|
||||||
|
|
||||||
_this.resolveOptions(options);
|
_this.resolveOptions(options);
|
||||||
|
|
||||||
_this.listenClick(trigger);
|
_this.listenClick(trigger);
|
||||||
|
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines if attributes would be resolved using internal setter functions
|
* Defines if attributes would be resolved using internal setter functions
|
||||||
* or custom functions that were passed in the constructor.
|
* or custom functions that were passed in the constructor.
|
||||||
@ -823,23 +821,21 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
|
|
||||||
|
|
||||||
clipboard_createClass(Clipboard, [{
|
clipboard_createClass(Clipboard, [{
|
||||||
key: 'resolveOptions',
|
key: "resolveOptions",
|
||||||
value: function resolveOptions() {
|
value: function resolveOptions() {
|
||||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||||
|
|
||||||
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
|
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
|
||||||
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
|
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
|
||||||
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
|
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
|
||||||
this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
|
this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a click event listener to the passed trigger.
|
* Adds a click event listener to the passed trigger.
|
||||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'listenClick',
|
key: "listenClick",
|
||||||
value: function listenClick(trigger) {
|
value: function listenClick(trigger) {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
@ -847,14 +843,13 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
return _this2.onClick(e);
|
return _this2.onClick(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a new `ClipboardAction` on each click event.
|
* Defines a new `ClipboardAction` on each click event.
|
||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'onClick',
|
key: "onClick",
|
||||||
value: function onClick(e) {
|
value: function onClick(e) {
|
||||||
var trigger = e.delegateTarget || e.currentTarget;
|
var trigger = e.delegateTarget || e.currentTarget;
|
||||||
|
|
||||||
@ -871,25 +866,23 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
emitter: this
|
emitter: this
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default `action` lookup function.
|
* Default `action` lookup function.
|
||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'defaultAction',
|
key: "defaultAction",
|
||||||
value: function defaultAction(trigger) {
|
value: function defaultAction(trigger) {
|
||||||
return getAttributeValue('action', trigger);
|
return getAttributeValue('action', trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default `target` lookup function.
|
* Default `target` lookup function.
|
||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'defaultTarget',
|
key: "defaultTarget",
|
||||||
value: function defaultTarget(trigger) {
|
value: function defaultTarget(trigger) {
|
||||||
var selector = getAttributeValue('target', trigger);
|
var selector = getAttributeValue('target', trigger);
|
||||||
|
|
||||||
@ -897,7 +890,6 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
return document.querySelector(selector);
|
return document.querySelector(selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the support of the given action, or all actions if no action is
|
* Returns the support of the given action, or all actions if no action is
|
||||||
* given.
|
* given.
|
||||||
@ -905,8 +897,7 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'defaultText',
|
key: "defaultText",
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default `text` lookup function.
|
* Default `text` lookup function.
|
||||||
@ -915,13 +906,12 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
value: function defaultText(trigger) {
|
value: function defaultText(trigger) {
|
||||||
return getAttributeValue('text', trigger);
|
return getAttributeValue('text', trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy lifecycle.
|
* Destroy lifecycle.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'destroy',
|
key: "destroy",
|
||||||
value: function destroy() {
|
value: function destroy() {
|
||||||
this.listener.destroy();
|
this.listener.destroy();
|
||||||
|
|
||||||
@ -931,24 +921,20 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}], [{
|
}], [{
|
||||||
key: 'isSupported',
|
key: "isSupported",
|
||||||
value: function isSupported() {
|
value: function isSupported() {
|
||||||
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
|
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
|
||||||
|
|
||||||
var actions = typeof action === 'string' ? [action] : action;
|
var actions = typeof action === 'string' ? [action] : action;
|
||||||
var support = !!document.queryCommandSupported;
|
var support = !!document.queryCommandSupported;
|
||||||
|
|
||||||
actions.forEach(function (action) {
|
actions.forEach(function (action) {
|
||||||
support = support && !!document.queryCommandSupported(action);
|
support = support && !!document.queryCommandSupported(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
return support;
|
return support;
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Clipboard;
|
return Clipboard;
|
||||||
}(tiny_emitter_default.a);
|
}(tiny_emitter_default.a);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to retrieve attribute value.
|
* Helper function to retrieve attribute value.
|
||||||
* @param {String} suffix
|
* @param {String} suffix
|
||||||
@ -957,7 +943,7 @@ var clipboard_Clipboard = function (_Emitter) {
|
|||||||
|
|
||||||
|
|
||||||
function getAttributeValue(suffix, element) {
|
function getAttributeValue(suffix, element) {
|
||||||
var attribute = 'data-clipboard-' + suffix;
|
var attribute = "data-clipboard-".concat(suffix);
|
||||||
|
|
||||||
if (!element.hasAttribute(attribute)) {
|
if (!element.hasAttribute(attribute)) {
|
||||||
return;
|
return;
|
||||||
|
2
dist/clipboard.min.js
vendored
2
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
2607
package-lock.json
generated
2607
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -17,9 +17,9 @@
|
|||||||
"tiny-emitter": "^2.0.0"
|
"tiny-emitter": "^2.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.26.0",
|
"@babel/core": "^7.11.6",
|
||||||
"babel-loader": "^7.1.4",
|
"@babel/preset-env": "^7.11.5",
|
||||||
"babel-preset-env": "^1.7.0",
|
"babel-loader": "^8.1.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"cross-env": "^5.2.0",
|
"cross-env": "^5.2.0",
|
||||||
"karma": "^3.1.1",
|
"karma": "^3.1.1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user