Browse Source

Convert the hand tool to ES6 syntax

Tim van der Meij 8 years ago
parent
commit
bc49524ac7
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
  1. 67
      web/hand_tool.js

67
web/hand_tool.js

@ -20,20 +20,17 @@ import { localized } from './ui_utils';
* @typedef {Object} HandToolOptions * @typedef {Object} HandToolOptions
* @property {HTMLDivElement} container - The document container. * @property {HTMLDivElement} container - The document container.
* @property {EventBus} eventBus - The application event bus. * @property {EventBus} eventBus - The application event bus.
* @property {BasePreferences} preferences - Object for reading/writing
* persistent settings.
*/ */
/** class HandTool {
* @class
*/
var HandTool = (function HandToolClosure() {
/** /**
* @constructs HandTool
* @param {HandToolOptions} options * @param {HandToolOptions} options
*/ */
function HandTool(options) { constructor({ container, eventBus, preferences, }) {
this.container = options.container; this.container = container;
this.eventBus = options.eventBus; this.eventBus = eventBus;
var preferences = options.preferences;
this.wasActive = false; this.wasActive = false;
@ -46,12 +43,12 @@ var HandTool = (function HandToolClosure() {
this.eventBus.on('togglehandtool', this.toggle.bind(this)); this.eventBus.on('togglehandtool', this.toggle.bind(this));
Promise.all([localized, let enableOnLoad = preferences.get('enableHandToolOnLoad');
preferences.get('enableHandToolOnLoad')]).then((values) => { Promise.all([localized, enableOnLoad]).then((values) => {
if (values[1] === true) { if (values[1] === true) {
this.handTool.activate(); this.handTool.activate();
} }
}).catch(function rejected(reason) { }); }).catch(function(reason) {});
this.eventBus.on('presentationmodechanged', (evt) => { this.eventBus.on('presentationmodechanged', (evt) => {
if (evt.switchInProgress) { if (evt.switchInProgress) {
@ -65,35 +62,31 @@ var HandTool = (function HandToolClosure() {
}); });
} }
HandTool.prototype = { /**
/** * @return {boolean}
* @return {boolean} */
*/ get isActive() {
get isActive() { return !!this.handTool.active;
return !!this.handTool.active; }
},
toggle: function HandTool_toggle() {
this.handTool.toggle();
},
enterPresentationMode: function HandTool_enterPresentationMode() { toggle() {
if (this.isActive) { this.handTool.toggle();
this.wasActive = true; }
this.handTool.deactivate();
}
},
exitPresentationMode: function HandTool_exitPresentationMode() { enterPresentationMode() {
if (this.wasActive) { if (this.isActive) {
this.wasActive = false; this.wasActive = true;
this.handTool.activate(); this.handTool.deactivate();
}
} }
}; }
return HandTool; exitPresentationMode() {
})(); if (this.wasActive) {
this.wasActive = false;
this.handTool.activate();
}
}
}
export { export {
HandTool, HandTool,

Loading…
Cancel
Save