feat: decoupling create fakeElemet logic

This commit is contained in:
vitormalencar 2021-02-25 16:16:12 +01:00
parent eff98406b9
commit b66010bf77

View File

@ -39,19 +39,12 @@ class ClipboardAction {
this.selectTarget();
}
}
/**
* 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';
this.fakeHandlerCallback = () => this.removeFake();
this.fakeHandler =
this.container.addEventListener('click', this.fakeHandlerCallback) ||
true;
this.fakeElem = document.createElement('textarea');
// Prevent zooming on iOS
this.fakeElem.style.fontSize = '12pt';
@ -69,9 +62,26 @@ class ClipboardAction {
this.fakeElem.setAttribute('readonly', '');
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.removeFake();