Refactor toolbar (and secondary toolbar).

This commit is contained in:
Yury Delendik 2016-11-18 12:50:29 -06:00
parent 043cea251d
commit a4402c84de
7 changed files with 457 additions and 231 deletions

View file

@ -91,6 +91,12 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
{ element: options.documentPropertiesButton,
eventName: 'documentproperties', close: true }
];
this.items = {
firstPage: options.firstPageButton,
lastPage: options.lastPageButton,
pageRotateCw: options.pageRotateCwButton,
pageRotateCcw: options.pageRotateCcwButton,
};
this.mainContainer = mainContainer;
this.eventBus = eventBus;
@ -99,6 +105,8 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
this.containerHeight = null;
this.previousContainerHeight = null;
this.reset();
// Bind the event listeners for click and hand tool actions.
this._bindClickListeners();
this._bindHandToolListener(options.toggleHandToolButton);
@ -115,6 +123,31 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
return this.opened;
},
setPageNumber: function SecondaryToolbar_setPageNumber(pageNumber) {
this.pageNumber = pageNumber;
this._updateUIState();
},
setPagesCount: function SecondaryToolbar_setPagesCount(pagesCount) {
this.pagesCount = pagesCount;
this._updateUIState();
},
reset: function SecondaryToolbar_reset() {
this.pageNumber = 0;
this.pagesCount = 0;
this._updateUIState();
},
_updateUIState: function SecondaryToolbar_updateUIState() {
var items = this.items;
items.firstPage.disabled = (this.pageNumber <= 1);
items.lastPage.disabled = (this.pageNumber >= this.pagesCount);
items.pageRotateCw.disabled = this.pagesCount === 0;
items.pageRotateCcw.disabled = this.pagesCount === 0;
},
_bindClickListeners: function SecondaryToolbar_bindClickListeners() {
// Button to toggle the visibility of the secondary toolbar.
this.toggleButton.addEventListener('click', this.toggle.bind(this));