Removes circular dependency of secondary toolbar on app.js.
This commit is contained in:
parent
61a4c740d2
commit
eb3d1ca003
5 changed files with 150 additions and 106 deletions
|
@ -17,29 +17,22 @@
|
|||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('pdfjs-web/hand_tool', ['exports', 'pdfjs-web/ui_utils',
|
||||
'pdfjs-web/grab_to_pan', 'pdfjs-web/preferences',
|
||||
'pdfjs-web/secondary_toolbar'], factory);
|
||||
define('pdfjs-web/hand_tool', ['exports', 'pdfjs-web/grab_to_pan',
|
||||
'pdfjs-web/preferences'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports, require('./ui_utils.js'), require('./grab_to_pan.js'),
|
||||
require('./preferences.js'), require('./secondary_toolbar.js'));
|
||||
factory(exports, require('./grab_to_pan.js'), require('./preferences.js'));
|
||||
} else {
|
||||
factory((root.pdfjsWebHandTool = {}), root.pdfjsWebUIUtils,
|
||||
root.pdfjsWebGrabToPan, root.pdfjsWebPreferences,
|
||||
root.pdfjsWebSecondaryToolbar);
|
||||
factory((root.pdfjsWebHandTool = {}), root.pdfjsWebGrabToPan,
|
||||
root.pdfjsWebPreferences);
|
||||
}
|
||||
}(this, function (exports, uiUtils, grabToPan, preferences, secondaryToolbar) {
|
||||
}(this, function (exports, grabToPan, preferences) {
|
||||
|
||||
var mozL10n = uiUtils.mozL10n;
|
||||
var GrabToPan = grabToPan.GrabToPan;
|
||||
var Preferences = preferences.Preferences;
|
||||
var SecondaryToolbar = secondaryToolbar.SecondaryToolbar;
|
||||
|
||||
/**
|
||||
* @typedef {Object} HandToolOptions
|
||||
* @property {HTMLDivElement} container - The document container.
|
||||
* @property {HTMLButtonElement} toggleHandTool - The button element for
|
||||
* toggling the hand tool.
|
||||
* @property {EventBus} eventBus - The application event bus.
|
||||
*/
|
||||
|
||||
|
@ -54,52 +47,36 @@ var HandTool = (function HandToolClosure() {
|
|||
function HandTool(options) {
|
||||
this.container = options.container;
|
||||
this.eventBus = options.eventBus;
|
||||
this.toggleHandTool = options.toggleHandTool;
|
||||
|
||||
this.wasActive = false;
|
||||
|
||||
this.handTool = new GrabToPan({
|
||||
element: this.container,
|
||||
onActiveChanged: function(isActive) {
|
||||
if (!this.toggleHandTool) {
|
||||
return;
|
||||
}
|
||||
if (isActive) {
|
||||
this.toggleHandTool.title =
|
||||
mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
|
||||
this.toggleHandTool.firstElementChild.textContent =
|
||||
mozL10n.get('hand_tool_disable_label', null, 'Disable hand tool');
|
||||
} else {
|
||||
this.toggleHandTool.title =
|
||||
mozL10n.get('hand_tool_enable.title', null, 'Enable hand tool');
|
||||
this.toggleHandTool.firstElementChild.textContent =
|
||||
mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
|
||||
}
|
||||
this.eventBus.dispatch('handtoolchanged', {isActive: isActive});
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
if (this.toggleHandTool) {
|
||||
this.toggleHandTool.addEventListener('click', this.toggle.bind(this));
|
||||
this.eventBus.on('togglehandtool', this.toggle.bind(this));
|
||||
|
||||
this.eventBus.on('localized', function (e) {
|
||||
Preferences.get('enableHandToolOnLoad').then(function resolved(value) {
|
||||
if (value) {
|
||||
this.handTool.activate();
|
||||
}
|
||||
}.bind(this), function rejected(reason) {});
|
||||
}.bind(this));
|
||||
this.eventBus.on('localized', function (e) {
|
||||
Preferences.get('enableHandToolOnLoad').then(function resolved(value) {
|
||||
if (value) {
|
||||
this.handTool.activate();
|
||||
}
|
||||
}.bind(this), function rejected(reason) {});
|
||||
}.bind(this));
|
||||
|
||||
this.eventBus.on('presentationmodechanged', function (e) {
|
||||
if (e.switchInProgress) {
|
||||
return;
|
||||
}
|
||||
if (e.active) {
|
||||
this.enterPresentationMode();
|
||||
} else {
|
||||
this.exitPresentationMode();
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
this.eventBus.on('presentationmodechanged', function (e) {
|
||||
if (e.switchInProgress) {
|
||||
return;
|
||||
}
|
||||
if (e.active) {
|
||||
this.enterPresentationMode();
|
||||
} else {
|
||||
this.exitPresentationMode();
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
HandTool.prototype = {
|
||||
|
@ -112,7 +89,6 @@ var HandTool = (function HandToolClosure() {
|
|||
|
||||
toggle: function HandTool_toggle() {
|
||||
this.handTool.toggle();
|
||||
SecondaryToolbar.close();
|
||||
},
|
||||
|
||||
enterPresentationMode: function HandTool_enterPresentationMode() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue