mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Replace callbacks for updating the UI with dispatching events on the event bus
This makes it more similar to how other components update the viewer UI and avoids the need to have extra member variables and checks.
This commit is contained in:
parent
e0c811f2ed
commit
38ff79186a
2 changed files with 34 additions and 32 deletions
43
web/app.js
43
web/app.js
|
@ -346,25 +346,6 @@ let PDFViewerApplication = {
|
|||
linkService: pdfLinkService,
|
||||
eventBus,
|
||||
});
|
||||
this.findController.onUpdateResultsCount = (matchesCount) => {
|
||||
if (this.supportsIntegratedFind) {
|
||||
this.externalServices.updateFindMatchesCount(matchesCount);
|
||||
} else {
|
||||
this.findBar.updateResultsCount(matchesCount);
|
||||
}
|
||||
};
|
||||
this.findController.onUpdateState = (state, previous, matchesCount) => {
|
||||
if (this.supportsIntegratedFind) {
|
||||
this.externalServices.updateFindControlState({
|
||||
result: state,
|
||||
findPrevious: previous,
|
||||
matchesCount,
|
||||
});
|
||||
} else {
|
||||
this.findBar.updateUIState(state, previous, matchesCount);
|
||||
}
|
||||
};
|
||||
|
||||
this.pdfViewer.setFindController(this.findController);
|
||||
|
||||
// TODO: improve `PDFFindBar` constructor parameter passing
|
||||
|
@ -1343,6 +1324,8 @@ let PDFViewerApplication = {
|
|||
eventBus.on('documentproperties', webViewerDocumentProperties);
|
||||
eventBus.on('find', webViewerFind);
|
||||
eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
|
||||
eventBus.on('updatefindmatchescount', webViewerUpdateFindMatchesCount);
|
||||
eventBus.on('updatefindcontrolstate', webViewerUpdateFindControlState);
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
eventBus.on('fileinputchange', webViewerFileInputChange);
|
||||
}
|
||||
|
@ -1414,6 +1397,8 @@ let PDFViewerApplication = {
|
|||
eventBus.off('documentproperties', webViewerDocumentProperties);
|
||||
eventBus.off('find', webViewerFind);
|
||||
eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
|
||||
eventBus.off('updatefindmatchescount', webViewerUpdateFindMatchesCount);
|
||||
eventBus.off('updatefindcontrolstate', webViewerUpdateFindControlState);
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
eventBus.off('fileinputchange', webViewerFileInputChange);
|
||||
}
|
||||
|
@ -1976,6 +1961,26 @@ function webViewerFindFromUrlHash(evt) {
|
|||
});
|
||||
}
|
||||
|
||||
function webViewerUpdateFindMatchesCount({ matchesCount, }) {
|
||||
if (PDFViewerApplication.supportsIntegratedFind) {
|
||||
PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
|
||||
} else {
|
||||
PDFViewerApplication.findBar.updateResultsCount(matchesCount);
|
||||
}
|
||||
}
|
||||
|
||||
function webViewerUpdateFindControlState({ state, previous, matchesCount, }) {
|
||||
if (PDFViewerApplication.supportsIntegratedFind) {
|
||||
PDFViewerApplication.externalServices.updateFindControlState({
|
||||
result: state,
|
||||
findPrevious: previous,
|
||||
matchesCount,
|
||||
});
|
||||
} else {
|
||||
PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
|
||||
}
|
||||
}
|
||||
|
||||
function webViewerScaleChanging(evt) {
|
||||
PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
|
||||
|
||||
|
|
|
@ -57,9 +57,6 @@ class PDFFindController {
|
|||
this._linkService = linkService;
|
||||
this._eventBus = eventBus;
|
||||
|
||||
this.onUpdateResultsCount = null;
|
||||
this.onUpdateState = null;
|
||||
|
||||
this._reset();
|
||||
|
||||
eventBus.on('findbarclose', () => {
|
||||
|
@ -564,19 +561,19 @@ class PDFFindController {
|
|||
}
|
||||
|
||||
_updateUIResultsCount() {
|
||||
if (!this.onUpdateResultsCount) {
|
||||
return;
|
||||
}
|
||||
const matchesCount = this._requestMatchesCount();
|
||||
this.onUpdateResultsCount(matchesCount);
|
||||
this._eventBus.dispatch('updatefindmatchescount', {
|
||||
source: this,
|
||||
matchesCount: this._requestMatchesCount(),
|
||||
});
|
||||
}
|
||||
|
||||
_updateUIState(state, previous) {
|
||||
if (!this.onUpdateState) {
|
||||
return;
|
||||
}
|
||||
const matchesCount = this._requestMatchesCount();
|
||||
this.onUpdateState(state, previous, matchesCount);
|
||||
this._eventBus.dispatch('updatefindcontrolstate', {
|
||||
source: this,
|
||||
state,
|
||||
previous,
|
||||
matchesCount: this._requestMatchesCount(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue