Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

print.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Tabulator v4.6.3 (c) Oliver Folkerd */
  2. var Print = function Print(table) {
  3. this.table = table; //hold Tabulator object
  4. this.element = false;
  5. this.manualBlock = false;
  6. };
  7. Print.prototype.initialize = function () {
  8. window.addEventListener("beforeprint", this.replaceTable.bind(this));
  9. window.addEventListener("afterprint", this.cleanup.bind(this));
  10. };
  11. Print.prototype.replaceTable = function () {
  12. if (!this.manualBlock) {
  13. this.element = document.createElement("div");
  14. this.element.classList.add("tabulator-print-table");
  15. this.element.appendChild(this.table.modules.export.genereateTable(this.table.options.printConfig, this.table.options.printStyled, this.table.options.printRowRange, "print"));
  16. this.table.element.style.display = "none";
  17. this.table.element.parentNode.insertBefore(this.element, this.table.element);
  18. }
  19. };
  20. Print.prototype.cleanup = function () {
  21. document.body.classList.remove("tabulator-print-fullscreen-hide");
  22. if (this.element && this.element.parentNode) {
  23. this.element.parentNode.removeChild(this.element);
  24. this.table.element.style.display = "";
  25. }
  26. };
  27. Print.prototype.printFullscreen = function (visible, style, config) {
  28. var scrollX = window.scrollX,
  29. scrollY = window.scrollY,
  30. headerEl = document.createElement("div"),
  31. footerEl = document.createElement("div"),
  32. tableEl = this.table.modules.export.genereateTable(typeof config != "undefined" ? config : this.table.options.printConfig, typeof style != "undefined" ? style : this.table.options.printStyled, visible, "print"),
  33. headerContent,
  34. footerContent;
  35. this.manualBlock = true;
  36. this.element = document.createElement("div");
  37. this.element.classList.add("tabulator-print-fullscreen");
  38. if (this.table.options.printHeader) {
  39. headerEl.classList.add("tabulator-print-header");
  40. headerContent = typeof this.table.options.printHeader == "function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
  41. if (typeof headerContent == "string") {
  42. headerEl.innerHTML = headerContent;
  43. } else {
  44. headerEl.appendChild(headerContent);
  45. }
  46. this.element.appendChild(headerEl);
  47. }
  48. this.element.appendChild(tableEl);
  49. if (this.table.options.printFooter) {
  50. footerEl.classList.add("tabulator-print-footer");
  51. footerContent = typeof this.table.options.printFooter == "function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
  52. if (typeof footerContent == "string") {
  53. footerEl.innerHTML = footerContent;
  54. } else {
  55. footerEl.appendChild(footerContent);
  56. }
  57. this.element.appendChild(footerEl);
  58. }
  59. document.body.classList.add("tabulator-print-fullscreen-hide");
  60. document.body.appendChild(this.element);
  61. if (this.table.options.printFormatter) {
  62. this.table.options.printFormatter(this.element, tableEl);
  63. }
  64. window.print();
  65. this.cleanup();
  66. window.scrollTo(scrollX, scrollY);
  67. this.manualBlock = false;
  68. };
  69. Tabulator.prototype.registerModule("print", Print);