Skip to content

Commit

Permalink
Convert the hand tool to a class
Browse files Browse the repository at this point in the history
  • Loading branch information
timvandermeij committed Apr 16, 2016
1 parent 7f90f5b commit 4cbb872
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
3 changes: 1 addition & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
79 changes: 50 additions & 29 deletions web/hand_tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,47 @@ 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.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) {
Expand All @@ -79,27 +96,31 @@ var HandTool = {
}
}.bind(this));
}
},
}

toggle: function handToolToggle() {
this.handTool.toggle();
SecondaryToolbar.close();
},
HandTool.prototype = {
toggle: function HandTool_toggle() {
this.handTool.toggle();
SecondaryToolbar.close();
},

enterPresentationMode: function handToolEnterPresentationMode() {
if (this.handTool.active) {
this.wasActive = true;
this.handTool.deactivate();
}
},
enterPresentationMode: function HandTool_enterPresentationMode() {
if (this.handTool.active) {
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 = null;
this.handTool.activate();
}
}
}
};
};

return HandTool;
})();

exports.HandTool = HandTool;
}));

0 comments on commit 4cbb872

Please sign in to comment.