Skip to content

Commit

Permalink
Refactors PDFFindBar and FirefoxCom find events.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Apr 26, 2016
1 parent bf0ba15 commit 4cf8b01
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
11 changes: 10 additions & 1 deletion web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ var PDFViewerApplication = {
this.findBar.updateUIState(state, previous, matchCount);
}
}.bind(this);
this.findController.listenWindowEvents();

this.pdfViewer.setFindController(this.findController);

Expand Down Expand Up @@ -1250,6 +1249,7 @@ var PDFViewerApplication = {
eventBus.on('pagemode', webViewerPageMode);
eventBus.on('namedaction', webViewerNamedAction);
eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
eventBus.on('find', webViewerFind);
}
};

Expand Down Expand Up @@ -1825,6 +1825,15 @@ function webViewerLocalized() {
});
}

function webViewerFind(e) {
PDFViewerApplication.findController.executeCommand('find' + e.type, {
query: e.query,
caseSensitive: e.caseSensitive,
highlightAll: e.highlightAll,
findPrevious: e.findPrevious
});
}

function webViewerScaleChange(e) {
var appConfig = PDFViewerApplication.appConfig;
appConfig.toolbar.zoomOut.disabled = (e.scale === MIN_SCALE);
Expand Down
3 changes: 3 additions & 0 deletions web/dom_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
e.source.container.dispatchEvent(event);
});
eventBus.on('find', function (e) {
if (e.source === window) {
return; // event comes from FirefoxCom, no need to replicate
}
var event = document.createEvent('CustomEvent');
event.initCustomEvent('find' + e.type, true, true, {
query: e.query,
Expand Down
26 changes: 26 additions & 0 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ Preferences._readFromStorage = function (prefObj) {
});
};

(function listenFindEvents() {
var events = [
'find',
'findagain',
'findhighlightallchange',
'findcasesensitivitychange'
];
var handleEvent = function (evt) {
if (!PDFViewerApplication.initialized) {
return;
}
PDFViewerApplication.eventBus.dispatch('find', {
source: window,
type: evt.type.substring('find'.length),
query: evt.detail.query,
caseSensitive: !!evt.detail.caseSensitive,
highlightAll: !!evt.detail.highlightAll,
findPrevious: !!evt.detail.findPrevious
});
}.bind(this);

for (var i = 0, len = events.length; i < len; i++) {
window.addEventListener(events[i], handleEvent);
}
})();

function FirefoxComDataRangeTransport(length, initialData) {
pdfjsLib.PDFDataRangeTransport.call(this, length, initialData);
}
Expand Down
16 changes: 0 additions & 16 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ var PDFFindController = (function PDFFindControllerClosure() {
}

PDFFindController.prototype = {
listenWindowEvents: function PDFFindController_listenWindowEvents() {
var events = [
'find',
'findagain',
'findhighlightallchange',
'findcasesensitivitychange'
];
var handleEvent = function (e) {
this.executeCommand(e.type, e.detail);
}.bind(this);

for (var i = 0, len = events.length; i < len; i++) {
window.addEventListener(events[i], handleEvent);
}
},

reset: function PDFFindController_reset() {
this.startedTextExtraction = false;
this.extractTextPromises = [];
Expand Down

0 comments on commit 4cf8b01

Please sign in to comment.