Package for export pdf
This commit is contained in:
36
public/js/app/filament-export-0.3.0.js
Normal file
36
public/js/app/filament-export-0.3.0.js
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user