Files
d9-eql/web/themes/custom/eql/dist/assets/js/paged-setup.js
T
2025-07-21 18:39:34 +02:00

32 lines
6.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (function() { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./scripts/paged-setup.js":
/*!********************************!*\
!*** ./scripts/paged-setup.js ***!
\********************************/
/***/ (function() {
eval("// window.runPagedIfPrinting = function () {\n// console.log(\"📄 Impression via iframe\");\n \n// // 1. Créer une iframe cachée\n// const iframe = document.createElement(\"iframe\");\n// iframe.style.position = \"fixed\";\n// iframe.style.left = \"-100vw\"; // hors de la vue\n// iframe.style.top = \"-100vh\";\n// iframe.style.width = \"0\";\n// iframe.style.height = \"0\";\n// iframe.style.visibility = \"hidden\";\n// iframe.setAttribute(\"aria-hidden\", \"true\");\n \n// document.body.appendChild(iframe);\n \n// // 2. Copier tout le document dans liframe\n// const clonedHTML = document.documentElement.outerHTML;\n// const doc = iframe.contentWindow.document;\n// doc.open();\n// doc.write(clonedHTML);\n// doc.close();\n \n// // 3. Attendre que tout soit chargé\n// iframe.onload = () => {\n// console.log(\"📦 Iframe chargée, injection manuelle de Paged.js\");\n \n// const pagedScript = iframe.contentDocument.createElement(\"script\");\n// pagedScript.src = \"https://unpkg.com/pagedjs/dist/paged.js\";\n// pagedScript.onload = () => {\n// console.log(\"📚 Paged.js chargé, génération des pages...\");\n \n// const previewer = new iframe.contentWindow.Paged.Previewer();\n \n// previewer.preview().then(() => {\n// console.log(\"🖨️ Aperçu prêt, impression dans iframe…\");\n \n// setTimeout(() => {\n// const printScript = iframe.contentDocument.createElement(\"script\");\n// printScript.textContent = `\n// window.addEventListener(\"load\", () => {\n// setTimeout(() => {\n// window.print();\n// window.onafterprint = () => window.close(); // facultatif\n// }, 100);\n// });\n// `;\n// iframe.contentDocument.body.appendChild(printScript);\n// }, 300);\n \n// });\n// };\n \n// // Injecte le script dans <head> de liframe\n// iframe.contentDocument.head.appendChild(pagedScript);\n// };\n \n// };\n \n// // 📎 Listeners impression\n// function setupPagedPrintListeners() {\n// window.addEventListener(\"beforeprint\", (e) => {\n// e.preventDefault(); // empêcher la version native\n// });\n \n// if (window.matchMedia) {\n// window.matchMedia(\"print\").addEventListener(\"change\", (e) => {\n// if (e.matches) {\n// window.runPagedIfPrinting();\n// }\n// });\n// }\n \n// console.log(\"✅ Paged.js listeners (iframe) installés.\");\n// }\n \n// if (document.readyState !== \"loading\") {\n// setupPagedPrintListeners();\n// } else {\n// document.addEventListener(\"DOMContentLoaded\", setupPagedPrintListeners);\n// }\n \n\nwindow.runPagedIfPrinting = function () {\n console.log(\"📄 Impression détectée — Paged.js va s'exécuter\");\n \n if (typeof Paged !== \"undefined\" && Paged.Previewer) {\n // Sauvegarde du DOM actuel\n const original = document.body.cloneNode(true);\n \n const previewer = new Paged.Previewer();\n \n previewer.preview().then(() => {\n console.log(\"📃 Paged.js rendu terminé\");\n \n const restoreDOM = () => {\n console.log(\"🔄 Restauration du DOM après impression\");\n document.body.replaceWith(original);\n window.removeEventListener(\"afterprint\", restoreDOM);\n };\n \n // ✅ Restauration après impression (ou annulation)\n window.addEventListener(\"afterprint\", restoreDOM);\n });\n } else {\n console.warn(\"❌ Paged.js non chargé ou Previewer indisponible !\");\n }\n };\n \n // Initialisation automatique\n function setupPagedPrintListeners() {\n // Classique\n window.addEventListener(\"beforeprint\", window.runPagedIfPrinting);\n \n // Pour certains navigateurs modernes\n if (window.matchMedia) {\n const mediaQueryList = window.matchMedia(\"print\");\n if (mediaQueryList.addEventListener) {\n mediaQueryList.addEventListener(\"change\", (e) => {\n if (e.matches) {\n window.runPagedIfPrinting();\n }\n });\n } else {\n // Safari fallback\n mediaQueryList.addListener((e) => {\n if (e.matches) {\n window.runPagedIfPrinting();\n }\n });\n }\n }\n \n console.log(\"✅ Paged.js listeners installés.\");\n }\n \n // Démarrage au bon moment\n if (document.readyState !== \"loading\") {\n setupPagedPrintListeners();\n } else {\n document.addEventListener(\"DOMContentLoaded\", setupPagedPrintListeners);\n }\n \n\n//# sourceURL=webpack://dev.eql.fr/./scripts/paged-setup.js?");
/***/ })
/******/ });
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./scripts/paged-setup.js"]();
/******/
/******/ })()
;