From a2c9b99b1f08096f4470a34b2e014b85441bb30f Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Fri, 2 Aug 2019 14:26:52 +0800 Subject: [PATCH] update --- README.md | 3 ++- dist/xe-clipboard.js | 9 ++------- dist/xe-clipboard.min.js | 2 +- index.js | 9 ++------- package.json | 2 +- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a7c3c1b..85d108b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ [![gzip size: JS](http://img.badgesize.io/https://unpkg.com/xe-clipboard/dist/xe-clipboard.min.js?compression=gzip&label=gzip%20size:%20JS)](https://unpkg.com/xe-clipboard/dist/xe-clipboard.min.js) [![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/xuliangzhan/xe-clipboard/blob/master/LICENSE) -It depends on the [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) APIs, support commonly used H5 browser IE, Chrome, Firefox, Opera, Safari, IOS, Android. +It depends on the [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) APIs, support commonly used H5 browser IE, Chrome, Firefox, Opera, Safari, IOS, Android. +compressed by gzip: < 1KB ## Browser Support diff --git a/dist/xe-clipboard.js b/dist/xe-clipboard.js index fa9505f..570c8f7 100644 --- a/dist/xe-clipboard.js +++ b/dist/xe-clipboard.js @@ -36,14 +36,11 @@ } } - function selectText() { + function copyText() { $elem.focus(); $elem.select(); $elem.setSelectionRange(0, $elem.value.length); - } - - function copyText(showDefault) { - return doc.execCommand('copy', showDefault); + return doc.execCommand.apply(doc, 'copy', arguments); } /** * Copy the contents to the clipboard. @@ -57,11 +54,9 @@ try { handleText(content); - selectText(); result = copyText(); if (!result) { - selectText(); result = copyText(true); } } catch (e) {} diff --git a/dist/xe-clipboard.min.js b/dist/xe-clipboard.min.js index 7aeab27..11c3839 100644 --- a/dist/xe-clipboard.min.js +++ b/dist/xe-clipboard.min.js @@ -1 +1 @@ -!function(e,t){if("function"==typeof define&&define.amd)define("xe-clipboard",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.XEClipboard=n.exports.default}}(this,function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=window.document,o=n.createElement("textarea");function i(){o.focus(),o.select(),o.setSelectionRange(0,o.value.length)}function d(e){return n.execCommand("copy",e)}function t(e){var t=!1;try{!function(e){var t=o.style;o.id="$XECopy",t.width="48px",t.height="24px",t.position="fixed",t.zIndex="0",t.left="-500px",t.top="-500px",o.value=null==e?"":""+e,o.parentNode||n.body.appendChild(o)}(e),i(),(t=d())||(i(),t=d(!0))}catch(e){}return t}var r=t.copy=t;e.default=r}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define("xe-clipboard",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.XEClipboard=n.exports.default}}(this,function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=window.document,o=n.createElement("textarea");function i(){return o.focus(),o.select(),o.setSelectionRange(0,o.value.length),n.execCommand.apply(n,"copy",arguments)}function t(e){var t=!1;try{!function(e){var t=o.style;o.id="$XECopy",t.width="48px",t.height="24px",t.position="fixed",t.zIndex="0",t.left="-500px",t.top="-500px",o.value=null==e?"":""+e,o.parentNode||n.body.appendChild(o)}(e),(t=i())||(t=i(!0))}catch(e){}return t}var d=t.copy=t;e.default=d}); \ No newline at end of file diff --git a/index.js b/index.js index a0641e5..a9767b3 100644 --- a/index.js +++ b/index.js @@ -18,14 +18,11 @@ function handleText (content) { } } -function selectText () { +function copyText () { $elem.focus() $elem.select() $elem.setSelectionRange(0, $elem.value.length) -} - -function copyText (showDefault) { - return doc.execCommand('copy', showDefault) + return doc.execCommand.apply(doc, 'copy', arguments) } /** @@ -37,10 +34,8 @@ function XEClipboard (content) { var result = false try { handleText(content) - selectText() result = copyText() if (!result) { - selectText() result = copyText(true) } } catch (e) {} diff --git a/package.json b/package.json index 7cdb6c7..1cdf09c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xe-clipboard", - "version": "1.2.0", + "version": "1.3.0", "description": "Copy the contents to the clipboard, support commonly used H5 browser IE, Chrome, Firefox, Opera, Safari, IOS, Android.", "main": "index.js", "unpkg": "dist/xe-clipboard.js",