Fixed copy to clipboard to work on non-firefox/chrome browsers.

Ylian Saint-Hilaire committed Jun 6, 2019 at 13:34 UTC d541aa82f9a830ebf258f9a3e51d30d32e12259d
3 files changed +9 -7
views/agentinvite.handlebars
+3 -2
@@ -285,8 +285,9 @@
285 else { openTab(null, 'wintab64'); }
286 }
287
288 - function copyToClipLinuxInstall() { navigator.clipboard.writeText(linuxInstall); }
289 - function copyToClipLinuxUnInstall() { navigator.clipboard.writeText(linuxUnInstall); }
288 + function copyToClipLinuxInstall() { copyTextToClip(linuxInstall); }
289 + function copyToClipLinuxUnInstall() { copyTextToClip(linuxUnInstall); }
290 + 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(); }
291
292 </script>
293 </body>
views/default-min.handlebars
+3 -2
@@ -8773,7 +8773,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
8773 validateAgentInvite();
8774 }
8775
8776 - function d2CopyInviteToClip() { navigator.clipboard.writeText(Q('agentInvitationLink').href); }
8776 + function d2CopyInviteToClip() { copyTextToClip(Q('agentInvitationLink').href); }
8777
8778 function validateAgentInvite() {
8779 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
8882 var portStr = (serverinfo.port == 443) ? '' : (":" + serverinfo.port);
8883 var c = "https://" + servername + portStr + domainUrl + url;
8884 if (addflag == 1) c += Q('aginsType').value;
8885 - navigator.clipboard.writeText(c);
8885 + copyTextToClip(c);
8886 }
8887
8888 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
14172 function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); }
14173 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))); }
14174 function findOne(arr1, arr2) { if ((arr1 == null) || (arr2 == null)) return false; return arr2.some(function (v) { return arr1.indexOf(v) >= 0; }); };
14175 + 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(); }
14176
14177 </script></body></html>
\ No newline at end of file
views/default.handlebars
+3 -3
@@ -2725,7 +2725,7 @@
2725 validateAgentInvite();
2726 }
2727
2728 - function d2CopyInviteToClip() { navigator.clipboard.writeText(Q('agentInvitationLink').href); }
2728 + function d2CopyInviteToClip() { copyTextToClip(Q('agentInvitationLink').href); }
2729
2730 function validateAgentInvite() {
2731 if ((features & 64) && (Q('d2InviteType').value == 1)) {
@@ -2834,7 +2834,7 @@
2834 var portStr = (serverinfo.port == 443) ? '' : (":" + serverinfo.port);
2835 var c = "https://" + servername + portStr + domainUrl + url;
2836 if (addflag == 1) c += Q('aginsType').value;
2837 - navigator.clipboard.writeText(c);
2837 + copyTextToClip(c);
2838 }
2839
2840 function fileDownload(path, name, appendFlag) {
@@ -5559,7 +5559,6 @@
5559 p13uploadNextFile();
5560 break;
5561 default:
5562 - console.log('Unknown onFileUploadStateChange state', state);
5562 break;
5563 }
5564 }
@@ -8124,6 +8123,7 @@
8123 function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); }
8124 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))); }
8125 function findOne(arr1, arr2) { if ((arr1 == null) || (arr2 == null)) return false; return arr2.some(function (v) { return arr1.indexOf(v) >= 0; }); };
8126 + 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(); }
8127
8128 </script>
8129 </body>