mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Merge 5e6b9c32da
into f7da00f0ba
This commit is contained in:
commit
0c75db6b49
68
example/index.html
Normal file
68
example/index.html
Normal file
@ -0,0 +1,68 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Example</title>
|
||||
<style>
|
||||
.copy {
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
|
||||
font: inherit;
|
||||
|
||||
border-radius: 5px;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
button.copy {
|
||||
border: 1px solid rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
#span, #input {
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
padding: 2px 5px;
|
||||
margin-right: 10px;
|
||||
|
||||
font: inherit;
|
||||
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<input type="text" id="input" value="input">
|
||||
|
||||
<span class="copy" data-clipboard-action="copy" data-clipboard-target="#input">
|
||||
<span>
|
||||
</span>
|
||||
<button class="copy" data-clipboard-action="copy" data-clipboard-target="#input">
|
||||
<button>
|
||||
</button>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<span id="span">span</span>
|
||||
|
||||
<span class="copy" data-clipboard-action="copy" data-clipboard-target="#span">
|
||||
<span>
|
||||
</span>
|
||||
<button class="copy" data-clipboard-action="copy" data-clipboard-target="#span">
|
||||
<button>
|
||||
</button>
|
||||
|
||||
<br><br>
|
||||
|
||||
<textarea cols="30" rows="10" placeholder="Paste here"></textarea>
|
||||
|
||||
|
||||
<script src="../dist/clipboard.js"></script>
|
||||
<script>
|
||||
new Clipboard('.copy');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -25,7 +25,8 @@
|
||||
"babelify": "^6.3.0",
|
||||
"browserify": "^11.2.0",
|
||||
"delegate-events": "^1.1.1",
|
||||
"tiny-emitter": "^1.0.0"
|
||||
"tiny-emitter": "^1.0.0",
|
||||
"toggle-selection": "^1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"karma": "^0.13.10",
|
||||
|
@ -1,3 +1,5 @@
|
||||
import deselectCurrent from 'toggle-selection';
|
||||
|
||||
/**
|
||||
* Inner class which performs selection from either `text` or `target`
|
||||
* properties and then executes copy or cut operations.
|
||||
@ -92,6 +94,7 @@ class ClipboardAction {
|
||||
this.selectedText = this.target.value;
|
||||
}
|
||||
else {
|
||||
const reselectPrevious = deselectCurrent();
|
||||
let range = document.createRange();
|
||||
let selection = window.getSelection();
|
||||
|
||||
@ -99,6 +102,8 @@ class ClipboardAction {
|
||||
range.selectNodeContents(this.target);
|
||||
selection.addRange(range);
|
||||
this.selectedText = selection.toString();
|
||||
|
||||
reselectPrevious();
|
||||
}
|
||||
|
||||
this.copyText();
|
||||
|
Loading…
Reference in New Issue
Block a user