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:
@@ -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);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user