[Pkg-javascript-commits] [pdf.js] 387/414: Convert the hand tool to a class

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:43 UTC 2016


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

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

commit b0aca31de8e34badca5b70272857bc658b61b5e1
Author: Tim van der Meij <timvandermeij at gmail.com>
Date:   Sat Apr 16 16:47:48 2016 +0200

    Convert the hand tool to a class
---
 web/app.js       |  5 ++--
 web/hand_tool.js | 88 +++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 61 insertions(+), 32 deletions(-)

diff --git a/web/app.js b/web/app.js
index 0bcd5a2..87982cf 100644
--- a/web/app.js
+++ b/web/app.js
@@ -225,11 +225,10 @@ var PDFViewerApplication = {
 
     this.overlayManager = OverlayManager;
 
-    HandTool.initialize({
+    this.handTool = new HandTool({
       container: container,
       toggleHandTool: document.getElementById('toggleHandTool')
     });
-    this.handTool = HandTool;
 
     this.pdfDocumentProperties = new PDFDocumentProperties({
       overlayName: 'documentPropertiesOverlay',
@@ -2148,7 +2147,7 @@ window.addEventListener('keydown', function keydown(evt) {
 
       case 72: // 'h'
         if (!isViewerInPresentationMode) {
-          HandTool.toggle();
+          PDFViewerApplication.handTool.toggle();
         }
         break;
       case 82: // 'r'
diff --git a/web/hand_tool.js b/web/hand_tool.js
index 85addc5..8d5f184 100644
--- a/web/hand_tool.js
+++ b/web/hand_tool.js
@@ -35,30 +35,49 @@ var GrabToPan = grabToPan.GrabToPan;
 var Preferences = preferences.Preferences;
 var SecondaryToolbar = secondaryToolbar.SecondaryToolbar;
 
-var HandTool = {
-  initialize: function handToolInitialize(options) {
-    var toggleHandTool = options.toggleHandTool;
+/**
+ * @typedef {Object} HandToolOptions
+ * @property {HTMLDivElement} container - The document container.
+ * @property {HTMLButtonElement} toggleHandTool - The button element for
+ *                                                toggling the hand tool.
+ */
+
+/**
+ * @class
+ */
+var HandTool = (function HandToolClosure() {
+  /**
+   * @constructs HandTool
+   * @param {HandToolOptions} options
+   */
+  function HandTool(options) {
+    this.container = options.container;
+    this.toggleHandTool = options.toggleHandTool;
+
+    this.wasActive = false;
+
     this.handTool = new GrabToPan({
-      element: options.container,
+      element: this.container,
       onActiveChanged: function(isActive) {
-        if (!toggleHandTool) {
+        if (!this.toggleHandTool) {
           return;
         }
         if (isActive) {
-          toggleHandTool.title =
+          this.toggleHandTool.title =
             mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
-          toggleHandTool.firstElementChild.textContent =
+          this.toggleHandTool.firstElementChild.textContent =
             mozL10n.get('hand_tool_disable_label', null, 'Disable hand tool');
         } else {
-          toggleHandTool.title =
+          this.toggleHandTool.title =
             mozL10n.get('hand_tool_enable.title', null, 'Enable hand tool');
-          toggleHandTool.firstElementChild.textContent =
+          this.toggleHandTool.firstElementChild.textContent =
             mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
         }
-      }
+      }.bind(this)
     });
-    if (toggleHandTool) {
-      toggleHandTool.addEventListener('click', this.toggle.bind(this), false);
+
+    if (this.toggleHandTool) {
+      this.toggleHandTool.addEventListener('click', this.toggle.bind(this));
 
       window.addEventListener('localized', function (evt) {
         Preferences.get('enableHandToolOnLoad').then(function resolved(value) {
@@ -79,27 +98,38 @@ var HandTool = {
         }
       }.bind(this));
     }
-  },
+  }
 
-  toggle: function handToolToggle() {
-    this.handTool.toggle();
-    SecondaryToolbar.close();
-  },
+  HandTool.prototype = {
+    /**
+     * @return {boolean}
+     */
+    get isActive() {
+      return !!this.handTool.active;
+    },
 
-  enterPresentationMode: function handToolEnterPresentationMode() {
-    if (this.handTool.active) {
-      this.wasActive = true;
-      this.handTool.deactivate();
-    }
-  },
+    toggle: function HandTool_toggle() {
+      this.handTool.toggle();
+      SecondaryToolbar.close();
+    },
+
+    enterPresentationMode: function HandTool_enterPresentationMode() {
+      if (this.isActive) {
+        this.wasActive = true;
+        this.handTool.deactivate();
+      }
+    },
 
-  exitPresentationMode: function handToolExitPresentationMode() {
-    if (this.wasActive) {
-      this.wasActive = null;
-      this.handTool.activate();
+    exitPresentationMode: function HandTool_exitPresentationMode() {
+      if (this.wasActive) {
+        this.wasActive = false;
+        this.handTool.activate();
+      }
     }
-  }
-};
+  };
+
+  return HandTool;
+})();
 
 exports.HandTool = HandTool;
 }));

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