Merge pull request #8391 from timvandermeij/es6-web
Convert the hand tool, interfaces and secondary toolbar to ES6 syntax
This commit is contained in:
commit
595ee1232d
@ -20,20 +20,17 @@ import { localized } from './ui_utils';
|
|||||||
* @typedef {Object} HandToolOptions
|
* @typedef {Object} HandToolOptions
|
||||||
* @property {HTMLDivElement} container - The document container.
|
* @property {HTMLDivElement} container - The document container.
|
||||||
* @property {EventBus} eventBus - The application event bus.
|
* @property {EventBus} eventBus - The application event bus.
|
||||||
|
* @property {BasePreferences} preferences - Object for reading/writing
|
||||||
|
* persistent settings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class HandTool {
|
||||||
/**
|
/**
|
||||||
* @class
|
|
||||||
*/
|
|
||||||
var HandTool = (function HandToolClosure() {
|
|
||||||
/**
|
|
||||||
* @constructs HandTool
|
|
||||||
* @param {HandToolOptions} options
|
* @param {HandToolOptions} options
|
||||||
*/
|
*/
|
||||||
function HandTool(options) {
|
constructor({ container, eventBus, preferences, }) {
|
||||||
this.container = options.container;
|
this.container = container;
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = eventBus;
|
||||||
var preferences = options.preferences;
|
|
||||||
|
|
||||||
this.wasActive = false;
|
this.wasActive = false;
|
||||||
|
|
||||||
@ -46,12 +43,12 @@ var HandTool = (function HandToolClosure() {
|
|||||||
|
|
||||||
this.eventBus.on('togglehandtool', this.toggle.bind(this));
|
this.eventBus.on('togglehandtool', this.toggle.bind(this));
|
||||||
|
|
||||||
Promise.all([localized,
|
let enableOnLoad = preferences.get('enableHandToolOnLoad');
|
||||||
preferences.get('enableHandToolOnLoad')]).then((values) => {
|
Promise.all([localized, enableOnLoad]).then((values) => {
|
||||||
if (values[1] === true) {
|
if (values[1] === true) {
|
||||||
this.handTool.activate();
|
this.handTool.activate();
|
||||||
}
|
}
|
||||||
}).catch(function rejected(reason) { });
|
}).catch(function(reason) {});
|
||||||
|
|
||||||
this.eventBus.on('presentationmodechanged', (evt) => {
|
this.eventBus.on('presentationmodechanged', (evt) => {
|
||||||
if (evt.switchInProgress) {
|
if (evt.switchInProgress) {
|
||||||
@ -65,35 +62,31 @@ var HandTool = (function HandToolClosure() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
HandTool.prototype = {
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
get isActive() {
|
get isActive() {
|
||||||
return !!this.handTool.active;
|
return !!this.handTool.active;
|
||||||
},
|
}
|
||||||
|
|
||||||
toggle: function HandTool_toggle() {
|
toggle() {
|
||||||
this.handTool.toggle();
|
this.handTool.toggle();
|
||||||
},
|
}
|
||||||
|
|
||||||
enterPresentationMode: function HandTool_enterPresentationMode() {
|
enterPresentationMode() {
|
||||||
if (this.isActive) {
|
if (this.isActive) {
|
||||||
this.wasActive = true;
|
this.wasActive = true;
|
||||||
this.handTool.deactivate();
|
this.handTool.deactivate();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
exitPresentationMode: function HandTool_exitPresentationMode() {
|
exitPresentationMode() {
|
||||||
if (this.wasActive) {
|
if (this.wasActive) {
|
||||||
this.wasActive = false;
|
this.wasActive = false;
|
||||||
this.handTool.activate();
|
this.handTool.activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return HandTool;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
HandTool,
|
HandTool,
|
||||||
|
@ -19,82 +19,87 @@
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*/
|
*/
|
||||||
function IPDFLinkService() {}
|
class IPDFLinkService {
|
||||||
IPDFLinkService.prototype = {
|
|
||||||
/**
|
/**
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get page() {},
|
get page() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} value
|
* @param {number} value
|
||||||
*/
|
*/
|
||||||
set page(value) {},
|
set page(value) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dest - The PDF destination object.
|
* @param dest - The PDF destination object.
|
||||||
*/
|
*/
|
||||||
navigateTo(dest) {},
|
navigateTo(dest) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dest - The PDF destination object.
|
* @param dest - The PDF destination object.
|
||||||
* @returns {string} The hyperlink to the PDF object.
|
* @returns {string} The hyperlink to the PDF object.
|
||||||
*/
|
*/
|
||||||
getDestinationHash(dest) {},
|
getDestinationHash(dest) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param hash - The PDF parameters/hash.
|
* @param hash - The PDF parameters/hash.
|
||||||
* @returns {string} The hyperlink to the PDF object.
|
* @returns {string} The hyperlink to the PDF object.
|
||||||
*/
|
*/
|
||||||
getAnchorUrl(hash) {},
|
getAnchorUrl(hash) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} hash
|
* @param {string} hash
|
||||||
*/
|
*/
|
||||||
setHash(hash) {},
|
setHash(hash) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} action
|
* @param {string} action
|
||||||
*/
|
*/
|
||||||
executeNamedAction(action) {},
|
executeNamedAction(action) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} pageNum - page number.
|
* @param {number} pageNum - page number.
|
||||||
* @param {Object} pageRef - reference to the page.
|
* @param {Object} pageRef - reference to the page.
|
||||||
*/
|
*/
|
||||||
cachePageRef(pageNum, pageRef) {},
|
cachePageRef(pageNum, pageRef) {}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*/
|
*/
|
||||||
function IPDFHistory() {}
|
class IPDFHistory {
|
||||||
IPDFHistory.prototype = {
|
forward() {}
|
||||||
forward() {},
|
back() {}
|
||||||
back() {},
|
push(params) {}
|
||||||
push(params) {},
|
updateNextHashParam(hash) {}
|
||||||
updateNextHashParam(hash) {},
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*/
|
*/
|
||||||
function IRenderableView() {}
|
class IRenderableView {
|
||||||
IRenderableView.prototype = {
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} - Unique ID for rendering queue.
|
* @returns {string} - Unique ID for rendering queue.
|
||||||
*/
|
*/
|
||||||
get renderingId() {},
|
get renderingId() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {RenderingStates}
|
* @returns {RenderingStates}
|
||||||
*/
|
*/
|
||||||
get renderingState() {},
|
get renderingState() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise} Resolved on draw completion.
|
* @returns {Promise} Resolved on draw completion.
|
||||||
*/
|
*/
|
||||||
draw() {},
|
draw() {}
|
||||||
resume() {},
|
|
||||||
};
|
resume() {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*/
|
*/
|
||||||
function IPDFTextLayerFactory() {}
|
class IPDFTextLayerFactory {
|
||||||
IPDFTextLayerFactory.prototype = {
|
|
||||||
/**
|
/**
|
||||||
* @param {HTMLDivElement} textLayerDiv
|
* @param {HTMLDivElement} textLayerDiv
|
||||||
* @param {number} pageIndex
|
* @param {number} pageIndex
|
||||||
@ -104,7 +109,7 @@ IPDFTextLayerFactory.prototype = {
|
|||||||
*/
|
*/
|
||||||
createTextLayerBuilder(textLayerDiv, pageIndex, viewport,
|
createTextLayerBuilder(textLayerDiv, pageIndex, viewport,
|
||||||
enhanceTextSelection = false) {}
|
enhanceTextSelection = false) {}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
|
@ -45,17 +45,13 @@ import { mozL10n, SCROLLBAR_PADDING } from './ui_utils';
|
|||||||
* the document properties dialog.
|
* the document properties dialog.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class SecondaryToolbar {
|
||||||
/**
|
/**
|
||||||
* @class
|
|
||||||
*/
|
|
||||||
var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|
||||||
/**
|
|
||||||
* @constructs SecondaryToolbar
|
|
||||||
* @param {SecondaryToolbarOptions} options
|
* @param {SecondaryToolbarOptions} options
|
||||||
* @param {HTMLDivElement} mainContainer
|
* @param {HTMLDivElement} mainContainer
|
||||||
* @param {EventBus} eventBus
|
* @param {EventBus} eventBus
|
||||||
*/
|
*/
|
||||||
function SecondaryToolbar(options, mainContainer, eventBus) {
|
constructor(options, mainContainer, eventBus) {
|
||||||
this.toolbar = options.toolbar;
|
this.toolbar = options.toolbar;
|
||||||
this.toggleButton = options.toggleButton;
|
this.toggleButton = options.toggleButton;
|
||||||
this.toolbarButtonContainer = options.toolbarButtonContainer;
|
this.toolbarButtonContainer = options.toolbarButtonContainer;
|
||||||
@ -101,40 +97,37 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
this.eventBus.on('resize', this._setMaxHeight.bind(this));
|
this.eventBus.on('resize', this._setMaxHeight.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
SecondaryToolbar.prototype = {
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
get isOpen() {
|
get isOpen() {
|
||||||
return this.opened;
|
return this.opened;
|
||||||
},
|
}
|
||||||
|
|
||||||
setPageNumber: function SecondaryToolbar_setPageNumber(pageNumber) {
|
setPageNumber(pageNumber) {
|
||||||
this.pageNumber = pageNumber;
|
this.pageNumber = pageNumber;
|
||||||
this._updateUIState();
|
this._updateUIState();
|
||||||
},
|
}
|
||||||
|
|
||||||
setPagesCount: function SecondaryToolbar_setPagesCount(pagesCount) {
|
setPagesCount(pagesCount) {
|
||||||
this.pagesCount = pagesCount;
|
this.pagesCount = pagesCount;
|
||||||
this._updateUIState();
|
this._updateUIState();
|
||||||
},
|
}
|
||||||
|
|
||||||
reset: function SecondaryToolbar_reset() {
|
reset() {
|
||||||
this.pageNumber = 0;
|
this.pageNumber = 0;
|
||||||
this.pagesCount = 0;
|
this.pagesCount = 0;
|
||||||
this._updateUIState();
|
this._updateUIState();
|
||||||
},
|
}
|
||||||
|
|
||||||
_updateUIState: function SecondaryToolbar_updateUIState() {
|
_updateUIState() {
|
||||||
var items = this.items;
|
this.items.firstPage.disabled = (this.pageNumber <= 1);
|
||||||
|
this.items.lastPage.disabled = (this.pageNumber >= this.pagesCount);
|
||||||
|
this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
||||||
|
this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
||||||
|
}
|
||||||
|
|
||||||
items.firstPage.disabled = (this.pageNumber <= 1);
|
_bindClickListeners() {
|
||||||
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.
|
// Button to toggle the visibility of the secondary toolbar.
|
||||||
this.toggleButton.addEventListener('click', this.toggle.bind(this));
|
this.toggleButton.addEventListener('click', this.toggle.bind(this));
|
||||||
|
|
||||||
@ -151,16 +144,17 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_bindHandToolListener:
|
_bindHandToolListener(toggleHandToolButton) {
|
||||||
function SecondaryToolbar_bindHandToolListener(toggleHandToolButton) {
|
let isHandToolActive = false;
|
||||||
var isHandToolActive = false;
|
|
||||||
this.eventBus.on('handtoolchanged', function (e) {
|
this.eventBus.on('handtoolchanged', function(evt) {
|
||||||
if (isHandToolActive === e.isActive) {
|
if (isHandToolActive === evt.isActive) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isHandToolActive = e.isActive;
|
isHandToolActive = evt.isActive;
|
||||||
|
|
||||||
if (isHandToolActive) {
|
if (isHandToolActive) {
|
||||||
toggleHandToolButton.title =
|
toggleHandToolButton.title =
|
||||||
mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
|
mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
|
||||||
@ -173,9 +167,9 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
|
mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
open: function SecondaryToolbar_open() {
|
open() {
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -184,29 +178,29 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
|
|
||||||
this.toggleButton.classList.add('toggled');
|
this.toggleButton.classList.add('toggled');
|
||||||
this.toolbar.classList.remove('hidden');
|
this.toolbar.classList.remove('hidden');
|
||||||
},
|
}
|
||||||
|
|
||||||
close: function SecondaryToolbar_close() {
|
close() {
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.opened = false;
|
this.opened = false;
|
||||||
this.toolbar.classList.add('hidden');
|
this.toolbar.classList.add('hidden');
|
||||||
this.toggleButton.classList.remove('toggled');
|
this.toggleButton.classList.remove('toggled');
|
||||||
},
|
}
|
||||||
|
|
||||||
toggle: function SecondaryToolbar_toggle() {
|
toggle() {
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
this.close();
|
this.close();
|
||||||
} else {
|
} else {
|
||||||
this.open();
|
this.open();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_setMaxHeight: function SecondaryToolbar_setMaxHeight() {
|
_setMaxHeight() {
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
return; // Only adjust the 'max-height' if the toolbar is visible.
|
return; // Only adjust the 'max-height' if the toolbar is visible.
|
||||||
}
|
}
|
||||||
@ -220,10 +214,7 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
|
|
||||||
this.previousContainerHeight = this.containerHeight;
|
this.previousContainerHeight = this.containerHeight;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return SecondaryToolbar;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
SecondaryToolbar,
|
SecondaryToolbar,
|
||||||
|
Loading…
Reference in New Issue
Block a user