mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Merge 8d64f582bb
into 00d5cc4e96
This commit is contained in:
commit
df45265f59
@ -52,6 +52,7 @@ class ClipboardAction {
|
||||
*/
|
||||
selectFake() {
|
||||
let isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||
let top = (window.pageYOffset || document.documentElement.scrollTop);
|
||||
|
||||
this.removeFake();
|
||||
|
||||
@ -68,12 +69,21 @@ class ClipboardAction {
|
||||
this.fakeElem.style.position = 'fixed';
|
||||
this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px';
|
||||
// Move element to the same position vertically
|
||||
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
||||
this.fakeElem.style.top = top + 'px';
|
||||
this.fakeElem.setAttribute('readonly', '');
|
||||
this.fakeElem.value = this.text;
|
||||
|
||||
document.body.appendChild(this.fakeElem);
|
||||
|
||||
// Only after it's in the DOM can we truly tell if some other style like
|
||||
// negative margins are causing it to be rendered off-screen. If it ends
|
||||
// up off screen at all the browser will scroll to it when we select() it
|
||||
let rect = this.fakeElem.getBoundingClientRect();
|
||||
|
||||
if (rect.top < 0) {
|
||||
this.fakeElem.style.top = top - rect.top + 'px';
|
||||
}
|
||||
|
||||
this.selectedText = select(this.fakeElem);
|
||||
this.copyText();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user