Skip to content

Commit

Permalink
Change copying to clipboard so that it doesn't rely on clipboard even…
Browse files Browse the repository at this point in the history
…ts being enabled
  • Loading branch information
Wladimir Palant committed Jul 31, 2017
1 parent 17b0f63 commit 8b80993
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions data/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@

/* global document */

let clipboardDummy = null;

exports.set = function(data)
{
// Solution by courtesy of https://stackoverflow.com/a/12693636/785541
let listener = event =>
if (!clipboardDummy)
{
event.clipboardData.setData("text/plain", data);
event.preventDefault();
};
document.addEventListener("copy", listener);
clipboardDummy = document.createElement("textarea");
clipboardDummy.style.position = "absolute";
clipboardDummy.style.width = "0px";
clipboardDummy.style.height = "0px";
clipboardDummy.style.left = "-1000px";
document.body.appendChild(clipboardDummy);
}

clipboardDummy.value = data;
clipboardDummy.select();
document.execCommand("copy", false, null);
document.removeEventListener("copy", listener);
};

0 comments on commit 8b80993

Please sign in to comment.