otsdaq_utilities  v2_05_02_indev
print.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 
3 var Print = function Print(table) {
4  this.table = table; //hold Tabulator object
5  this.element = false;
6  this.manualBlock = false;
7 };
8 
9 Print.prototype.initialize = function () {
10  window.addEventListener("beforeprint", this.replaceTable.bind(this));
11  window.addEventListener("afterprint", this.cleanup.bind(this));
12 };
13 
14 Print.prototype.replaceTable = function () {
15  if (!this.manualBlock) {
16  this.element = document.createElement("div");
17  this.element.classList.add("tabulator-print-table");
18 
19  this.element.appendChild(this.table.modules.htmlTableExport.genereateTable(this.table.options.printConfig, this.table.options.printCopyStyle, this.table.options.printVisibleRows, "print"));
20 
21  this.table.element.style.display = "none";
22 
23  this.table.element.parentNode.insertBefore(this.element, this.table.element);
24  }
25 };
26 
27 Print.prototype.cleanup = function () {
28  document.body.classList.remove("tabulator-print-fullscreen-hide");
29 
30  if (this.element && this.element.parentNode) {
31  this.element.parentNode.removeChild(this.element);
32  this.table.element.style.display = "";
33  }
34 };
35 
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"),
42  headerContent,
43  footerContent;
44 
45  this.manualBlock = true;
46 
47  this.element = document.createElement("div");
48  this.element.classList.add("tabulator-print-fullscreen");
49 
50  if (this.table.options.printHeader) {
51  headerEl.classList.add("tabulator-print-header");
52 
53  headerContent = typeof this.table.options.printHeader == "function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
54 
55  if (typeof headerContent == "string") {
56  headerEl.innerHTML = headerContent;
57  } else {
58  headerEl.appendChild(headerContent);
59  }
60 
61  this.element.appendChild(headerEl);
62  }
63 
64  this.element.appendChild(tableEl);
65 
66  if (this.table.options.printFooter) {
67  footerEl.classList.add("tabulator-print-footer");
68 
69  footerContent = typeof this.table.options.printFooter == "function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
70 
71  if (typeof footerContent == "string") {
72  footerEl.innerHTML = footerContent;
73  } else {
74  footerEl.appendChild(footerContent);
75  }
76 
77  this.element.appendChild(footerEl);
78  }
79 
80  document.body.classList.add("tabulator-print-fullscreen-hide");
81  document.body.appendChild(this.element);
82 
83  if (this.table.options.printFormatter) {
84  this.table.options.printFormatter(this.element, tableEl);
85  }
86 
87  window.print();
88 
89  this.cleanup();
90 
91  window.scrollTo(scrollX, scrollY);
92 
93  this.manualBlock = false;
94 };
95 
96 Tabulator.prototype.registerModule("print", Print);