2013-09-05 06:48:31 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 02:34:27 +09:00
|
|
|
(function (root, factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define('pdfjs-web/secondary_toolbar', ['exports', 'pdfjs-web/ui_utils'],
|
|
|
|
factory);
|
|
|
|
} else if (typeof exports !== 'undefined') {
|
|
|
|
factory(exports, require('./ui_utils.js'));
|
|
|
|
} else {
|
|
|
|
factory((root.pdfjsWebSecondaryToolbar = {}), root.pdfjsWebUIUtils);
|
|
|
|
}
|
|
|
|
}(this, function (exports, uiUtils) {
|
|
|
|
|
|
|
|
var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
|
2016-04-29 05:04:09 +09:00
|
|
|
var mozL10n = uiUtils.mozL10n;
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2013-09-05 06:48:31 +09:00
|
|
|
var SecondaryToolbar = {
|
|
|
|
opened: false,
|
|
|
|
previousContainerHeight: null,
|
|
|
|
newContainerHeight: null,
|
|
|
|
|
2016-04-29 05:04:09 +09:00
|
|
|
initialize: function secondaryToolbarInitialize(options, eventBus) {
|
|
|
|
this.eventBus = eventBus;
|
2013-09-05 06:48:31 +09:00
|
|
|
this.toolbar = options.toolbar;
|
|
|
|
this.buttonContainer = this.toolbar.firstElementChild;
|
|
|
|
|
|
|
|
// Define the toolbar buttons.
|
2013-10-18 06:49:30 +09:00
|
|
|
this.toggleButton = options.toggleButton;
|
2013-10-19 06:03:28 +09:00
|
|
|
this.presentationModeButton = options.presentationModeButton;
|
2013-09-05 06:48:31 +09:00
|
|
|
this.openFile = options.openFile;
|
|
|
|
this.print = options.print;
|
|
|
|
this.download = options.download;
|
2014-01-17 20:16:43 +09:00
|
|
|
this.viewBookmark = options.viewBookmark;
|
2013-09-05 06:48:31 +09:00
|
|
|
this.firstPage = options.firstPage;
|
|
|
|
this.lastPage = options.lastPage;
|
|
|
|
this.pageRotateCw = options.pageRotateCw;
|
|
|
|
this.pageRotateCcw = options.pageRotateCcw;
|
2016-04-29 05:04:09 +09:00
|
|
|
this.toggleHandTool = options.toggleHandTool;
|
2014-01-22 08:07:07 +09:00
|
|
|
this.documentPropertiesButton = options.documentPropertiesButton;
|
2013-09-05 06:48:31 +09:00
|
|
|
|
|
|
|
// Attach the event listeners.
|
2013-10-18 06:49:30 +09:00
|
|
|
var elements = [
|
2014-01-08 19:59:30 +09:00
|
|
|
// Button to toggle the visibility of the secondary toolbar:
|
2013-10-18 06:49:30 +09:00
|
|
|
{ element: this.toggleButton, handler: this.toggle },
|
2014-01-08 19:59:30 +09:00
|
|
|
// All items within the secondary toolbar
|
2013-10-19 06:03:28 +09:00
|
|
|
{ element: this.presentationModeButton,
|
|
|
|
handler: this.presentationModeClick },
|
2013-10-18 06:49:30 +09:00
|
|
|
{ element: this.openFile, handler: this.openFileClick },
|
|
|
|
{ element: this.print, handler: this.printClick },
|
|
|
|
{ element: this.download, handler: this.downloadClick },
|
2014-01-17 20:16:43 +09:00
|
|
|
{ element: this.viewBookmark, handler: this.viewBookmarkClick },
|
2013-10-18 06:49:30 +09:00
|
|
|
{ element: this.firstPage, handler: this.firstPageClick },
|
|
|
|
{ element: this.lastPage, handler: this.lastPageClick },
|
|
|
|
{ element: this.pageRotateCw, handler: this.pageRotateCwClick },
|
2014-01-22 08:07:07 +09:00
|
|
|
{ element: this.pageRotateCcw, handler: this.pageRotateCcwClick },
|
2016-04-29 05:04:09 +09:00
|
|
|
{ element: this.toggleHandTool, handler: this.toggleHandToolClick },
|
2014-01-22 08:07:07 +09:00
|
|
|
{ element: this.documentPropertiesButton,
|
|
|
|
handler: this.documentPropertiesClick }
|
2013-10-18 06:49:30 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var item in elements) {
|
|
|
|
var element = elements[item].element;
|
|
|
|
if (element) {
|
|
|
|
element.addEventListener('click', elements[item].handler.bind(this));
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 05:04:09 +09:00
|
|
|
|
|
|
|
// 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));
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
// Event handling functions.
|
|
|
|
presentationModeClick: function secondaryToolbarPresentationModeClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('presentationmode');
|
2013-09-05 06:48:31 +09:00
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
openFileClick: function secondaryToolbarOpenFileClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('openfile');
|
2014-01-22 08:07:07 +09:00
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
printClick: function secondaryToolbarPrintClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('print');
|
2014-01-22 08:07:07 +09:00
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
downloadClick: function secondaryToolbarDownloadClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('download');
|
2014-01-22 08:07:07 +09:00
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
2014-01-17 20:16:43 +09:00
|
|
|
viewBookmarkClick: function secondaryToolbarViewBookmarkClick(evt) {
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
2013-09-05 06:48:31 +09:00
|
|
|
firstPageClick: function secondaryToolbarFirstPageClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('firstpage');
|
2014-01-17 20:16:43 +09:00
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
lastPageClick: function secondaryToolbarLastPageClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('lastpage');
|
2014-01-17 20:16:43 +09:00
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
pageRotateCwClick: function secondaryToolbarPageRotateCwClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('rotatecw');
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
pageRotateCcwClick: function secondaryToolbarPageRotateCcwClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('rotateccw');
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleHandToolClick: function secondaryToolbarToggleHandToolClick(evt) {
|
|
|
|
this.eventBus.dispatch('togglehandtool');
|
|
|
|
this.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
},
|
|
|
|
|
2014-01-22 08:07:07 +09:00
|
|
|
documentPropertiesClick: function secondaryToolbarDocumentPropsClick(evt) {
|
2016-04-29 05:04:09 +09:00
|
|
|
this.eventBus.dispatch('documentproperties');
|
2014-01-22 08:07:07 +09:00
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
2013-09-05 06:48:31 +09:00
|
|
|
// Misc. functions for interacting with the toolbar.
|
|
|
|
setMaxHeight: function secondaryToolbarSetMaxHeight(container) {
|
2013-10-19 06:03:28 +09:00
|
|
|
if (!container || !this.buttonContainer) {
|
2013-09-15 00:56:18 +09:00
|
|
|
return;
|
|
|
|
}
|
2013-09-05 06:48:31 +09:00
|
|
|
this.newContainerHeight = container.clientHeight;
|
|
|
|
if (this.previousContainerHeight === this.newContainerHeight) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.buttonContainer.setAttribute('style',
|
|
|
|
'max-height: ' + (this.newContainerHeight - SCROLLBAR_PADDING) + 'px;');
|
|
|
|
this.previousContainerHeight = this.newContainerHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
open: function secondaryToolbarOpen() {
|
|
|
|
if (this.opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.opened = true;
|
|
|
|
this.toggleButton.classList.add('toggled');
|
|
|
|
this.toolbar.classList.remove('hidden');
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function secondaryToolbarClose(target) {
|
|
|
|
if (!this.opened) {
|
|
|
|
return;
|
|
|
|
} else if (target && !this.toolbar.contains(target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.opened = false;
|
|
|
|
this.toolbar.classList.add('hidden');
|
|
|
|
this.toggleButton.classList.remove('toggled');
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function secondaryToolbarToggle() {
|
|
|
|
if (this.opened) {
|
|
|
|
this.close();
|
|
|
|
} else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
|
|
exports.SecondaryToolbar = SecondaryToolbar;
|
|
|
|
}));
|