3 var Print =
function Print(table) {
6 this.manualBlock =
false;
9 Print.prototype.initialize =
function () {
10 window.addEventListener(
"beforeprint", this.replaceTable.bind(
this));
11 window.addEventListener(
"afterprint", this.cleanup.bind(
this));
14 Print.prototype.replaceTable =
function () {
15 if (!this.manualBlock) {
16 this.element = document.createElement(
"div");
17 this.element.classList.add(
"tabulator-print-table");
19 this.element.appendChild(this.table.modules.htmlTableExport.genereateTable(
this.table.options.printConfig,
this.table.options.printCopyStyle,
this.table.options.printVisibleRows,
"print"));
21 this.table.element.style.display =
"none";
23 this.table.element.parentNode.insertBefore(this.element, this.table.element);
27 Print.prototype.cleanup =
function () {
28 document.body.classList.remove(
"tabulator-print-fullscreen-hide");
30 if (this.element && this.element.parentNode) {
31 this.element.parentNode.removeChild(this.element);
32 this.table.element.style.display =
"";
36 Print.prototype.printFullscreen =
function (visible, style, config) {
37 var scrollX = window.scrollX,
38 scrollY = window.scrollY,
39 headerEl = document.createElement(
"div"),
40 footerEl = document.createElement(
"div"),
41 tableEl = this.table.modules.htmlTableExport.genereateTable(typeof config !=
"undefined" ? config : this.table.options.printConfig, typeof style !=
"undefined" ? style :
this.table.options.printCopyStyle, visible,
"print"),
45 this.manualBlock =
true;
47 this.element = document.createElement(
"div");
48 this.element.classList.add(
"tabulator-print-fullscreen");
50 if (this.table.options.printHeader) {
51 headerEl.classList.add(
"tabulator-print-header");
53 headerContent = typeof this.table.options.printHeader ==
"function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
55 if (typeof headerContent ==
"string") {
56 headerEl.innerHTML = headerContent;
58 headerEl.appendChild(headerContent);
61 this.element.appendChild(headerEl);
64 this.element.appendChild(tableEl);
66 if (this.table.options.printFooter) {
67 footerEl.classList.add(
"tabulator-print-footer");
69 footerContent = typeof this.table.options.printFooter ==
"function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
71 if (typeof footerContent ==
"string") {
72 footerEl.innerHTML = footerContent;
74 footerEl.appendChild(footerContent);
77 this.element.appendChild(footerEl);
80 document.body.classList.add(
"tabulator-print-fullscreen-hide");
81 document.body.appendChild(this.element);
83 if (this.table.options.printFormatter) {
84 this.table.options.printFormatter(this.element, tableEl);
91 window.scrollTo(scrollX, scrollY);
93 this.manualBlock =
false;
96 Tabulator.prototype.registerModule(
"print", Print);