[Pkg-javascript-commits] [pdf.js] 111/174: Added find match counter

David Prévot taffit at moszumanska.debian.org
Thu Nov 19 18:45:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 17fe0b147017109d5fcb07c17143e769870e39b8
Author: Andy Parisi <andrew at andrewparisi.com>
Date:   Wed Jul 16 10:39:34 2014 -0400

    Added find match counter
---
 web/pdf_find_bar.js        | 29 +++++++++++++++++++++++++++++
 web/pdf_find_controller.js |  8 +++++++-
 web/viewer.css             |  7 +++++++
 web/viewer.html            |  1 +
 web/viewer.js              |  1 +
 5 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js
index 4484afc..0ab0382 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 afb563c..afac06b 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 a6e1dc3..426b292 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 50798ab..8a65736 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -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 -->
 
diff --git a/web/viewer.js b/web/viewer.js
index 947b422..d14cc50 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'),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list