mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
feat: decoupling create fakeElemet logic
This commit is contained in:
parent
eff98406b9
commit
b66010bf77
@ -39,19 +39,12 @@ class ClipboardAction {
|
|||||||
this.selectTarget();
|
this.selectTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a fake textarea element, sets its value from `text` property,
|
* Creates a fake textarea element, sets its value from `text` property,
|
||||||
* and makes a selection on it.
|
|
||||||
*/
|
*/
|
||||||
selectFake() {
|
createFakeElement() {
|
||||||
const isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
const isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||||
|
|
||||||
this.fakeHandlerCallback = () => this.removeFake();
|
|
||||||
this.fakeHandler =
|
|
||||||
this.container.addEventListener('click', this.fakeHandlerCallback) ||
|
|
||||||
true;
|
|
||||||
|
|
||||||
this.fakeElem = document.createElement('textarea');
|
this.fakeElem = document.createElement('textarea');
|
||||||
// Prevent zooming on iOS
|
// Prevent zooming on iOS
|
||||||
this.fakeElem.style.fontSize = '12pt';
|
this.fakeElem.style.fontSize = '12pt';
|
||||||
@ -69,9 +62,26 @@ class ClipboardAction {
|
|||||||
this.fakeElem.setAttribute('readonly', '');
|
this.fakeElem.setAttribute('readonly', '');
|
||||||
this.fakeElem.value = this.text;
|
this.fakeElem.value = this.text;
|
||||||
|
|
||||||
this.container.appendChild(this.fakeElem);
|
return this.fakeElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's the value of fakeElem,
|
||||||
|
* and makes a selection on it.
|
||||||
|
*/
|
||||||
|
selectFake() {
|
||||||
|
const fakeElem = this.createFakeElement();
|
||||||
|
|
||||||
|
this.fakeHandlerCallback = () => this.removeFake();
|
||||||
|
|
||||||
|
this.fakeHandler =
|
||||||
|
this.container.addEventListener('click', this.fakeHandlerCallback) ||
|
||||||
|
true;
|
||||||
|
|
||||||
|
this.container.appendChild(fakeElem);
|
||||||
|
|
||||||
|
this.selectedText = select(fakeElem);
|
||||||
|
|
||||||
this.selectedText = select(this.fakeElem);
|
|
||||||
this.copyText();
|
this.copyText();
|
||||||
|
|
||||||
this.removeFake();
|
this.removeFake();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user