Removes circular dependency of secondary toolbar on app.js.
This commit is contained in:
parent
61a4c740d2
commit
eb3d1ca003
92
web/app.js
92
web/app.js
@ -262,32 +262,21 @@ var PDFViewerApplication = {
|
||||
this.handTool = new HandTool({
|
||||
container: container,
|
||||
eventBus: this.eventBus,
|
||||
toggleHandTool: appConfig.secondaryToolbar.toggleHandTool
|
||||
});
|
||||
|
||||
this.pdfDocumentProperties =
|
||||
new PDFDocumentProperties(appConfig.documentProperties);
|
||||
|
||||
SecondaryToolbar.initialize(appConfig.secondaryToolbar);
|
||||
SecondaryToolbar.initialize(appConfig.secondaryToolbar, eventBus);
|
||||
this.secondaryToolbar = SecondaryToolbar;
|
||||
|
||||
if (this.supportsFullscreen) {
|
||||
var toolbar = SecondaryToolbar;
|
||||
this.pdfPresentationMode = new PDFPresentationMode({
|
||||
container: container,
|
||||
viewer: viewer,
|
||||
pdfViewer: this.pdfViewer,
|
||||
eventBus: this.eventBus,
|
||||
contextMenuItems: [
|
||||
{ element: appConfig.fullscreen.contextFirstPage,
|
||||
handler: toolbar.firstPageClick.bind(toolbar) },
|
||||
{ element: appConfig.fullscreen.contextLastPage,
|
||||
handler: toolbar.lastPageClick.bind(toolbar) },
|
||||
{ element: appConfig.fullscreen.contextPageRotateCw,
|
||||
handler: toolbar.pageRotateCwClick.bind(toolbar) },
|
||||
{ element: appConfig.fullscreen.contextPageRotateCcw,
|
||||
handler: toolbar.pageRotateCcwClick.bind(toolbar) }
|
||||
]
|
||||
contextMenuItems: appConfig.fullscreen
|
||||
});
|
||||
}
|
||||
|
||||
@ -1248,6 +1237,15 @@ var PDFViewerApplication = {
|
||||
eventBus.on('pagemode', webViewerPageMode);
|
||||
eventBus.on('namedaction', webViewerNamedAction);
|
||||
eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
|
||||
eventBus.on('presentationmode', webViewerPresentationMode);
|
||||
eventBus.on('openfile', webViewerOpenFile);
|
||||
eventBus.on('print', webViewerPrint);
|
||||
eventBus.on('download', webViewerDownload);
|
||||
eventBus.on('firstpage', webViewerFirstPage);
|
||||
eventBus.on('lastpage', webViewerLastPage);
|
||||
eventBus.on('rotatecw', webViewerRotateCw);
|
||||
eventBus.on('rotateccw', webViewerRotateCcw);
|
||||
eventBus.on('documentproperties', webViewerDocumentProperties);
|
||||
eventBus.on('find', webViewerFind);
|
||||
//#if GENERIC
|
||||
eventBus.on('fileinputchange', webViewerFileInputChange);
|
||||
@ -1477,16 +1475,22 @@ function webViewerInitialized() {
|
||||
});
|
||||
|
||||
appConfig.toolbar.presentationModeButton.addEventListener('click',
|
||||
SecondaryToolbar.presentationModeClick.bind(SecondaryToolbar));
|
||||
function (e) {
|
||||
PDFViewerApplication.eventBus.dispatch('presentationmode');
|
||||
|
||||
appConfig.toolbar.openFile.addEventListener('click',
|
||||
SecondaryToolbar.openFileClick.bind(SecondaryToolbar));
|
||||
});
|
||||
|
||||
appConfig.toolbar.print.addEventListener('click',
|
||||
SecondaryToolbar.printClick.bind(SecondaryToolbar));
|
||||
appConfig.toolbar.openFile.addEventListener('click', function (e) {
|
||||
PDFViewerApplication.eventBus.dispatch('openfile');
|
||||
});
|
||||
|
||||
appConfig.toolbar.download.addEventListener('click',
|
||||
SecondaryToolbar.downloadClick.bind(SecondaryToolbar));
|
||||
appConfig.toolbar.print.addEventListener('click', function (e) {
|
||||
PDFViewerApplication.eventBus.dispatch('print');
|
||||
});
|
||||
|
||||
appConfig.toolbar.download.addEventListener('click', function (e) {
|
||||
PDFViewerApplication.eventBus.dispatch('download');
|
||||
});
|
||||
|
||||
//#if (FIREFOX || MOZCENTRAL || CHROME)
|
||||
//PDFViewerApplication.setTitleUsingUrl(file);
|
||||
@ -1827,6 +1831,39 @@ function webViewerLocalized() {
|
||||
});
|
||||
}
|
||||
|
||||
function webViewerPresentationMode() {
|
||||
PDFViewerApplication.requestPresentationMode();
|
||||
}
|
||||
function webViewerOpenFile() {
|
||||
var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
||||
document.getElementById(openFileInputName).click();
|
||||
}
|
||||
function webViewerPrint() {
|
||||
window.print();
|
||||
}
|
||||
function webViewerDownload() {
|
||||
PDFViewerApplication.download();
|
||||
}
|
||||
function webViewerFirstPage() {
|
||||
if (PDFViewerApplication.pdfDocument) {
|
||||
PDFViewerApplication.page = 1;
|
||||
}
|
||||
}
|
||||
function webViewerLastPage() {
|
||||
if (PDFViewerApplication.pdfDocument) {
|
||||
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
||||
}
|
||||
}
|
||||
function webViewerRotateCw() {
|
||||
PDFViewerApplication.rotatePages(90);
|
||||
}
|
||||
function webViewerRotateCcw() {
|
||||
PDFViewerApplication.rotatePages(-90);
|
||||
}
|
||||
function webViewerDocumentProperties() {
|
||||
PDFViewerApplication.pdfDocumentProperties.open();
|
||||
}
|
||||
|
||||
function webViewerFind(e) {
|
||||
PDFViewerApplication.findController.executeCommand('find' + e.type, {
|
||||
query: e.query,
|
||||
@ -1937,11 +1974,16 @@ window.addEventListener('DOMMouseScroll', handleMouseWheel);
|
||||
window.addEventListener('mousewheel', handleMouseWheel);
|
||||
|
||||
window.addEventListener('click', function click(evt) {
|
||||
if (SecondaryToolbar.opened &&
|
||||
PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
|
||||
if (!SecondaryToolbar.opened) {
|
||||
return;
|
||||
}
|
||||
var appConfig = PDFViewerApplication.appConfig;
|
||||
if (PDFViewerApplication.pdfViewer.containsElement(evt.target) ||
|
||||
(appConfig.toolbar.container.contains(evt.target) &&
|
||||
evt.target !== appConfig.secondaryToolbar.toggleButton)) {
|
||||
SecondaryToolbar.close();
|
||||
}
|
||||
}, false);
|
||||
}, true);
|
||||
|
||||
window.addEventListener('keydown', function keydown(evt) {
|
||||
if (OverlayManager.active) {
|
||||
@ -2214,8 +2256,4 @@ window.addEventListener('afterprint', function afterPrint(evt) {
|
||||
|
||||
exports.PDFViewerApplication = PDFViewerApplication;
|
||||
exports.DefaultExernalServices = DefaultExernalServices;
|
||||
|
||||
//// TODO remove circular reference of pdfjs-web/secondary_toolbar on app.
|
||||
secondaryToolbarLib._setApp(exports);
|
||||
|
||||
}));
|
||||
|
@ -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,32 +47,17 @@ 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) {
|
||||
@ -100,7 +78,6 @@ var HandTool = (function HandToolClosure() {
|
||||
}
|
||||
}.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() {
|
||||
|
@ -62,13 +62,26 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
||||
this.mouseScrollDelta = 0;
|
||||
|
||||
if (contextMenuItems) {
|
||||
for (var i = 0, ii = contextMenuItems.length; i < ii; i++) {
|
||||
var item = contextMenuItems[i];
|
||||
item.element.addEventListener('click', function (handler) {
|
||||
contextMenuItems.contextFirstPage.addEventListener('click',
|
||||
function PDFPresentationMode_contextFirstPageClick(e) {
|
||||
this.contextMenuOpen = false;
|
||||
handler();
|
||||
}.bind(this, item.handler));
|
||||
}
|
||||
this.eventBus.dispatch('firstpage');
|
||||
}.bind(this));
|
||||
contextMenuItems.contextLastPage.addEventListener('click',
|
||||
function PDFPresentationMode_contextLastPageClick(e) {
|
||||
this.contextMenuOpen = false;
|
||||
this.eventBus.dispatch('lastpage');
|
||||
}.bind(this));
|
||||
contextMenuItems.contextPageRotateCw.addEventListener('click',
|
||||
function PDFPresentationMode_contextPageRotateCwClick(e) {
|
||||
this.contextMenuOpen = false;
|
||||
this.eventBus.dispatch('rotatecw');
|
||||
}.bind(this));
|
||||
contextMenuItems.contextPageRotateCcw.addEventListener('click',
|
||||
function PDFPresentationMode_contextPageRotateCcwClick(e) {
|
||||
this.contextMenuOpen = false;
|
||||
this.eventBus.dispatch('rotateccw');
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,16 +27,15 @@
|
||||
}(this, function (exports, uiUtils) {
|
||||
|
||||
var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
|
||||
|
||||
var app; // Avoiding circular reference, see _setApp function below.
|
||||
var PDFViewerApplication = null; // = app.PDFViewerApplication;
|
||||
var mozL10n = uiUtils.mozL10n;
|
||||
|
||||
var SecondaryToolbar = {
|
||||
opened: false,
|
||||
previousContainerHeight: null,
|
||||
newContainerHeight: null,
|
||||
|
||||
initialize: function secondaryToolbarInitialize(options) {
|
||||
initialize: function secondaryToolbarInitialize(options, eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
this.toolbar = options.toolbar;
|
||||
this.buttonContainer = this.toolbar.firstElementChild;
|
||||
|
||||
@ -51,6 +50,7 @@ var SecondaryToolbar = {
|
||||
this.lastPage = options.lastPage;
|
||||
this.pageRotateCw = options.pageRotateCw;
|
||||
this.pageRotateCcw = options.pageRotateCcw;
|
||||
this.toggleHandTool = options.toggleHandTool;
|
||||
this.documentPropertiesButton = options.documentPropertiesButton;
|
||||
|
||||
// Attach the event listeners.
|
||||
@ -58,7 +58,6 @@ var SecondaryToolbar = {
|
||||
// Button to toggle the visibility of the secondary toolbar:
|
||||
{ element: this.toggleButton, handler: this.toggle },
|
||||
// All items within the secondary toolbar
|
||||
// (except for toggleHandTool, hand_tool.js is responsible for it):
|
||||
{ element: this.presentationModeButton,
|
||||
handler: this.presentationModeClick },
|
||||
{ element: this.openFile, handler: this.openFileClick },
|
||||
@ -69,6 +68,7 @@ var SecondaryToolbar = {
|
||||
{ element: this.lastPage, handler: this.lastPageClick },
|
||||
{ element: this.pageRotateCw, handler: this.pageRotateCwClick },
|
||||
{ element: this.pageRotateCcw, handler: this.pageRotateCcwClick },
|
||||
{ element: this.toggleHandTool, handler: this.toggleHandToolClick },
|
||||
{ element: this.documentPropertiesButton,
|
||||
handler: this.documentPropertiesClick }
|
||||
];
|
||||
@ -79,27 +79,46 @@ var SecondaryToolbar = {
|
||||
element.addEventListener('click', elements[item].handler.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
// Tracking hand tool menu item changes.
|
||||
var isHandToolActive = false;
|
||||
this.eventBus.on('handtoolchanged', function (e) {
|
||||
if (isHandToolActive === e.isActive) {
|
||||
return;
|
||||
}
|
||||
isHandToolActive = e.isActive;
|
||||
if (isHandToolActive) {
|
||||
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');
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
// Event handling functions.
|
||||
presentationModeClick: function secondaryToolbarPresentationModeClick(evt) {
|
||||
PDFViewerApplication.requestPresentationMode();
|
||||
this.eventBus.dispatch('presentationmode');
|
||||
this.close();
|
||||
},
|
||||
|
||||
openFileClick: function secondaryToolbarOpenFileClick(evt) {
|
||||
var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
||||
document.getElementById(openFileInputName).click();
|
||||
this.eventBus.dispatch('openfile');
|
||||
this.close();
|
||||
},
|
||||
|
||||
printClick: function secondaryToolbarPrintClick(evt) {
|
||||
window.print();
|
||||
this.eventBus.dispatch('print');
|
||||
this.close();
|
||||
},
|
||||
|
||||
downloadClick: function secondaryToolbarDownloadClick(evt) {
|
||||
PDFViewerApplication.download();
|
||||
this.eventBus.dispatch('download');
|
||||
this.close();
|
||||
},
|
||||
|
||||
@ -108,27 +127,30 @@ var SecondaryToolbar = {
|
||||
},
|
||||
|
||||
firstPageClick: function secondaryToolbarFirstPageClick(evt) {
|
||||
PDFViewerApplication.page = 1;
|
||||
this.eventBus.dispatch('firstpage');
|
||||
this.close();
|
||||
},
|
||||
|
||||
lastPageClick: function secondaryToolbarLastPageClick(evt) {
|
||||
if (PDFViewerApplication.pdfDocument) {
|
||||
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
||||
}
|
||||
this.eventBus.dispatch('lastpage');
|
||||
this.close();
|
||||
},
|
||||
|
||||
pageRotateCwClick: function secondaryToolbarPageRotateCwClick(evt) {
|
||||
PDFViewerApplication.rotatePages(90);
|
||||
this.eventBus.dispatch('rotatecw');
|
||||
},
|
||||
|
||||
pageRotateCcwClick: function secondaryToolbarPageRotateCcwClick(evt) {
|
||||
PDFViewerApplication.rotatePages(-90);
|
||||
this.eventBus.dispatch('rotateccw');
|
||||
},
|
||||
|
||||
toggleHandToolClick: function secondaryToolbarToggleHandToolClick(evt) {
|
||||
this.eventBus.dispatch('togglehandtool');
|
||||
this.close();
|
||||
},
|
||||
|
||||
documentPropertiesClick: function secondaryToolbarDocumentPropsClick(evt) {
|
||||
PDFViewerApplication.pdfDocumentProperties.open();
|
||||
this.eventBus.dispatch('documentproperties');
|
||||
this.close();
|
||||
},
|
||||
|
||||
@ -175,11 +197,5 @@ var SecondaryToolbar = {
|
||||
}
|
||||
};
|
||||
|
||||
function _setApp(app_) {
|
||||
app = app_;
|
||||
PDFViewerApplication = app.PDFViewerApplication;
|
||||
}
|
||||
|
||||
exports.SecondaryToolbar = SecondaryToolbar;
|
||||
exports._setApp = _setApp;
|
||||
}));
|
||||
|
@ -57,6 +57,7 @@ function getViewerConfiguration() {
|
||||
viewerContainer: document.getElementById('viewer'),
|
||||
eventBus: null, // using global event bus with DOM events
|
||||
toolbar: {
|
||||
container: document.getElementById('toolbarViewer'),
|
||||
numPages: document.getElementById('numPages'),
|
||||
pageNumber: document.getElementById('pageNumber'),
|
||||
scaleSelectContainer: document.getElementById('scaleSelectContainer'),
|
||||
|
Loading…
Reference in New Issue
Block a user