1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-22 10:14:51 +00:00

Add support for tm-copy-to-clipboard message

This commit is contained in:
Jermolene
2017-12-15 15:08:18 +00:00
parent e344c38349
commit d2ff164c07
4 changed files with 61 additions and 0 deletions

View File

@@ -231,4 +231,34 @@ exports.copyStyles = function(srcDomNode,dstDomNode) {
$tw.utils.setStyles(dstDomNode,$tw.utils.getComputedStyles(srcDomNode));
};
/*
Copy plain text to the clipboard on browsers that support it
*/
exports.copyToClipboard = function(text,options) {
options = options || {};
var textArea = document.createElement("textarea");
textArea.style.position = "fixed";
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = "2em";
textArea.style.height = "2em";
textArea.style.padding = 0;
textArea.style.border = "none";
textArea.style.outline = "none";
textArea.style.boxShadow = "none";
textArea.style.background = "transparent";
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
var succeeded = false;
try {
succeeded = document.execCommand("copy");
} catch (err) {
}
if(!options.doNotNotify) {
$tw.notifier.display(succeeded ? "$:/language/Notifications/CopiedToClipboard/Succeeded" : "$:/language/Notifications/CopiedToClipboard/Failed");
}
document.body.removeChild(textArea);
};
})();