mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 18:25:37 +02:00
Added find match counter
This commit is contained in:
parent
c27d3125bf
commit
17fe0b1470
5 changed files with 45 additions and 1 deletions
|
@ -32,6 +32,7 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
||||||
this.highlightAll = options.highlightAllCheckbox || null;
|
this.highlightAll = options.highlightAllCheckbox || null;
|
||||||
this.caseSensitive = options.caseSensitiveCheckbox || null;
|
this.caseSensitive = options.caseSensitiveCheckbox || null;
|
||||||
this.findMsg = options.findMsg || null;
|
this.findMsg = options.findMsg || null;
|
||||||
|
this.findResultsCount = options.findResultsCount || null;
|
||||||
this.findStatusIcon = options.findStatusIcon || null;
|
this.findStatusIcon = options.findStatusIcon || null;
|
||||||
this.findPreviousButton = options.findPreviousButton || null;
|
this.findPreviousButton = options.findPreviousButton || null;
|
||||||
this.findNextButton = options.findNextButton || null;
|
this.findNextButton = options.findNextButton || null;
|
||||||
|
@ -133,6 +134,34 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
||||||
this.findMsg.textContent = findMsg;
|
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() {
|
open: function PDFFindBar_open() {
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
this.opened = true;
|
this.opened = true;
|
||||||
|
|
|
@ -116,7 +116,10 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||||
var queryLen = query.length;
|
var queryLen = query.length;
|
||||||
|
|
||||||
if (queryLen === 0) {
|
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) {
|
if (!caseSensitive) {
|
||||||
|
@ -139,6 +142,9 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||||
this.resumePageIdx = null;
|
this.resumePageIdx = null;
|
||||||
this.nextPageMatch();
|
this.nextPageMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the matches count
|
||||||
|
this.findBar.updateResultsCount(this.pageMatches);
|
||||||
},
|
},
|
||||||
|
|
||||||
extractText: function PDFFindController_extractText() {
|
extractText: function PDFFindController_extractText() {
|
||||||
|
|
|
@ -477,6 +477,13 @@ html[dir='ltr'] .doorHangerRight:before {
|
||||||
margin-right: -9px;
|
margin-right: -9px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#findResultsCount {
|
||||||
|
background-color: hsl(0, 0%, 85%);
|
||||||
|
color: hsl(0, 0%, 32%);
|
||||||
|
text-align: center;
|
||||||
|
padding: 3px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
#findMsg {
|
#findMsg {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
color: #A6B7D0;
|
color: #A6B7D0;
|
||||||
|
|
|
@ -149,6 +149,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||||
|
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||||
<span id="findMsg" class="toolbarLabel"></span>
|
<span id="findMsg" class="toolbarLabel"></span>
|
||||||
</div> <!-- findbar -->
|
</div> <!-- findbar -->
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,7 @@ var PDFViewerApplication = {
|
||||||
highlightAllCheckbox: document.getElementById('findHighlightAll'),
|
highlightAllCheckbox: document.getElementById('findHighlightAll'),
|
||||||
caseSensitiveCheckbox: document.getElementById('findMatchCase'),
|
caseSensitiveCheckbox: document.getElementById('findMatchCase'),
|
||||||
findMsg: document.getElementById('findMsg'),
|
findMsg: document.getElementById('findMsg'),
|
||||||
|
findResultsCount: document.getElementById('findResultsCount'),
|
||||||
findStatusIcon: document.getElementById('findStatusIcon'),
|
findStatusIcon: document.getElementById('findStatusIcon'),
|
||||||
findPreviousButton: document.getElementById('findPrevious'),
|
findPreviousButton: document.getElementById('findPrevious'),
|
||||||
findNextButton: document.getElementById('findNext'),
|
findNextButton: document.getElementById('findNext'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue