// import { Previewer } from 'https://unpkg.com/pagedjs@0.1.38/dist/paged.esm.js'; import { Previewer, Handler } from '../js/paged.esm.js'; let iconScreen = ''; let iconBook = ''; let iconPrinter = '' async function load_home(){ let allContent = document.querySelectorAll(".added-content"); for (let content of allContent) { let name = content.id; let path = 'src/' + name + '/content.html' content.innerHTML = await (await fetch(path)).text(); } } window.addEventListener('load', async() => { await load_home(); // 1. Get content let content = document.body.innerHTML; document.body.innerHTML = ""; // 2. Move content into #content + build header document.body.innerHTML = '\
\
\ \ \ \ \ \
\
\
\
\ ' + content + '
'; // 3. Add onclick event document.querySelector('#button-print-preview').addEventListener('click', printPreview); document.querySelector('#button-screen').addEventListener('click', screenReload); document.querySelector('#button-print').addEventListener('click', printPdf); // 4. Display the correct view let view = localStorage.getItem('view'); if(view == "print"){ printPreview(); } }); /* PREVIEW ----------------------------------------------------------- */ function printPreview() { localStorage.setItem('view', 'print'); let inputPrint = document.getElementById("input-print"); document.getElementById("button-print").disabled = true; if(inputPrint.checked){ document.getElementById("button-print").disabled = false; }else{ document.getElementById("style-screen").remove(); let bookcontent = document.querySelector("#content"); let content = bookcontent.innerHTML; bookcontent.innerHTML = ""; // 1. Create Previewer let previewer = new Previewer(); // 2. Register Handlers previewer.registerHandlers( class PreviewHandler extends Handler { afterPreview() { document.getElementById("button-print").disabled = false; } } ); // 3. Render previewer.preview( content, ["css/print.css"], document.querySelector("#renderbook") ); inputPrint.checked = "true"; } }; /* SCREEN ----------------------------------------------------------- */ function screenReload() { localStorage.setItem('view', 'screen'); window.location.reload(false); }; /* PRINT ----------------------------------------------------------- */ function printPdf() { let inputPrint = document.getElementById("input-print"); if(inputPrint.checked){ window.print(); }else{ document.getElementById("style-screen").remove(); let bookcontent = document.querySelector("#content"); let content = bookcontent.innerHTML; bookcontent.innerHTML = ""; // 1. Create Previewer let previewer = new Previewer(); // 2. Register Handlers previewer.registerHandlers( class PrintHandler extends Handler { afterPreview () { window.print(); } } ); // 3. Render previewer.preview( content, ["css/print.css"], document.querySelector("#renderbook") ); document.getElementById("input-print").checked = "true"; } };