mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-06 13:56:45 +00:00
Extend copy to clipborad function to support customized mime types
This commit is contained in:
parent
94b325f41f
commit
be48c17b7f
@ -78,7 +78,7 @@ exports.startup = function() {
|
|||||||
$tw.utils.copyToClipboard(event.param,{
|
$tw.utils.copyToClipboard(event.param,{
|
||||||
successNotification: event.paramObject && event.paramObject.successNotification,
|
successNotification: event.paramObject && event.paramObject.successNotification,
|
||||||
failureNotification: event.paramObject && event.paramObject.failureNotification
|
failureNotification: event.paramObject && event.paramObject.failureNotification
|
||||||
});
|
},event.paramObject.type);
|
||||||
});
|
});
|
||||||
// Install the tm-focus-selector message
|
// Install the tm-focus-selector message
|
||||||
$tw.rootWidget.addEventListener("tm-focus-selector",function(event) {
|
$tw.rootWidget.addEventListener("tm-focus-selector",function(event) {
|
||||||
|
@ -268,9 +268,7 @@ exports.copyStyles = function(srcDomNode,dstDomNode) {
|
|||||||
/*
|
/*
|
||||||
Copy plain text to the clipboard on browsers that support it
|
Copy plain text to the clipboard on browsers that support it
|
||||||
*/
|
*/
|
||||||
exports.copyToClipboard = function(text,options) {
|
exports.copyToClipboard = function(text = "",options = {},type = "text/plain") {
|
||||||
options = options || {};
|
|
||||||
text = text || "";
|
|
||||||
var textArea = document.createElement("textarea");
|
var textArea = document.createElement("textarea");
|
||||||
textArea.style.position = "fixed";
|
textArea.style.position = "fixed";
|
||||||
textArea.style.top = 0;
|
textArea.style.top = 0;
|
||||||
@ -283,10 +281,14 @@ exports.copyToClipboard = function(text,options) {
|
|||||||
textArea.style.outline = "none";
|
textArea.style.outline = "none";
|
||||||
textArea.style.boxShadow = "none";
|
textArea.style.boxShadow = "none";
|
||||||
textArea.style.background = "transparent";
|
textArea.style.background = "transparent";
|
||||||
textArea.value = text;
|
|
||||||
document.body.appendChild(textArea);
|
document.body.appendChild(textArea);
|
||||||
textArea.select();
|
textArea.select();
|
||||||
textArea.setSelectionRange(0,text.length);
|
textArea.setSelectionRange(0,text.length);
|
||||||
|
textArea.addEventListener("copy",function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.clipboardData.setData("text/plain",text);
|
||||||
|
event.clipboardData.setData(type,text);
|
||||||
|
});
|
||||||
var succeeded = false;
|
var succeeded = false;
|
||||||
try {
|
try {
|
||||||
succeeded = document.execCommand("copy");
|
succeeded = document.execCommand("copy");
|
||||||
|
@ -3,9 +3,12 @@ tags: $:/tags/Macro
|
|||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
|
|
||||||
\procedure copy-to-clipboard(src,class:"tc-btn-invisible",style)
|
\procedure copy-to-clipboard(src,class:"tc-btn-invisible",style,type:"text/plain")
|
||||||
<$button message="tm-copy-to-clipboard"
|
|
||||||
param=<<src>>
|
\procedure copy-to-clipboard-actions()
|
||||||
|
<$action-sendmessage $message="tm-copy-to-clipboard" $param=<<src>> type=<<type>>/>
|
||||||
|
\end copy-to-clipboard-actions
|
||||||
|
<$button actions=<<copy-to-clipboard-actions>>
|
||||||
class=<<class>>
|
class=<<class>>
|
||||||
style=<<style>>
|
style=<<style>>
|
||||||
tooltip={{$:/language/Buttons/CopyToClipboard/Hint}}
|
tooltip={{$:/language/Buttons/CopyToClipboard/Hint}}
|
||||||
@ -15,12 +18,12 @@ tags: $:/tags/Macro
|
|||||||
<$text text={{$:/language/Buttons/CopyToClipboard/Caption}}/>
|
<$text text={{$:/language/Buttons/CopyToClipboard/Caption}}/>
|
||||||
</span>
|
</span>
|
||||||
</$button>
|
</$button>
|
||||||
\end
|
\end copy-to-clipboard
|
||||||
|
|
||||||
\procedure copy-to-clipboard-above-right(src,class:"tc-btn-invisible",style)
|
\procedure copy-to-clipboard-above-right(src,class:"tc-btn-invisible",style,type:"text/plain")
|
||||||
<div style="position: relative;">
|
<div style.position="relative">
|
||||||
<div style="position: absolute; bottom: 0; right: 0;">
|
<div style.position="absolute" style.bottom="0" style.right="0">
|
||||||
<$macrocall $name="copy-to-clipboard" src=<<src>> class=<<class>> style=<<style>>/>
|
<$transclude $variable="copy-to-clipboard" src=<<src>> class=<<class>> style=<<style>> type=<<type>>/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
\end
|
\end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user