mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Moves selection code to a different package
This commit is contained in:
parent
f0245ab701
commit
c6dc01cc29
@ -25,6 +25,7 @@
|
|||||||
"babelify": "^6.3.0",
|
"babelify": "^6.3.0",
|
||||||
"browserify": "^11.2.0",
|
"browserify": "^11.2.0",
|
||||||
"delegate-events": "^1.1.1",
|
"delegate-events": "^1.1.1",
|
||||||
|
"select": "^1.0.0",
|
||||||
"tiny-emitter": "^1.0.0"
|
"tiny-emitter": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import select from 'select';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner class which performs selection from either `text` or `target`
|
* Inner class which performs selection from either `text` or `target`
|
||||||
* properties and then executes copy or cut operations.
|
* properties and then executes copy or cut operations.
|
||||||
@ -59,11 +61,10 @@ class ClipboardAction {
|
|||||||
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
||||||
this.fakeElem.setAttribute('readonly', '');
|
this.fakeElem.setAttribute('readonly', '');
|
||||||
this.fakeElem.value = this.text;
|
this.fakeElem.value = this.text;
|
||||||
this.selectedText = this.text;
|
|
||||||
|
|
||||||
document.body.appendChild(this.fakeElem);
|
document.body.appendChild(this.fakeElem);
|
||||||
|
|
||||||
this.fakeElem.select();
|
this.selectedText = select(this.fakeElem);
|
||||||
this.copyText();
|
this.copyText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,20 +88,7 @@ class ClipboardAction {
|
|||||||
* Selects the content from element passed on `target` property.
|
* Selects the content from element passed on `target` property.
|
||||||
*/
|
*/
|
||||||
selectTarget() {
|
selectTarget() {
|
||||||
if (this.target.nodeName === 'INPUT' || this.target.nodeName === 'TEXTAREA') {
|
this.selectedText = select(this.target);
|
||||||
this.target.select();
|
|
||||||
this.selectedText = this.target.value;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let range = document.createRange();
|
|
||||||
let selection = window.getSelection();
|
|
||||||
|
|
||||||
selection.removeAllRanges();
|
|
||||||
range.selectNodeContents(this.target);
|
|
||||||
selection.addRange(range);
|
|
||||||
this.selectedText = selection.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.copyText();
|
this.copyText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user