mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
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,
|
* 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.removeFake();
|
|
||||||
|
|
||||||
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';
|
||||||
@ -71,10 +63,29 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +47,9 @@ describe('ClipboardAction', () => {
|
|||||||
text: 'foo',
|
text: 'foo',
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(clip.fakeElem.style.right, '-9999px');
|
const el = clip.createFakeElement();
|
||||||
|
|
||||||
|
assert.equal(el.style.right, '-9999px');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -90,7 +92,9 @@ describe('ClipboardAction', () => {
|
|||||||
text: 'blah',
|
text: 'blah',
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(clip.selectedText, clip.fakeElem.value);
|
const el = clip.createFakeElement();
|
||||||
|
|
||||||
|
assert.equal(clip.selectedText, el.value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user