merged copytoclipboard
This commit is contained in:
maru21 2023-11-06 17:50:31 +01:00
parent aa6b528147
commit 11521adff7
3 changed files with 43 additions and 76 deletions

View File

@ -267,6 +267,43 @@ function wrongPwAlert() {
});
}
function copyToClipBoard(html) {
// Create an iframe (isolated container) for the HTML
var container = document.createElement("div");
container.innerHTML = html;
// Hide element
container.style.position = "fixed";
container.style.pointerEvents = "none";
container.style.opacity = 0;
// Detect all style sheets of the page
var activeSheets = Array.prototype.slice
.call(document.styleSheets)
.filter(function (sheet) {
return !sheet.disabled;
});
// Mount the iframe to the DOM to make `contentWindow` available
document.body.appendChild(container);
// Copy to clipboard
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(container);
window.getSelection().addRange(range);
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = true;
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++)
activeSheets[i].disabled = false;
// Remove the iframe
document.body.removeChild(container);
}
export {
hideMenus,
showMenu,
@ -279,5 +316,6 @@ export {
clickImportFiles,
resetNavBar,
printVersion,
wrongPwAlert
wrongPwAlert,
copyToClipBoard
};

View File

@ -5,7 +5,7 @@ import {
} from "./storage.js";
import { loadTemplate } from "./web.js";
import parseFormOnSubmit from "./parseForm.js";
import { modalNotifier, resetNavBar } from "./evts.js";
import { copyToClipBoard, modalNotifier, resetNavBar } from "./evts.js";
import { passwordHash } from "./scripts.js";
function buildFile() {
@ -331,42 +331,6 @@ function copyFileToClipboard() {
}
}
function copyToClipBoard(html) {
// Create an iframe (isolated container) for the HTML
var container = document.createElement("div");
container.innerHTML = html;
// Hide element
container.style.position = "fixed";
container.style.pointerEvents = "none";
container.style.opacity = 0;
// Detect all style sheets of the page
var activeSheets = Array.prototype.slice
.call(document.styleSheets)
.filter(function (sheet) {
return !sheet.disabled;
});
// Mount the iframe to the DOM to make `contentWindow` available
document.body.appendChild(container);
// Copy to clipboard
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(container);
window.getSelection().addRange(range);
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = true;
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++)
activeSheets[i].disabled = false;
// Remove the iframe
document.body.removeChild(container);
}
function formEvts(storageName) {
//add event listener to submitContainer

View File

@ -1,4 +1,6 @@
import { storeData, clearData, retrieveData, setCurrentFileName } from "./storage.js";
import { copyToClipBoard } from "./evts.js";
import { storeData, clearData, retrieveData } from "./storage.js";
function parseFormOnSubmit(returnJSON = false, parseOnly = false) {
//event.preventDefault;
@ -385,43 +387,6 @@ function loadTextBlocks() {
return textBlocksObject;
}
function copyToClipBoard(html) {
// Create an iframe (isolated container) for the HTML
var container = document.createElement("div");
container.innerHTML = html;
// Hide element
container.style.position = "fixed";
container.style.pointerEvents = "none";
container.style.opacity = 0;
// Detect all style sheets of the page
var activeSheets = Array.prototype.slice
.call(document.styleSheets)
.filter(function (sheet) {
return !sheet.disabled;
});
// Mount the iframe to the DOM to make `contentWindow` available
document.body.appendChild(container);
// Copy to clipboard
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(container);
window.getSelection().addRange(range);
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = true;
document.execCommand("copy");
for (var i = 0; i < activeSheets.length; i++)
activeSheets[i].disabled = false;
// Remove the iframe
document.body.removeChild(container);
}
function mainFormPlaceholder(msg) {
return "<div class='w3-row-padding w3-padding-24 w3-container w3-flat-clouds'><div class='w3-code notranslate w3-border-white' style='font-family: Arial, Helvetica, sans-serif;'><p>" + msg + "</p><br><br><br><br><br><br><br><br><br><br><br></div></div>";
}