Merge pull request #720 from zenorocha/small-enhancements

Remove unnecessary code and add node version control
This commit is contained in:
Beto Muniz 2021-01-21 17:11:55 -03:00 committed by GitHub
commit 62eef3e5b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 29 deletions

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
14

56
dist/clipboard.js vendored
View File

@ -71,7 +71,7 @@ var ClipboardAction = /*#__PURE__*/function () {
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
@ -97,28 +97,28 @@ var ClipboardAction = /*#__PURE__*/function () {
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.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
this.fakeElem = document.createElement("textarea"); // 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"; // Move element out of screen horizontally this.fakeElem.style.margin = '0'; // Move element out of screen horizontally
this.fakeElem.style.position = "absolute"; this.fakeElem.style.position = 'absolute';
this.fakeElem.style[isRTL ? "right" : "left"] = "-9999px"; // Move element to the same position vertically this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
var yPosition = window.pageYOffset || document.documentElement.scrollTop; var yPosition = window.pageYOffset || document.documentElement.scrollTop;
this.fakeElem.style.top = "".concat(yPosition, "px"); 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);
@ -133,7 +133,7 @@ var ClipboardAction = /*#__PURE__*/function () {
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);
this.fakeHandler = null; this.fakeHandler = null;
this.fakeHandlerCallback = null; this.fakeHandlerCallback = null;
} }
@ -178,7 +178,7 @@ var ClipboardAction = /*#__PURE__*/function () {
}, { }, {
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,
text: this.selectedText, text: this.selectedText,
trigger: this.trigger, trigger: this.trigger,
@ -216,10 +216,10 @@ var ClipboardAction = /*#__PURE__*/function () {
}, { }, {
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"');
} }
} }
@ -241,12 +241,12 @@ var ClipboardAction = /*#__PURE__*/function () {
key: "target", key: "target",
set: function set(target) { set: function set(target) {
if (target !== undefined) { if (target !== undefined) {
if (target && _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');
} }
if (this.action === "cut" && (target.hasAttribute("readonly") || target.hasAttribute("disabled"))) { if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
} }
@ -340,10 +340,10 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
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.
@ -355,7 +355,7 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
value: function listenClick(trigger) { value: function listenClick(trigger) {
var _this2 = this; var _this2 = this;
this.listener = listen_default()(trigger, "click", function (e) { this.listener = listen_default()(trigger, 'click', function (e) {
return _this2.onClick(e); return _this2.onClick(e);
}); });
} }
@ -390,7 +390,7 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
}, { }, {
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.
@ -400,7 +400,7 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
}, { }, {
key: "defaultTarget", key: "defaultTarget",
value: function defaultTarget(trigger) { value: function defaultTarget(trigger) {
var selector = getAttributeValue("target", trigger); var selector = getAttributeValue('target', trigger);
if (selector) { if (selector) {
return document.querySelector(selector); return document.querySelector(selector);
@ -420,7 +420,7 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
* @param {Element} trigger * @param {Element} trigger
*/ */
value: function defaultText(trigger) { value: function defaultText(trigger) {
return getAttributeValue("text", trigger); return getAttributeValue('text', trigger);
} }
/** /**
* Destroy lifecycle. * Destroy lifecycle.
@ -439,8 +439,8 @@ var Clipboard = /*#__PURE__*/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);

View File

@ -1,6 +1,5 @@
import Clipboard from '../src/clipboard'; import Clipboard from '../src/clipboard';
import ClipboardAction from '../src/clipboard-action'; import ClipboardAction from '../src/clipboard-action';
import listen from 'good-listener';
describe('Clipboard', () => { describe('Clipboard', () => {
before(() => { before(() => {