viewer-geckoview.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright 2016 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
  16. import { AppOptions } from "./app_options.js";
  17. import { LinkTarget } from "./pdf_link_service.js";
  18. import { PDFViewerApplication } from "./app.js";
  19. /* eslint-disable-next-line no-unused-vars */
  20. const pdfjsVersion =
  21. typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
  22. /* eslint-disable-next-line no-unused-vars */
  23. const pdfjsBuild =
  24. typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
  25. const AppConstants =
  26. typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
  27. ? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
  28. : null;
  29. window.PDFViewerApplication = PDFViewerApplication;
  30. window.PDFViewerApplicationConstants = AppConstants;
  31. window.PDFViewerApplicationOptions = AppOptions;
  32. if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
  33. require("./firefoxcom.js");
  34. require("./firefox_print_service.js");
  35. }
  36. function getViewerConfiguration() {
  37. return {
  38. appContainer: document.body,
  39. mainContainer: document.getElementById("viewerContainer"),
  40. viewerContainer: document.getElementById("viewer"),
  41. passwordOverlay: {
  42. dialog: document.getElementById("passwordDialog"),
  43. label: document.getElementById("passwordText"),
  44. input: document.getElementById("password"),
  45. submitButton: document.getElementById("passwordSubmit"),
  46. cancelButton: document.getElementById("passwordCancel"),
  47. },
  48. printContainer: document.getElementById("printContainer"),
  49. openFileInput:
  50. typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
  51. ? document.getElementById("fileInput")
  52. : null,
  53. };
  54. }
  55. function webViewerLoad() {
  56. const config = getViewerConfiguration();
  57. if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
  58. if (window.chrome) {
  59. const link = document.createElement("link");
  60. link.rel = "stylesheet";
  61. link.href = "../build/dev-css/viewer.css";
  62. document.head.append(link);
  63. }
  64. Promise.all([
  65. import("pdfjs-web/genericcom.js"),
  66. import("pdfjs-web/pdf_print_service.js"),
  67. ]).then(function ([genericCom, pdfPrintService]) {
  68. PDFViewerApplication.run(config);
  69. });
  70. } else {
  71. PDFViewerApplication.run(config);
  72. }
  73. }
  74. // Block the "load" event until all pages are loaded, to ensure that printing
  75. // works in Firefox; see https://bugzilla.mozilla.org/show_bug.cgi?id=1618553
  76. document.blockUnblockOnload?.(true);
  77. if (
  78. document.readyState === "interactive" ||
  79. document.readyState === "complete"
  80. ) {
  81. webViewerLoad();
  82. } else {
  83. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  84. }
  85. export {
  86. PDFViewerApplication,
  87. AppConstants as PDFViewerApplicationConstants,
  88. AppOptions as PDFViewerApplicationOptions,
  89. };