1 var Print =
function(table){
4 this.manualBlock =
false;
7 Print.prototype.initialize =
function(){
8 window.addEventListener(
"beforeprint", this.replaceTable.bind(
this));
9 window.addEventListener(
"afterprint", this.cleanup.bind(
this));
12 Print.prototype.replaceTable =
function(){
13 if(!this.manualBlock){
14 this.element = document.createElement(
"div");
15 this.element.classList.add(
"tabulator-print-table");
17 this.element.appendChild(this.table.modules.htmlTableExport.genereateTable(
this.table.options.printConfig,
this.table.options.printCopyStyle,
this.table.options.printVisibleRows,
"print"));
19 this.table.element.style.display =
"none";
21 this.table.element.parentNode.insertBefore(this.element, this.table.element);
25 Print.prototype.cleanup =
function(){
26 document.body.classList.remove(
"tabulator-print-fullscreen-hide");
28 if(this.element && this.element.parentNode){
29 this.element.parentNode.removeChild(this.element);
30 this.table.element.style.display =
"";
34 Print.prototype.printFullscreen =
function(visible, style, config){
35 var scrollX = window.scrollX,
36 scrollY = window.scrollY,
37 headerEl = document.createElement(
"div"),
38 footerEl = document.createElement(
"div"),
39 tableEl = this.table.modules.htmlTableExport.genereateTable(typeof config !=
"undefined" ? config : this.table.options.printConfig, typeof style !=
"undefined" ? style :
this.table.options.printCopyStyle, visible,
"print"),
40 headerContent, footerContent;
42 this.manualBlock =
true;
44 this.element = document.createElement(
"div");
45 this.element.classList.add(
"tabulator-print-fullscreen");
47 if(this.table.options.printHeader){
48 headerEl.classList.add(
"tabulator-print-header");
50 headerContent = typeof this.table.options.printHeader ==
"function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
52 if(typeof headerContent ==
"string"){
53 headerEl.innerHTML = headerContent;
55 headerEl.appendChild(headerContent);
58 this.element.appendChild(headerEl);
61 this.element.appendChild(tableEl);
63 if(this.table.options.printFooter){
64 footerEl.classList.add(
"tabulator-print-footer");
66 footerContent = typeof this.table.options.printFooter ==
"function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
69 if(typeof footerContent ==
"string"){
70 footerEl.innerHTML = footerContent;
72 footerEl.appendChild(footerContent);
75 this.element.appendChild(footerEl);
78 document.body.classList.add(
"tabulator-print-fullscreen-hide");
79 document.body.appendChild(this.element);
81 if(this.table.options.printFormatter){
82 this.table.options.printFormatter(this.element, tableEl);
89 window.scrollTo(scrollX, scrollY);
91 this.manualBlock =
false;
94 Tabulator.prototype.registerModule(
"print", Print);