diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js
index 4484afc03..b187fd8cd 100644
--- a/web/pdf_find_bar.js
+++ b/web/pdf_find_bar.js
@@ -32,6 +32,7 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.highlightAll = options.highlightAllCheckbox || null;
this.caseSensitive = options.caseSensitiveCheckbox || null;
this.findMsg = options.findMsg || null;
+ this.findResultsCount = options.findResultsCount || null;
this.findStatusIcon = options.findStatusIcon || null;
this.findPreviousButton = options.findPreviousButton || null;
this.findNextButton = options.findNextButton || null;
@@ -94,7 +95,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
return window.dispatchEvent(event);
},
- updateUIState: function PDFFindBar_updateUIState(state, previous) {
+ updateUIState:
+ function PDFFindBar_updateUIState(state, previous, matchCount) {
var notFound = false;
var findMsg = '';
var status = '';
@@ -131,6 +133,26 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.findField.setAttribute('data-status', status);
this.findMsg.textContent = findMsg;
+
+ this.updateResultsCount(matchCount);
+ },
+
+ updateResultsCount: function(matchCount) {
+ if (!this.findResultsCount) {
+ return; // no UI control is provided
+ }
+
+ // If there are no matches, hide the counter
+ if (!matchCount) {
+ this.findResultsCount.classList.add('hidden');
+ return;
+ }
+
+ // Create the match counter
+ this.findResultsCount.textContent = matchCount.toLocaleString();
+
+ // Show the counter
+ this.findResultsCount.classList.remove('hidden');
},
open: function PDFFindBar_open() {
diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js
index afb563c7d..9d30067bb 100644
--- a/web/pdf_find_controller.js
+++ b/web/pdf_find_controller.js
@@ -39,6 +39,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.active = false; // If active, find results will be highlighted.
this.pageContents = []; // Stores the text for each page.
this.pageMatches = [];
+ this.matchCount = 0;
this.selected = { // Currently selected match.
pageIdx: -1,
matchIdx: -1
@@ -116,7 +117,8 @@ var PDFFindController = (function PDFFindControllerClosure() {
var queryLen = query.length;
if (queryLen === 0) {
- return; // Do nothing: the matches should be wiped out already.
+ // Do nothing: the matches should be wiped out already.
+ return;
}
if (!caseSensitive) {
@@ -139,6 +141,12 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.resumePageIdx = null;
this.nextPageMatch();
}
+
+ // Update the matches count
+ if (matches.length > 0) {
+ this.matchCount += matches.length;
+ this.updateUIResultsCount();
+ }
},
extractText: function PDFFindController_extractText() {
@@ -230,6 +238,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.hadMatch = false;
this.resumePageIdx = null;
this.pageMatches = [];
+ this.matchCount = 0;
var self = this;
for (var i = 0; i < numPages; i++) {
@@ -386,6 +395,15 @@ var PDFFindController = (function PDFFindControllerClosure() {
}
},
+ updateUIResultsCount:
+ function PDFFindController_updateUIResultsCount() {
+ if (this.findBar === null) {
+ throw new Error('PDFFindController is not initialized with a ' +
+ 'PDFFindBar instance.');
+ }
+ this.findBar.updateResultsCount(this.matchCount);
+ },
+
updateUIState: function PDFFindController_updateUIState(state, previous) {
if (this.integratedFind) {
FirefoxCom.request('updateFindControlState',
@@ -396,7 +414,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
throw new Error('PDFFindController is not initialized with a ' +
'PDFFindBar instance.');
}
- this.findBar.updateUIState(state, previous);
+ this.findBar.updateUIState(state, previous, this.matchCount);
}
};
return PDFFindController;
diff --git a/web/viewer.css b/web/viewer.css
index a6e1dc328..426b292c6 100644
--- a/web/viewer.css
+++ b/web/viewer.css
@@ -477,6 +477,13 @@ html[dir='ltr'] .doorHangerRight:before {
margin-right: -9px;
}
+#findResultsCount {
+ background-color: hsl(0, 0%, 85%);
+ color: hsl(0, 0%, 32%);
+ text-align: center;
+ padding: 3px 4px;
+}
+
#findMsg {
font-style: italic;
color: #A6B7D0;
diff --git a/web/viewer.html b/web/viewer.html
index 50798ab5a..8a65736ee 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -149,6 +149,7 @@ See https://github.com/adobe-type-tools/cmap-resources
+
diff --git a/web/viewer.js b/web/viewer.js
index 947b42241..d14cc50b7 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -167,6 +167,7 @@ var PDFViewerApplication = {
highlightAllCheckbox: document.getElementById('findHighlightAll'),
caseSensitiveCheckbox: document.getElementById('findMatchCase'),
findMsg: document.getElementById('findMsg'),
+ findResultsCount: document.getElementById('findResultsCount'),
findStatusIcon: document.getElementById('findStatusIcon'),
findPreviousButton: document.getElementById('findPrevious'),
findNextButton: document.getElementById('findNext'),