| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 | 
							- /* Copyright 2017 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';
 
- Object.defineProperty(exports, "__esModule", {
 
-   value: true
 
- });
 
- exports.PDFSidebar = exports.SidebarView = undefined;
 
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
- var _ui_utils = require('./ui_utils');
 
- var _pdf_rendering_queue = require('./pdf_rendering_queue');
 
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
- var UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
 
- var SidebarView = {
 
-   NONE: 0,
 
-   THUMBS: 1,
 
-   OUTLINE: 2,
 
-   ATTACHMENTS: 3
 
- };
 
- var PDFSidebar = function () {
 
-   function PDFSidebar(options) {
 
-     var l10n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ui_utils.NullL10n;
 
-     _classCallCheck(this, PDFSidebar);
 
-     this.isOpen = false;
 
-     this.active = SidebarView.THUMBS;
 
-     this.isInitialViewSet = false;
 
-     this.onToggled = null;
 
-     this.pdfViewer = options.pdfViewer;
 
-     this.pdfThumbnailViewer = options.pdfThumbnailViewer;
 
-     this.pdfOutlineViewer = options.pdfOutlineViewer;
 
-     this.outerContainer = options.outerContainer;
 
-     this.viewerContainer = options.viewerContainer;
 
-     this.eventBus = options.eventBus;
 
-     this.toggleButton = options.toggleButton;
 
-     this.thumbnailButton = options.thumbnailButton;
 
-     this.outlineButton = options.outlineButton;
 
-     this.attachmentsButton = options.attachmentsButton;
 
-     this.thumbnailView = options.thumbnailView;
 
-     this.outlineView = options.outlineView;
 
-     this.attachmentsView = options.attachmentsView;
 
-     this.disableNotification = options.disableNotification || false;
 
-     this.l10n = l10n;
 
-     this._addEventListeners();
 
-   }
 
-   _createClass(PDFSidebar, [{
 
-     key: 'reset',
 
-     value: function reset() {
 
-       this.isInitialViewSet = false;
 
-       this._hideUINotification(null);
 
-       this.switchView(SidebarView.THUMBS);
 
-       this.outlineButton.disabled = false;
 
-       this.attachmentsButton.disabled = false;
 
-     }
 
-   }, {
 
-     key: 'setInitialView',
 
-     value: function setInitialView() {
 
-       var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SidebarView.NONE;
 
-       if (this.isInitialViewSet) {
 
-         return;
 
-       }
 
-       this.isInitialViewSet = true;
 
-       if (this.isOpen && view === SidebarView.NONE) {
 
-         this._dispatchEvent();
 
-         return;
 
-       }
 
-       var isViewPreserved = view === this.visibleView;
 
-       this.switchView(view, true);
 
-       if (isViewPreserved) {
 
-         this._dispatchEvent();
 
-       }
 
-     }
 
-   }, {
 
-     key: 'switchView',
 
-     value: function switchView(view) {
 
-       var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
 
-       if (view === SidebarView.NONE) {
 
-         this.close();
 
-         return;
 
-       }
 
-       var isViewChanged = view !== this.active;
 
-       var shouldForceRendering = false;
 
-       switch (view) {
 
-         case SidebarView.THUMBS:
 
-           this.thumbnailButton.classList.add('toggled');
 
-           this.outlineButton.classList.remove('toggled');
 
-           this.attachmentsButton.classList.remove('toggled');
 
-           this.thumbnailView.classList.remove('hidden');
 
-           this.outlineView.classList.add('hidden');
 
-           this.attachmentsView.classList.add('hidden');
 
-           if (this.isOpen && isViewChanged) {
 
-             this._updateThumbnailViewer();
 
-             shouldForceRendering = true;
 
-           }
 
-           break;
 
-         case SidebarView.OUTLINE:
 
-           if (this.outlineButton.disabled) {
 
-             return;
 
-           }
 
-           this.thumbnailButton.classList.remove('toggled');
 
-           this.outlineButton.classList.add('toggled');
 
-           this.attachmentsButton.classList.remove('toggled');
 
-           this.thumbnailView.classList.add('hidden');
 
-           this.outlineView.classList.remove('hidden');
 
-           this.attachmentsView.classList.add('hidden');
 
-           break;
 
-         case SidebarView.ATTACHMENTS:
 
-           if (this.attachmentsButton.disabled) {
 
-             return;
 
-           }
 
-           this.thumbnailButton.classList.remove('toggled');
 
-           this.outlineButton.classList.remove('toggled');
 
-           this.attachmentsButton.classList.add('toggled');
 
-           this.thumbnailView.classList.add('hidden');
 
-           this.outlineView.classList.add('hidden');
 
-           this.attachmentsView.classList.remove('hidden');
 
-           break;
 
-         default:
 
-           console.error('PDFSidebar_switchView: "' + view + '" is an unsupported value.');
 
-           return;
 
-       }
 
-       this.active = view | 0;
 
-       if (forceOpen && !this.isOpen) {
 
-         this.open();
 
-         return;
 
-       }
 
-       if (shouldForceRendering) {
 
-         this._forceRendering();
 
-       }
 
-       if (isViewChanged) {
 
-         this._dispatchEvent();
 
-       }
 
-       this._hideUINotification(this.active);
 
-     }
 
-   }, {
 
-     key: 'open',
 
-     value: function open() {
 
-       if (this.isOpen) {
 
-         return;
 
-       }
 
-       this.isOpen = true;
 
-       this.toggleButton.classList.add('toggled');
 
-       this.outerContainer.classList.add('sidebarMoving');
 
-       this.outerContainer.classList.add('sidebarOpen');
 
-       if (this.active === SidebarView.THUMBS) {
 
-         this._updateThumbnailViewer();
 
-       }
 
-       this._forceRendering();
 
-       this._dispatchEvent();
 
-       this._hideUINotification(this.active);
 
-     }
 
-   }, {
 
-     key: 'close',
 
-     value: function close() {
 
-       if (!this.isOpen) {
 
-         return;
 
-       }
 
-       this.isOpen = false;
 
-       this.toggleButton.classList.remove('toggled');
 
-       this.outerContainer.classList.add('sidebarMoving');
 
-       this.outerContainer.classList.remove('sidebarOpen');
 
-       this._forceRendering();
 
-       this._dispatchEvent();
 
-     }
 
-   }, {
 
-     key: 'toggle',
 
-     value: function toggle() {
 
-       if (this.isOpen) {
 
-         this.close();
 
-       } else {
 
-         this.open();
 
-       }
 
-     }
 
-   }, {
 
-     key: '_dispatchEvent',
 
-     value: function _dispatchEvent() {
 
-       this.eventBus.dispatch('sidebarviewchanged', {
 
-         source: this,
 
-         view: this.visibleView
 
-       });
 
-     }
 
-   }, {
 
-     key: '_forceRendering',
 
-     value: function _forceRendering() {
 
-       if (this.onToggled) {
 
-         this.onToggled();
 
-       } else {
 
-         this.pdfViewer.forceRendering();
 
-         this.pdfThumbnailViewer.forceRendering();
 
-       }
 
-     }
 
-   }, {
 
-     key: '_updateThumbnailViewer',
 
-     value: function _updateThumbnailViewer() {
 
-       var pdfViewer = this.pdfViewer,
 
-           pdfThumbnailViewer = this.pdfThumbnailViewer;
 
-       var pagesCount = pdfViewer.pagesCount;
 
-       for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
 
-         var pageView = pdfViewer.getPageView(pageIndex);
 
-         if (pageView && pageView.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
 
-           var thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
 
-           thumbnailView.setImage(pageView);
 
-         }
 
-       }
 
-       pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
 
-     }
 
-   }, {
 
-     key: '_showUINotification',
 
-     value: function _showUINotification(view) {
 
-       var _this = this;
 
-       if (this.disableNotification) {
 
-         return;
 
-       }
 
-       this.l10n.get('toggle_sidebar_notification.title', null, 'Toggle Sidebar (document contains outline/attachments)').then(function (msg) {
 
-         _this.toggleButton.title = msg;
 
-       });
 
-       if (!this.isOpen) {
 
-         this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
 
-       } else if (view === this.active) {
 
-         return;
 
-       }
 
-       switch (view) {
 
-         case SidebarView.OUTLINE:
 
-           this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
 
-           break;
 
-         case SidebarView.ATTACHMENTS:
 
-           this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
 
-           break;
 
-       }
 
-     }
 
-   }, {
 
-     key: '_hideUINotification',
 
-     value: function _hideUINotification(view) {
 
-       var _this2 = this;
 
-       if (this.disableNotification) {
 
-         return;
 
-       }
 
-       var removeNotification = function removeNotification(view) {
 
-         switch (view) {
 
-           case SidebarView.OUTLINE:
 
-             _this2.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
 
-             break;
 
-           case SidebarView.ATTACHMENTS:
 
-             _this2.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
 
-             break;
 
-         }
 
-       };
 
-       if (!this.isOpen && view !== null) {
 
-         return;
 
-       }
 
-       this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
 
-       if (view !== null) {
 
-         removeNotification(view);
 
-         return;
 
-       }
 
-       for (view in SidebarView) {
 
-         removeNotification(SidebarView[view]);
 
-       }
 
-       this.l10n.get('toggle_sidebar.title', null, 'Toggle Sidebar').then(function (msg) {
 
-         _this2.toggleButton.title = msg;
 
-       });
 
-     }
 
-   }, {
 
-     key: '_addEventListeners',
 
-     value: function _addEventListeners() {
 
-       var _this3 = this;
 
-       this.viewerContainer.addEventListener('transitionend', function (evt) {
 
-         if (evt.target === _this3.viewerContainer) {
 
-           _this3.outerContainer.classList.remove('sidebarMoving');
 
-         }
 
-       });
 
-       this.thumbnailButton.addEventListener('click', function () {
 
-         _this3.switchView(SidebarView.THUMBS);
 
-       });
 
-       this.outlineButton.addEventListener('click', function () {
 
-         _this3.switchView(SidebarView.OUTLINE);
 
-       });
 
-       this.outlineButton.addEventListener('dblclick', function () {
 
-         _this3.pdfOutlineViewer.toggleOutlineTree();
 
-       });
 
-       this.attachmentsButton.addEventListener('click', function () {
 
-         _this3.switchView(SidebarView.ATTACHMENTS);
 
-       });
 
-       this.eventBus.on('outlineloaded', function (evt) {
 
-         var outlineCount = evt.outlineCount;
 
-         _this3.outlineButton.disabled = !outlineCount;
 
-         if (outlineCount) {
 
-           _this3._showUINotification(SidebarView.OUTLINE);
 
-         } else if (_this3.active === SidebarView.OUTLINE) {
 
-           _this3.switchView(SidebarView.THUMBS);
 
-         }
 
-       });
 
-       this.eventBus.on('attachmentsloaded', function (evt) {
 
-         if (evt.attachmentsCount) {
 
-           _this3.attachmentsButton.disabled = false;
 
-           _this3._showUINotification(SidebarView.ATTACHMENTS);
 
-           return;
 
-         }
 
-         Promise.resolve().then(function () {
 
-           if (_this3.attachmentsView.hasChildNodes()) {
 
-             return;
 
-           }
 
-           _this3.attachmentsButton.disabled = true;
 
-           if (_this3.active === SidebarView.ATTACHMENTS) {
 
-             _this3.switchView(SidebarView.THUMBS);
 
-           }
 
-         });
 
-       });
 
-       this.eventBus.on('presentationmodechanged', function (evt) {
 
-         if (!evt.active && !evt.switchInProgress && _this3.isThumbnailViewVisible) {
 
-           _this3._updateThumbnailViewer();
 
-         }
 
-       });
 
-     }
 
-   }, {
 
-     key: 'visibleView',
 
-     get: function get() {
 
-       return this.isOpen ? this.active : SidebarView.NONE;
 
-     }
 
-   }, {
 
-     key: 'isThumbnailViewVisible',
 
-     get: function get() {
 
-       return this.isOpen && this.active === SidebarView.THUMBS;
 
-     }
 
-   }, {
 
-     key: 'isOutlineViewVisible',
 
-     get: function get() {
 
-       return this.isOpen && this.active === SidebarView.OUTLINE;
 
-     }
 
-   }, {
 
-     key: 'isAttachmentsViewVisible',
 
-     get: function get() {
 
-       return this.isOpen && this.active === SidebarView.ATTACHMENTS;
 
-     }
 
-   }]);
 
-   return PDFSidebar;
 
- }();
 
- exports.SidebarView = SidebarView;
 
- exports.PDFSidebar = PDFSidebar;
 
 
  |