Added find match counter
This commit is contained in:
		
							parent
							
								
									c27d3125bf
								
							
						
					
					
						commit
						17fe0b1470
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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>
 | 
			
		||||
          <input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
 | 
			
		||||
          <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>
 | 
			
		||||
        </div>  <!-- findbar -->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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'),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user