Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Aug 2, 2019
1 parent 5b70b65 commit a2c9b99
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 2 additions & 7 deletions dist/xe-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -57,11 +54,9 @@

try {
handleText(content);
selectText();
result = copyText();

if (!result) {
selectText();
result = copyText(true);
}
} catch (e) {}
Expand Down
2 changes: 1 addition & 1 deletion dist/xe-clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand All @@ -37,10 +34,8 @@ function XEClipboard (content) {
var result = false
try {
handleText(content)
selectText()
result = copyText()
if (!result) {
selectText()
result = copyText(true)
}
} catch (e) {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit a2c9b99

Please sign in to comment.