Merge pull request #733 from zenorocha/feature-732-removing-dom-el
This commit is contained in:
commit
15737fe877
|
@ -42,18 +42,10 @@ class ClipboardAction {
|
|||
|
||||
/**
|
||||
* 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.removeFake();
|
||||
|
||||
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';
|
||||
|
@ -71,10 +63,29 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,9 @@ describe('ClipboardAction', () => {
|
|||
text: 'foo',
|
||||
});
|
||||
|
||||
assert.equal(clip.fakeElem.style.right, '-9999px');
|
||||
const el = clip.createFakeElement();
|
||||
|
||||
assert.equal(el.style.right, '-9999px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -90,7 +92,9 @@ describe('ClipboardAction', () => {
|
|||
text: 'blah',
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.fakeElem.value);
|
||||
const el = clip.createFakeElement();
|
||||
|
||||
assert.equal(clip.selectedText, el.value);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue