mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
[api-minor] Remove the getGlobalEventBus
viewer functionality (PR 11631 follow-up)
The correct/intended way of working with the "viewer components" is by providing an `EventBus` instance upon initialization, and the `getGlobalEventBus` was only added for backwards compatibility. Note, for example, that using `getGlobalEventBus` doesn't really work at all well with a use-case where there's *multiple* `PDFViewer` instances on a one page, since it may then be difficult/impossible to tell which viewer a particular event originated from. All of the "viewer components" examples have been previously updated, such that there's no longer any code/examples which relies on the now removed `getGlobalEventBus` functionality.
This commit is contained in:
parent
c12ea21c14
commit
7fd5f2dd61
8 changed files with 10 additions and 26 deletions
|
@ -17,7 +17,6 @@ import {
|
||||||
CSS_UNITS,
|
CSS_UNITS,
|
||||||
DEFAULT_SCALE,
|
DEFAULT_SCALE,
|
||||||
DEFAULT_SCALE_VALUE,
|
DEFAULT_SCALE_VALUE,
|
||||||
getGlobalEventBus,
|
|
||||||
getVisibleElements,
|
getVisibleElements,
|
||||||
isPortraitOrientation,
|
isPortraitOrientation,
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
|
@ -145,7 +144,7 @@ class BaseViewer {
|
||||||
|
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.viewer = options.viewer || options.container.firstElementChild;
|
this.viewer = options.viewer || options.container.firstElementChild;
|
||||||
this.eventBus = options.eventBus || getGlobalEventBus();
|
this.eventBus = options.eventBus;
|
||||||
this.linkService = options.linkService || new SimpleLinkService();
|
this.linkService = options.linkService || new SimpleLinkService();
|
||||||
this.downloadManager = options.downloadManager || null;
|
this.downloadManager = options.downloadManager || null;
|
||||||
this.findController = options.findController || null;
|
this.findController = options.findController || null;
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, NullL10n } from "./ui_utils.js";
|
|
||||||
import { FindState } from "./pdf_find_controller.js";
|
import { FindState } from "./pdf_find_controller.js";
|
||||||
|
import { NullL10n } from "./ui_utils.js";
|
||||||
|
|
||||||
const MATCHES_COUNT_LIMIT = 1000;
|
const MATCHES_COUNT_LIMIT = 1000;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class PDFFindBar {
|
||||||
this.findResultsCount = options.findResultsCount || null;
|
this.findResultsCount = options.findResultsCount || null;
|
||||||
this.findPreviousButton = options.findPreviousButton || null;
|
this.findPreviousButton = options.findPreviousButton || null;
|
||||||
this.findNextButton = options.findNextButton || null;
|
this.findNextButton = options.findNextButton || null;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.l10n = l10n;
|
this.l10n = l10n;
|
||||||
|
|
||||||
// Add event listeners to the DOM elements.
|
// Add event listeners to the DOM elements.
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, scrollIntoView } from "./ui_utils.js";
|
|
||||||
import { createPromiseCapability } from "pdfjs-lib";
|
import { createPromiseCapability } from "pdfjs-lib";
|
||||||
import { getCharacterType } from "./pdf_find_utils.js";
|
import { getCharacterType } from "./pdf_find_utils.js";
|
||||||
|
import { scrollIntoView } from "./ui_utils.js";
|
||||||
|
|
||||||
const FindState = {
|
const FindState = {
|
||||||
FOUND: 0,
|
FOUND: 0,
|
||||||
|
@ -69,7 +69,7 @@ class PDFFindController {
|
||||||
*/
|
*/
|
||||||
constructor({ linkService, eventBus }) {
|
constructor({ linkService, eventBus }) {
|
||||||
this._linkService = linkService;
|
this._linkService = linkService;
|
||||||
this._eventBus = eventBus || getGlobalEventBus();
|
this._eventBus = eventBus;
|
||||||
|
|
||||||
this._reset();
|
this._reset();
|
||||||
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getGlobalEventBus,
|
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
parseQueryString,
|
parseQueryString,
|
||||||
waitOnEventOrTimeout,
|
waitOnEventOrTimeout,
|
||||||
|
@ -59,7 +58,7 @@ class PDFHistory {
|
||||||
*/
|
*/
|
||||||
constructor({ linkService, eventBus }) {
|
constructor({ linkService, eventBus }) {
|
||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this._initialized = false;
|
this._initialized = false;
|
||||||
this._fingerprint = "";
|
this._fingerprint = "";
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, parseQueryString } from "./ui_utils.js";
|
import { parseQueryString } from "./ui_utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFLinkServiceOptions
|
* @typedef {Object} PDFLinkServiceOptions
|
||||||
|
@ -44,7 +44,7 @@ class PDFLinkService {
|
||||||
externalLinkEnabled = true,
|
externalLinkEnabled = true,
|
||||||
ignoreDestinationZoom = false,
|
ignoreDestinationZoom = false,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.externalLinkTarget = externalLinkTarget;
|
this.externalLinkTarget = externalLinkTarget;
|
||||||
this.externalLinkRel = externalLinkRel;
|
this.externalLinkRel = externalLinkRel;
|
||||||
this.externalLinkEnabled = externalLinkEnabled;
|
this.externalLinkEnabled = externalLinkEnabled;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {
|
||||||
approximateFraction,
|
approximateFraction,
|
||||||
CSS_UNITS,
|
CSS_UNITS,
|
||||||
DEFAULT_SCALE,
|
DEFAULT_SCALE,
|
||||||
getGlobalEventBus,
|
|
||||||
getOutputScale,
|
getOutputScale,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
RendererType,
|
RendererType,
|
||||||
|
@ -92,7 +91,7 @@ class PDFPageView {
|
||||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||||
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
||||||
|
|
||||||
this.eventBus = options.eventBus || getGlobalEventBus();
|
this.eventBus = options.eventBus;
|
||||||
this.renderingQueue = options.renderingQueue;
|
this.renderingQueue = options.renderingQueue;
|
||||||
this.textLayerFactory = options.textLayerFactory;
|
this.textLayerFactory = options.textLayerFactory;
|
||||||
this.annotationLayerFactory = options.annotationLayerFactory;
|
this.annotationLayerFactory = options.annotationLayerFactory;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus } from "./ui_utils.js";
|
|
||||||
import { renderTextLayer } from "pdfjs-lib";
|
import { renderTextLayer } from "pdfjs-lib";
|
||||||
|
|
||||||
const EXPAND_DIVS_TIMEOUT = 300; // ms
|
const EXPAND_DIVS_TIMEOUT = 300; // ms
|
||||||
|
@ -45,7 +44,7 @@ class TextLayerBuilder {
|
||||||
enhanceTextSelection = false,
|
enhanceTextSelection = false,
|
||||||
}) {
|
}) {
|
||||||
this.textLayerDiv = textLayerDiv;
|
this.textLayerDiv = textLayerDiv;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.textContent = null;
|
this.textContent = null;
|
||||||
this.textContentItemsStr = [];
|
this.textContentItemsStr = [];
|
||||||
this.textContentStream = null;
|
this.textContentStream = null;
|
||||||
|
|
|
@ -884,17 +884,6 @@ class EventBus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let globalEventBus = null;
|
|
||||||
function getGlobalEventBus(dispatchToDOM = false) {
|
|
||||||
console.error(
|
|
||||||
"getGlobalEventBus is deprecated, use a manually created EventBus instance instead."
|
|
||||||
);
|
|
||||||
if (!globalEventBus) {
|
|
||||||
globalEventBus = new EventBus({ dispatchToDOM });
|
|
||||||
}
|
|
||||||
return globalEventBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clamp(v, min, max) {
|
function clamp(v, min, max) {
|
||||||
return Math.min(Math.max(v, min), max);
|
return Math.min(Math.max(v, min), max);
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1002,6 @@ export {
|
||||||
SpreadMode,
|
SpreadMode,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
EventBus,
|
EventBus,
|
||||||
getGlobalEventBus,
|
|
||||||
clamp,
|
clamp,
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
getPDFFileNameFromURL,
|
getPDFFileNameFromURL,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue