dom_events.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.getGlobalEventBus = exports.attachDOMEventsToEventBus = undefined;
  27. var _ui_utils = require('./ui_utils');
  28. function attachDOMEventsToEventBus(eventBus) {
  29. eventBus.on('documentload', function () {
  30. var event = document.createEvent('CustomEvent');
  31. event.initCustomEvent('documentload', true, true, {});
  32. window.dispatchEvent(event);
  33. });
  34. eventBus.on('pagerendered', function (evt) {
  35. var event = document.createEvent('CustomEvent');
  36. event.initCustomEvent('pagerendered', true, true, {
  37. pageNumber: evt.pageNumber,
  38. cssTransform: evt.cssTransform
  39. });
  40. evt.source.div.dispatchEvent(event);
  41. });
  42. eventBus.on('textlayerrendered', function (evt) {
  43. var event = document.createEvent('CustomEvent');
  44. event.initCustomEvent('textlayerrendered', true, true, { pageNumber: evt.pageNumber });
  45. evt.source.textLayerDiv.dispatchEvent(event);
  46. });
  47. eventBus.on('pagechange', function (evt) {
  48. var event = document.createEvent('UIEvents');
  49. event.initUIEvent('pagechange', true, true, window, 0);
  50. event.pageNumber = evt.pageNumber;
  51. evt.source.container.dispatchEvent(event);
  52. });
  53. eventBus.on('pagesinit', function (evt) {
  54. var event = document.createEvent('CustomEvent');
  55. event.initCustomEvent('pagesinit', true, true, null);
  56. evt.source.container.dispatchEvent(event);
  57. });
  58. eventBus.on('pagesloaded', function (evt) {
  59. var event = document.createEvent('CustomEvent');
  60. event.initCustomEvent('pagesloaded', true, true, { pagesCount: evt.pagesCount });
  61. evt.source.container.dispatchEvent(event);
  62. });
  63. eventBus.on('scalechange', function (evt) {
  64. var event = document.createEvent('UIEvents');
  65. event.initUIEvent('scalechange', true, true, window, 0);
  66. event.scale = evt.scale;
  67. event.presetValue = evt.presetValue;
  68. evt.source.container.dispatchEvent(event);
  69. });
  70. eventBus.on('updateviewarea', function (evt) {
  71. var event = document.createEvent('UIEvents');
  72. event.initUIEvent('updateviewarea', true, true, window, 0);
  73. event.location = evt.location;
  74. evt.source.container.dispatchEvent(event);
  75. });
  76. eventBus.on('find', function (evt) {
  77. if (evt.source === window) {
  78. return;
  79. }
  80. var event = document.createEvent('CustomEvent');
  81. event.initCustomEvent('find' + evt.type, true, true, {
  82. query: evt.query,
  83. phraseSearch: evt.phraseSearch,
  84. caseSensitive: evt.caseSensitive,
  85. highlightAll: evt.highlightAll,
  86. findPrevious: evt.findPrevious
  87. });
  88. window.dispatchEvent(event);
  89. });
  90. eventBus.on('attachmentsloaded', function (evt) {
  91. var event = document.createEvent('CustomEvent');
  92. event.initCustomEvent('attachmentsloaded', true, true, { attachmentsCount: evt.attachmentsCount });
  93. evt.source.container.dispatchEvent(event);
  94. });
  95. eventBus.on('sidebarviewchanged', function (evt) {
  96. var event = document.createEvent('CustomEvent');
  97. event.initCustomEvent('sidebarviewchanged', true, true, { view: evt.view });
  98. evt.source.outerContainer.dispatchEvent(event);
  99. });
  100. eventBus.on('pagemode', function (evt) {
  101. var event = document.createEvent('CustomEvent');
  102. event.initCustomEvent('pagemode', true, true, { mode: evt.mode });
  103. evt.source.pdfViewer.container.dispatchEvent(event);
  104. });
  105. eventBus.on('namedaction', function (evt) {
  106. var event = document.createEvent('CustomEvent');
  107. event.initCustomEvent('namedaction', true, true, { action: evt.action });
  108. evt.source.pdfViewer.container.dispatchEvent(event);
  109. });
  110. eventBus.on('presentationmodechanged', function (evt) {
  111. var event = document.createEvent('CustomEvent');
  112. event.initCustomEvent('presentationmodechanged', true, true, {
  113. active: evt.active,
  114. switchInProgress: evt.switchInProgress
  115. });
  116. window.dispatchEvent(event);
  117. });
  118. eventBus.on('outlineloaded', function (evt) {
  119. var event = document.createEvent('CustomEvent');
  120. event.initCustomEvent('outlineloaded', true, true, { outlineCount: evt.outlineCount });
  121. evt.source.container.dispatchEvent(event);
  122. });
  123. }
  124. var globalEventBus = null;
  125. function getGlobalEventBus() {
  126. if (globalEventBus) {
  127. return globalEventBus;
  128. }
  129. globalEventBus = new _ui_utils.EventBus();
  130. attachDOMEventsToEventBus(globalEventBus);
  131. return globalEventBus;
  132. }
  133. exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
  134. exports.getGlobalEventBus = getGlobalEventBus;