Moves match counter from find UI to the controller.
This commit is contained in:
parent
17fe0b1470
commit
b8b922196c
@ -95,7 +95,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|||||||
return window.dispatchEvent(event);
|
return window.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUIState: function PDFFindBar_updateUIState(state, previous) {
|
updateUIState:
|
||||||
|
function PDFFindBar_updateUIState(state, previous, matchCount) {
|
||||||
var notFound = false;
|
var notFound = false;
|
||||||
var findMsg = '';
|
var findMsg = '';
|
||||||
var status = '';
|
var status = '';
|
||||||
@ -132,36 +133,28 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|||||||
|
|
||||||
this.findField.setAttribute('data-status', status);
|
this.findField.setAttribute('data-status', status);
|
||||||
this.findMsg.textContent = findMsg;
|
this.findMsg.textContent = findMsg;
|
||||||
|
|
||||||
|
this.updateResultsCount(matchCount);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateResultsCount: function(matches) {
|
updateResultsCount: function(matchCount) {
|
||||||
if (!matches) {
|
if (!this.findResultsCount) {
|
||||||
return this.hideResultsCount();
|
return; // no UI control is provided
|
||||||
}
|
|
||||||
|
|
||||||
// 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 there are no matches, hide the counter
|
||||||
if (!matchCounter) {
|
if (!matchCount) {
|
||||||
return this.hideResultsCount();
|
this.findResultsCount.classList.add('hidden');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the match counter
|
// Create the match counter
|
||||||
this.findResultsCount.textContent = matchCounter;
|
this.findResultsCount.textContent = matchCount.toLocaleString();
|
||||||
|
|
||||||
// Show the counter
|
// Show the counter
|
||||||
this.findResultsCount.classList.remove('hidden');
|
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;
|
||||||
|
@ -39,6 +39,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
this.active = false; // If active, find results will be highlighted.
|
this.active = false; // If active, find results will be highlighted.
|
||||||
this.pageContents = []; // Stores the text for each page.
|
this.pageContents = []; // Stores the text for each page.
|
||||||
this.pageMatches = [];
|
this.pageMatches = [];
|
||||||
|
this.matchCount = 0;
|
||||||
this.selected = { // Currently selected match.
|
this.selected = { // Currently selected match.
|
||||||
pageIdx: -1,
|
pageIdx: -1,
|
||||||
matchIdx: -1
|
matchIdx: -1
|
||||||
@ -117,8 +118,6 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
|
|
||||||
if (queryLen === 0) {
|
if (queryLen === 0) {
|
||||||
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +143,10 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the matches count
|
// Update the matches count
|
||||||
this.findBar.updateResultsCount(this.pageMatches);
|
if (matches.length > 0) {
|
||||||
|
this.matchCount += matches.length;
|
||||||
|
this.updateUIResultsCount();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
extractText: function PDFFindController_extractText() {
|
extractText: function PDFFindController_extractText() {
|
||||||
@ -236,6 +238,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
this.hadMatch = false;
|
this.hadMatch = false;
|
||||||
this.resumePageIdx = null;
|
this.resumePageIdx = null;
|
||||||
this.pageMatches = [];
|
this.pageMatches = [];
|
||||||
|
this.matchCount = 0;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
for (var i = 0; i < numPages; i++) {
|
for (var i = 0; i < numPages; i++) {
|
||||||
@ -392,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) {
|
updateUIState: function PDFFindController_updateUIState(state, previous) {
|
||||||
if (this.integratedFind) {
|
if (this.integratedFind) {
|
||||||
FirefoxCom.request('updateFindControlState',
|
FirefoxCom.request('updateFindControlState',
|
||||||
@ -402,7 +414,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
throw new Error('PDFFindController is not initialized with a ' +
|
throw new Error('PDFFindController is not initialized with a ' +
|
||||||
'PDFFindBar instance.');
|
'PDFFindBar instance.');
|
||||||
}
|
}
|
||||||
this.findBar.updateUIState(state, previous);
|
this.findBar.updateUIState(state, previous, this.matchCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return PDFFindController;
|
return PDFFindController;
|
||||||
|
Loading…
Reference in New Issue
Block a user