From d541aa82f9a830ebf258f9a3e51d30d32e12259d Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 6 Jun 2019 13:34:18 -0700 Subject: [PATCH] Fixed copy to clipboard to work on non-firefox/chrome browsers. --- views/agentinvite.handlebars | 5 +++-- views/default-min.handlebars | 5 +++-- views/default.handlebars | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/views/agentinvite.handlebars b/views/agentinvite.handlebars index 76d3c427..35ebde61 100644 --- a/views/agentinvite.handlebars +++ b/views/agentinvite.handlebars @@ -285,8 +285,9 @@ else { openTab(null, 'wintab64'); } } - function copyToClipLinuxInstall() { navigator.clipboard.writeText(linuxInstall); } - function copyToClipLinuxUnInstall() { navigator.clipboard.writeText(linuxUnInstall); } + function copyToClipLinuxInstall() { copyTextToClip(linuxInstall); } + function copyToClipLinuxUnInstall() { copyTextToClip(linuxUnInstall); } + function copyTextToClip(txt) { function selectElementText(e) { if (document.selection) { var range = document.body.createTextRange(); range.moveToElementText(e); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNode(e); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); } } var e = document.createElement('DIV'); e.textContent = txt; document.body.appendChild(e); selectElementText(e); document.execCommand('copy'); e.remove(); } diff --git a/views/default-min.handlebars b/views/default-min.handlebars index dcffb776..b1b799ee 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -8773,7 +8773,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this validateAgentInvite(); } - function d2CopyInviteToClip() { navigator.clipboard.writeText(Q('agentInvitationLink').href); } + function d2CopyInviteToClip() { copyTextToClip(Q('agentInvitationLink').href); } function validateAgentInvite() { if ((features & 64) && (Q('d2InviteType').value == 1)) { @@ -8882,7 +8882,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this var portStr = (serverinfo.port == 443) ? '' : (":" + serverinfo.port); var c = "https://" + servername + portStr + domainUrl + url; if (addflag == 1) c += Q('aginsType').value; - navigator.clipboard.writeText(c); + copyTextToClip(c); } function fileDownload(path, name, appendFlag) { @@ -14172,5 +14172,6 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); } function u2fSupported() { return (window.u2f && ((navigator.userAgent.indexOf('Chrome/') > 0) || (navigator.userAgent.indexOf('Firefox/') > 0) || (navigator.userAgent.indexOf('Opera/') > 0) || (navigator.userAgent.indexOf('Safari/') > 0))); } function findOne(arr1, arr2) { if ((arr1 == null) || (arr2 == null)) return false; return arr2.some(function (v) { return arr1.indexOf(v) >= 0; }); }; + function copyTextToClip(txt) { function selectElementText(e) { if (document.selection) { var range = document.body.createTextRange(); range.moveToElementText(e); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNode(e); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); } } var e = document.createElement('DIV'); e.textContent = txt; document.body.appendChild(e); selectElementText(e); document.execCommand('copy'); e.remove(); } \ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index ef754224..3fd156e6 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2725,7 +2725,7 @@ validateAgentInvite(); } - function d2CopyInviteToClip() { navigator.clipboard.writeText(Q('agentInvitationLink').href); } + function d2CopyInviteToClip() { copyTextToClip(Q('agentInvitationLink').href); } function validateAgentInvite() { if ((features & 64) && (Q('d2InviteType').value == 1)) { @@ -2834,7 +2834,7 @@ var portStr = (serverinfo.port == 443) ? '' : (":" + serverinfo.port); var c = "https://" + servername + portStr + domainUrl + url; if (addflag == 1) c += Q('aginsType').value; - navigator.clipboard.writeText(c); + copyTextToClip(c); } function fileDownload(path, name, appendFlag) { @@ -5559,7 +5559,6 @@ p13uploadNextFile(); break; default: - console.log('Unknown onFileUploadStateChange state', state); break; } } @@ -8124,6 +8123,7 @@ function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); } function u2fSupported() { return (window.u2f && ((navigator.userAgent.indexOf('Chrome/') > 0) || (navigator.userAgent.indexOf('Firefox/') > 0) || (navigator.userAgent.indexOf('Opera/') > 0) || (navigator.userAgent.indexOf('Safari/') > 0))); } function findOne(arr1, arr2) { if ((arr1 == null) || (arr2 == null)) return false; return arr2.some(function (v) { return arr1.indexOf(v) >= 0; }); }; + function copyTextToClip(txt) { function selectElementText(e) { if (document.selection) { var range = document.body.createTextRange(); range.moveToElementText(e); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNode(e); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); } } var e = document.createElement('DIV'); e.textContent = txt; document.body.appendChild(e); selectElementText(e); document.execCommand('copy'); e.remove(); }