1
0
forked from poc/pds
Files
poc-pds1/public/js/app/filament-export-0.3.0.js
2025-04-28 00:11:34 +05:30

36 lines
1.0 KiB
JavaScript

function onElementRemoved(element, callback) {
new MutationObserver(function (mutations) {
if (!document.body.contains(element)) {
callback();
this.disconnect();
}
}).observe(element.parentElement, { childList: true });
}
function triggerInputEvent(statePath, value) {
let input = document.getElementById(statePath);
input.value = value;
input.dispatchEvent(new Event('input', { bubbles: true }));
}
function printHTML(html, statePath, uniqueActionId) {
let iframe = document.createElement("iframe");
let random = Math.floor(Math.random() * 99999);
iframe.id = `print-${random}`;
iframe.srcdoc = html;
document.body.append(iframe);
onElementRemoved(iframe, () => triggerInputEvent(statePath, `afterprint-${uniqueActionId}`));
iframe.contentWindow.onafterprint = () => document.getElementById(iframe.id).remove();
iframe.contentWindow.onload = () => iframe.contentWindow.print();
}
window.triggerInputEvent = triggerInputEvent;
window.printHTML = printHTML;