[Pkg-javascript-commits] [pdf.js] 65/157: Refactor the 'resize' event handler in viewer.js (issue 6158)

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 06:46:36 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 35ee1e1b0abf8d9e636beb1d2022256d12e4198a
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Mon Jul 6 16:13:41 2015 +0200

    Refactor the 'resize' event handler in viewer.js (issue 6158)
    
    *This is the next step towards fixing 6158.*
    
    This patch removes the dependency on the state of the scale `<select>` dropdown from the `resize` event handler, and instead uses the (in `PDFViewer`) stored `currentScaleValue`.
    I believe that the way this code is currently written is purely for historical reasons, since originally *only* the numerical scale was stored internally (hence there was no other way to access the scale value).
    However, since we now store the scale value, we should use it instead of quering the DOM. This helps ensure that the internally stored scale value is always accurately displayed in the UI (which should be good since, after the creation of `PDFViewer`, the `<select>` DOM element is now updated by an event handler).
---
 web/viewer.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/web/viewer.js b/web/viewer.js
index 878379e..77bbccf 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1643,13 +1643,16 @@ window.addEventListener('updateviewarea', function (evt) {
 }, true);
 
 window.addEventListener('resize', function webViewerResize(evt) {
-  if (PDFViewerApplication.initialized &&
-      (document.getElementById('pageAutoOption').selected ||
-       /* Note: the scale is constant for |pageActualOption|. */
-       document.getElementById('pageFitOption').selected ||
-       document.getElementById('pageWidthOption').selected)) {
-    var selectedScale = document.getElementById('scaleSelect').value;
-    PDFViewerApplication.setScale(selectedScale, false);
+  if (PDFViewerApplication.initialized) {
+    var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
+    switch (currentScaleValue) {
+      case 'auto':
+      case 'page-fit':
+      case 'page-width':
+        // Note: the scale is constant for 'page-actual'.
+        PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
+        break;
+    }
   }
   updateViewarea();
 
@@ -1707,7 +1710,7 @@ window.addEventListener('change', function webViewerChange(evt) {
 function selectScaleOption(value) {
   var options = document.getElementById('scaleSelect').options;
   var predefinedValueFound = false;
-  for (var i = 0; i < options.length; i++) {
+  for (var i = 0, ii = options.length; i < ii; i++) {
     var option = options[i];
     if (option.value !== value) {
       option.selected = false;

-- 
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