diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index 4484afc03..0ab0382ea 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; @@ -133,6 +134,34 @@ var PDFFindBar = (function PDFFindBarClosure() { this.findMsg.textContent = findMsg; }, + updateResultsCount: function(matches) { + if (!matches) { + return this.hideResultsCount(); + } + + // Loop through and add up all the matches between pages + var matchCounter = 0; + + for (var i = 0, len = matches.length; i < len; i++) { + matchCounter += matches[i].length; + } + + // If there are no matches, hide the counter + if (!matchCounter) { + return this.hideResultsCount(); + } + + // Create the match counter + this.findResultsCount.textContent = matchCounter; + + // Show the counter + this.findResultsCount.classList.remove('hidden'); + }, + + hideResultsCount: function() { + this.findResultsCount.classList.add('hidden'); + }, + open: function PDFFindBar_open() { if (!this.opened) { this.opened = true; diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index afb563c7d..afac06bd4 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -116,7 +116,10 @@ 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. + // Also, reset the result counter back to zero + this.findBar.updateResultsCount(); + return; } if (!caseSensitive) { @@ -139,6 +142,9 @@ var PDFFindController = (function PDFFindControllerClosure() { this.resumePageIdx = null; this.nextPageMatch(); } + + // Update the matches count + this.findBar.updateResultsCount(this.pageMatches); }, extractText: function PDFFindController_extractText() { 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'),