Merge pull request #8594 from Snuffleupagus/es6-web-let
Change `var` to `let`, and use object destructuring, in a couple of previously class converted `web/*.js` files
This commit is contained in:
commit
05b1ef2d23
@ -31,13 +31,14 @@ class AnnotationLayerBuilder {
|
|||||||
/**
|
/**
|
||||||
* @param {AnnotationLayerBuilderOptions} options
|
* @param {AnnotationLayerBuilderOptions} options
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor({ pageDiv, pdfPage, linkService, downloadManager,
|
||||||
this.pageDiv = options.pageDiv;
|
renderInteractiveForms = false, l10n = NullL10n, }) {
|
||||||
this.pdfPage = options.pdfPage;
|
this.pageDiv = pageDiv;
|
||||||
this.renderInteractiveForms = options.renderInteractiveForms;
|
this.pdfPage = pdfPage;
|
||||||
this.linkService = options.linkService;
|
this.linkService = linkService;
|
||||||
this.downloadManager = options.downloadManager;
|
this.downloadManager = downloadManager;
|
||||||
this.l10n = options.l10n || NullL10n;
|
this.renderInteractiveForms = renderInteractiveForms;
|
||||||
|
this.l10n = l10n;
|
||||||
|
|
||||||
this.div = null;
|
this.div = null;
|
||||||
}
|
}
|
||||||
@ -48,7 +49,7 @@ class AnnotationLayerBuilder {
|
|||||||
*/
|
*/
|
||||||
render(viewport, intent = 'display') {
|
render(viewport, intent = 'display') {
|
||||||
this.pdfPage.getAnnotations({ intent, }).then((annotations) => {
|
this.pdfPage.getAnnotations({ intent, }).then((annotations) => {
|
||||||
var parameters = {
|
let parameters = {
|
||||||
viewport: viewport.clone({ dontFlip: true, }),
|
viewport: viewport.clone({ dontFlip: true, }),
|
||||||
div: this.div,
|
div: this.div,
|
||||||
annotations,
|
annotations,
|
||||||
@ -68,7 +69,6 @@ class AnnotationLayerBuilder {
|
|||||||
if (annotations.length === 0) {
|
if (annotations.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.div = document.createElement('div');
|
this.div = document.createElement('div');
|
||||||
this.div.className = 'annotationLayer';
|
this.div.className = 'annotationLayer';
|
||||||
this.pageDiv.appendChild(this.div);
|
this.pageDiv.appendChild(this.div);
|
||||||
@ -99,8 +99,7 @@ class DefaultAnnotationLayerFactory {
|
|||||||
* @param {IL10n} l10n
|
* @param {IL10n} l10n
|
||||||
* @returns {AnnotationLayerBuilder}
|
* @returns {AnnotationLayerBuilder}
|
||||||
*/
|
*/
|
||||||
createAnnotationLayerBuilder(pageDiv, pdfPage,
|
createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false,
|
||||||
renderInteractiveForms = false,
|
|
||||||
l10n = NullL10n) {
|
l10n = NullL10n) {
|
||||||
return new AnnotationLayerBuilder({
|
return new AnnotationLayerBuilder({
|
||||||
pageDiv,
|
pageDiv,
|
||||||
|
@ -87,7 +87,7 @@ class PasswordPrompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verify() {
|
verify() {
|
||||||
var password = this.input.value;
|
let password = this.input.value;
|
||||||
if (password && password.length > 0) {
|
if (password && password.length > 0) {
|
||||||
this.close();
|
this.close();
|
||||||
return this.updateCallback(password);
|
return this.updateCallback(password);
|
||||||
|
@ -27,19 +27,19 @@ import {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFAttachmentViewerRenderParameters
|
* @typedef {Object} PDFAttachmentViewerRenderParameters
|
||||||
* @property {Array|null} attachments - An array of attachment objects.
|
* @property {Object|null} attachments - A lookup table of attachment objects.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PDFAttachmentViewer {
|
class PDFAttachmentViewer {
|
||||||
/**
|
/**
|
||||||
* @param {PDFAttachmentViewerOptions} options
|
* @param {PDFAttachmentViewerOptions} options
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor({ container, eventBus, downloadManager, }) {
|
||||||
this.attachments = null;
|
this.attachments = null;
|
||||||
|
|
||||||
this.container = options.container;
|
this.container = container;
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = eventBus;
|
||||||
this.downloadManager = options.downloadManager;
|
this.downloadManager = downloadManager;
|
||||||
|
|
||||||
this._renderedCapability = createPromiseCapability();
|
this._renderedCapability = createPromiseCapability();
|
||||||
this.eventBus.on('fileattachmentannotation',
|
this.eventBus.on('fileattachmentannotation',
|
||||||
@ -79,12 +79,12 @@ class PDFAttachmentViewer {
|
|||||||
throw new Error('bindPdfLink: ' +
|
throw new Error('bindPdfLink: ' +
|
||||||
'Unsupported "PDFJS.disableCreateObjectURL" value.');
|
'Unsupported "PDFJS.disableCreateObjectURL" value.');
|
||||||
}
|
}
|
||||||
var blobUrl;
|
let blobUrl;
|
||||||
button.onclick = function() {
|
button.onclick = function() {
|
||||||
if (!blobUrl) {
|
if (!blobUrl) {
|
||||||
blobUrl = createObjectURL(content, 'application/pdf');
|
blobUrl = createObjectURL(content, 'application/pdf');
|
||||||
}
|
}
|
||||||
var viewerUrl;
|
let viewerUrl;
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
// The current URL is the viewer, let's use it and append the file.
|
// The current URL is the viewer, let's use it and append the file.
|
||||||
viewerUrl = '?file=' + encodeURIComponent(blobUrl + '#' + filename);
|
viewerUrl = '?file=' + encodeURIComponent(blobUrl + '#' + filename);
|
||||||
@ -116,33 +116,31 @@ class PDFAttachmentViewer {
|
|||||||
/**
|
/**
|
||||||
* @param {PDFAttachmentViewerRenderParameters} params
|
* @param {PDFAttachmentViewerRenderParameters} params
|
||||||
*/
|
*/
|
||||||
render(params = {}) {
|
render({ attachments, keepRenderedCapability = false, }) {
|
||||||
var attachments = params.attachments || null;
|
let attachmentsCount = 0;
|
||||||
var attachmentsCount = 0;
|
|
||||||
|
|
||||||
if (this.attachments) {
|
if (this.attachments) {
|
||||||
var keepRenderedCapability = params.keepRenderedCapability === true;
|
this.reset(keepRenderedCapability === true);
|
||||||
this.reset(keepRenderedCapability);
|
|
||||||
}
|
}
|
||||||
this.attachments = attachments;
|
this.attachments = attachments || null;
|
||||||
|
|
||||||
if (!attachments) {
|
if (!attachments) {
|
||||||
this._dispatchEvent(attachmentsCount);
|
this._dispatchEvent(attachmentsCount);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var names = Object.keys(attachments).sort(function(a, b) {
|
let names = Object.keys(attachments).sort(function(a, b) {
|
||||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||||
});
|
});
|
||||||
attachmentsCount = names.length;
|
attachmentsCount = names.length;
|
||||||
|
|
||||||
for (var i = 0; i < attachmentsCount; i++) {
|
for (let i = 0; i < attachmentsCount; i++) {
|
||||||
var item = attachments[names[i]];
|
let item = attachments[names[i]];
|
||||||
var filename = removeNullCharacters(getFilenameFromUrl(item.filename));
|
let filename = removeNullCharacters(getFilenameFromUrl(item.filename));
|
||||||
|
|
||||||
var div = document.createElement('div');
|
let div = document.createElement('div');
|
||||||
div.className = 'attachmentsItem';
|
div.className = 'attachmentsItem';
|
||||||
var button = document.createElement('button');
|
let button = document.createElement('button');
|
||||||
button.textContent = filename;
|
button.textContent = filename;
|
||||||
if (/\.pdf$/i.test(filename) && !PDFJS.disableCreateObjectURL) {
|
if (/\.pdf$/i.test(filename) && !PDFJS.disableCreateObjectURL) {
|
||||||
this._bindPdfLink(button, item.content, filename);
|
this._bindPdfLink(button, item.content, filename);
|
||||||
@ -163,12 +161,12 @@ class PDFAttachmentViewer {
|
|||||||
*/
|
*/
|
||||||
_appendAttachment({ id, filename, content, }) {
|
_appendAttachment({ id, filename, content, }) {
|
||||||
this._renderedCapability.promise.then(() => {
|
this._renderedCapability.promise.then(() => {
|
||||||
var attachments = this.attachments;
|
let attachments = this.attachments;
|
||||||
|
|
||||||
if (!attachments) {
|
if (!attachments) {
|
||||||
attachments = Object.create(null);
|
attachments = Object.create(null);
|
||||||
} else {
|
} else {
|
||||||
for (var name in attachments) {
|
for (let name in attachments) {
|
||||||
if (id === name) {
|
if (id === name) {
|
||||||
return; // Ignore the new attachment if it already exists.
|
return; // Ignore the new attachment if it already exists.
|
||||||
}
|
}
|
||||||
|
@ -231,15 +231,15 @@ class PDFDocumentProperties {
|
|||||||
// Get all elements from the PDF date string.
|
// Get all elements from the PDF date string.
|
||||||
// JavaScript's `Date` object expects the month to be between
|
// JavaScript's `Date` object expects the month to be between
|
||||||
// 0 and 11 instead of 1 and 12, so we're correcting for this.
|
// 0 and 11 instead of 1 and 12, so we're correcting for this.
|
||||||
var year = parseInt(dateToParse.substring(0, 4), 10);
|
let year = parseInt(dateToParse.substring(0, 4), 10);
|
||||||
var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
|
let month = parseInt(dateToParse.substring(4, 6), 10) - 1;
|
||||||
var day = parseInt(dateToParse.substring(6, 8), 10);
|
let day = parseInt(dateToParse.substring(6, 8), 10);
|
||||||
var hours = parseInt(dateToParse.substring(8, 10), 10);
|
let hours = parseInt(dateToParse.substring(8, 10), 10);
|
||||||
var minutes = parseInt(dateToParse.substring(10, 12), 10);
|
let minutes = parseInt(dateToParse.substring(10, 12), 10);
|
||||||
var seconds = parseInt(dateToParse.substring(12, 14), 10);
|
let seconds = parseInt(dateToParse.substring(12, 14), 10);
|
||||||
var utRel = dateToParse.substring(14, 15);
|
let utRel = dateToParse.substring(14, 15);
|
||||||
var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
|
let offsetHours = parseInt(dateToParse.substring(15, 17), 10);
|
||||||
var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
|
let offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
|
||||||
|
|
||||||
// As per spec, utRel = 'Z' means equal to universal time.
|
// As per spec, utRel = 'Z' means equal to universal time.
|
||||||
// The other cases ('-' and '+') have to be handled here.
|
// The other cases ('-' and '+') have to be handled here.
|
||||||
@ -252,9 +252,9 @@ class PDFDocumentProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the new date format from the user's locale.
|
// Return the new date format from the user's locale.
|
||||||
var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
let date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
||||||
var dateString = date.toLocaleDateString();
|
let dateString = date.toLocaleDateString();
|
||||||
var timeString = date.toLocaleTimeString();
|
let timeString = date.toLocaleTimeString();
|
||||||
return this.l10n.get('document_properties_date_string',
|
return this.l10n.get('document_properties_date_string',
|
||||||
{ date: dateString, time: timeString, },
|
{ date: dateString, time: timeString, },
|
||||||
'{{date}}, {{time}}');
|
'{{date}}, {{time}}');
|
||||||
|
@ -103,9 +103,9 @@ class PDFFindBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateUIState(state, previous, matchCount) {
|
updateUIState(state, previous, matchCount) {
|
||||||
var notFound = false;
|
let notFound = false;
|
||||||
var findMsg = '';
|
let findMsg = '';
|
||||||
var status = '';
|
let status = '';
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case FindState.FOUND:
|
case FindState.FOUND:
|
||||||
@ -206,8 +206,8 @@ class PDFFindBar {
|
|||||||
// wrapped). Here we detect and fix that.
|
// wrapped). Here we detect and fix that.
|
||||||
this.bar.classList.remove('wrapContainers');
|
this.bar.classList.remove('wrapContainers');
|
||||||
|
|
||||||
var findbarHeight = this.bar.clientHeight;
|
let findbarHeight = this.bar.clientHeight;
|
||||||
var inputContainerHeight = this.bar.firstElementChild.clientHeight;
|
let inputContainerHeight = this.bar.firstElementChild.clientHeight;
|
||||||
|
|
||||||
if (findbarHeight > inputContainerHeight) {
|
if (findbarHeight > inputContainerHeight) {
|
||||||
// The findbar is taller than the input container, which means that
|
// The findbar is taller than the input container, which means that
|
||||||
|
@ -35,13 +35,13 @@ class PDFOutlineViewer {
|
|||||||
/**
|
/**
|
||||||
* @param {PDFOutlineViewerOptions} options
|
* @param {PDFOutlineViewerOptions} options
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor({ container, linkService, eventBus, }) {
|
||||||
this.outline = null;
|
this.outline = null;
|
||||||
this.lastToggleIsShow = true;
|
this.lastToggleIsShow = true;
|
||||||
|
|
||||||
this.container = options.container;
|
this.container = container;
|
||||||
this.linkService = options.linkService;
|
this.linkService = linkService;
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
@ -77,7 +77,7 @@ class PDFOutlineViewer {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var destination = item.dest;
|
let destination = item.dest;
|
||||||
|
|
||||||
element.href = this.linkService.getDestinationHash(destination);
|
element.href = this.linkService.getDestinationHash(destination);
|
||||||
element.onclick = () => {
|
element.onclick = () => {
|
||||||
@ -92,7 +92,7 @@ class PDFOutlineViewer {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_setStyles(element, item) {
|
_setStyles(element, item) {
|
||||||
var styleStr = '';
|
let styleStr = '';
|
||||||
if (item.bold) {
|
if (item.bold) {
|
||||||
styleStr += 'font-weight: bold;';
|
styleStr += 'font-weight: bold;';
|
||||||
}
|
}
|
||||||
@ -112,14 +112,14 @@ class PDFOutlineViewer {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_addToggleButton(div) {
|
_addToggleButton(div) {
|
||||||
var toggler = document.createElement('div');
|
let toggler = document.createElement('div');
|
||||||
toggler.className = 'outlineItemToggler';
|
toggler.className = 'outlineItemToggler';
|
||||||
toggler.onclick = (evt) => {
|
toggler.onclick = (evt) => {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
toggler.classList.toggle('outlineItemsHidden');
|
toggler.classList.toggle('outlineItemsHidden');
|
||||||
|
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
|
let shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
|
||||||
this._toggleOutlineItem(div, shouldShowAll);
|
this._toggleOutlineItem(div, shouldShowAll);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -137,8 +137,8 @@ class PDFOutlineViewer {
|
|||||||
*/
|
*/
|
||||||
_toggleOutlineItem(root, show) {
|
_toggleOutlineItem(root, show) {
|
||||||
this.lastToggleIsShow = show;
|
this.lastToggleIsShow = show;
|
||||||
var togglers = root.querySelectorAll('.outlineItemToggler');
|
let togglers = root.querySelectorAll('.outlineItemToggler');
|
||||||
for (var i = 0, ii = togglers.length; i < ii; ++i) {
|
for (let i = 0, ii = togglers.length; i < ii; ++i) {
|
||||||
togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
|
togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,32 +156,31 @@ class PDFOutlineViewer {
|
|||||||
/**
|
/**
|
||||||
* @param {PDFOutlineViewerRenderParameters} params
|
* @param {PDFOutlineViewerRenderParameters} params
|
||||||
*/
|
*/
|
||||||
render(params = {}) {
|
render({ outline, }) {
|
||||||
var outline = params.outline || null;
|
let outlineCount = 0;
|
||||||
var outlineCount = 0;
|
|
||||||
|
|
||||||
if (this.outline) {
|
if (this.outline) {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
this.outline = outline;
|
this.outline = outline || null;
|
||||||
|
|
||||||
if (!outline) {
|
if (!outline) {
|
||||||
this._dispatchEvent(outlineCount);
|
this._dispatchEvent(outlineCount);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fragment = document.createDocumentFragment();
|
let fragment = document.createDocumentFragment();
|
||||||
var queue = [{ parent: fragment, items: this.outline, }];
|
let queue = [{ parent: fragment, items: this.outline, }];
|
||||||
var hasAnyNesting = false;
|
let hasAnyNesting = false;
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
var levelData = queue.shift();
|
let levelData = queue.shift();
|
||||||
for (var i = 0, len = levelData.items.length; i < len; i++) {
|
for (let i = 0, len = levelData.items.length; i < len; i++) {
|
||||||
var item = levelData.items[i];
|
let item = levelData.items[i];
|
||||||
|
|
||||||
var div = document.createElement('div');
|
let div = document.createElement('div');
|
||||||
div.className = 'outlineItem';
|
div.className = 'outlineItem';
|
||||||
|
|
||||||
var element = document.createElement('a');
|
let element = document.createElement('a');
|
||||||
this._bindLink(element, item);
|
this._bindLink(element, item);
|
||||||
this._setStyles(element, item);
|
this._setStyles(element, item);
|
||||||
element.textContent =
|
element.textContent =
|
||||||
@ -193,7 +192,7 @@ class PDFOutlineViewer {
|
|||||||
hasAnyNesting = true;
|
hasAnyNesting = true;
|
||||||
this._addToggleButton(div);
|
this._addToggleButton(div);
|
||||||
|
|
||||||
var itemsDiv = document.createElement('div');
|
let itemsDiv = document.createElement('div');
|
||||||
itemsDiv.className = 'outlineItems';
|
itemsDiv.className = 'outlineItems';
|
||||||
div.appendChild(itemsDiv);
|
div.appendChild(itemsDiv);
|
||||||
queue.push({ parent: itemsDiv, items: item.items, });
|
queue.push({ parent: itemsDiv, items: item.items, });
|
||||||
|
@ -43,12 +43,12 @@ class PDFPresentationMode {
|
|||||||
/**
|
/**
|
||||||
* @param {PDFPresentationModeOptions} options
|
* @param {PDFPresentationModeOptions} options
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor({ container, viewer = null, pdfViewer, eventBus,
|
||||||
this.container = options.container;
|
contextMenuItems = null, }) {
|
||||||
this.viewer = options.viewer || options.container.firstElementChild;
|
this.container = container;
|
||||||
this.pdfViewer = options.pdfViewer;
|
this.viewer = viewer || container.firstElementChild;
|
||||||
this.eventBus = options.eventBus;
|
this.pdfViewer = pdfViewer;
|
||||||
var contextMenuItems = options.contextMenuItems || null;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.args = null;
|
this.args = null;
|
||||||
@ -119,9 +119,9 @@ class PDFPresentationMode {
|
|||||||
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
var delta = normalizeWheelEventDelta(evt);
|
let delta = normalizeWheelEventDelta(evt);
|
||||||
var currentTime = (new Date()).getTime();
|
let currentTime = (new Date()).getTime();
|
||||||
var storedTime = this.mouseScrollTimeStamp;
|
let storedTime = this.mouseScrollTimeStamp;
|
||||||
|
|
||||||
// If we've already switched page, avoid accidentally switching again.
|
// If we've already switched page, avoid accidentally switching again.
|
||||||
if (currentTime > storedTime &&
|
if (currentTime > storedTime &&
|
||||||
@ -136,9 +136,9 @@ class PDFPresentationMode {
|
|||||||
this.mouseScrollDelta += delta;
|
this.mouseScrollDelta += delta;
|
||||||
|
|
||||||
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
|
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
|
||||||
var totalDelta = this.mouseScrollDelta;
|
let totalDelta = this.mouseScrollDelta;
|
||||||
this._resetMouseScrollState();
|
this._resetMouseScrollState();
|
||||||
var success = totalDelta > 0 ? this._goToPreviousPage()
|
let success = totalDelta > 0 ? this._goToPreviousPage()
|
||||||
: this._goToNextPage();
|
: this._goToNextPage();
|
||||||
if (success) {
|
if (success) {
|
||||||
this.mouseScrollTimeStamp = currentTime;
|
this.mouseScrollTimeStamp = currentTime;
|
||||||
@ -155,7 +155,7 @@ class PDFPresentationMode {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_goToPreviousPage() {
|
_goToPreviousPage() {
|
||||||
var page = this.pdfViewer.currentPageNumber;
|
let page = this.pdfViewer.currentPageNumber;
|
||||||
// If we're at the first page, we don't need to do anything.
|
// If we're at the first page, we don't need to do anything.
|
||||||
if (page <= 1) {
|
if (page <= 1) {
|
||||||
return false;
|
return false;
|
||||||
@ -168,7 +168,7 @@ class PDFPresentationMode {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_goToNextPage() {
|
_goToNextPage() {
|
||||||
var page = this.pdfViewer.currentPageNumber;
|
let page = this.pdfViewer.currentPageNumber;
|
||||||
// If we're at the last page, we don't need to do anything.
|
// If we're at the last page, we don't need to do anything.
|
||||||
if (page >= this.pdfViewer.pagesCount) {
|
if (page >= this.pdfViewer.pagesCount) {
|
||||||
return false;
|
return false;
|
||||||
@ -249,7 +249,7 @@ class PDFPresentationMode {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_exit() {
|
_exit() {
|
||||||
var page = this.pdfViewer.currentPageNumber;
|
let page = this.pdfViewer.currentPageNumber;
|
||||||
this.container.classList.remove(ACTIVE_SELECTOR);
|
this.container.classList.remove(ACTIVE_SELECTOR);
|
||||||
|
|
||||||
// Ensure that the correct page is scrolled into view when exiting
|
// Ensure that the correct page is scrolled into view when exiting
|
||||||
@ -283,7 +283,7 @@ class PDFPresentationMode {
|
|||||||
if (evt.button === 0) {
|
if (evt.button === 0) {
|
||||||
// Enable clicking of links in presentation mode. Note: only links
|
// Enable clicking of links in presentation mode. Note: only links
|
||||||
// pointing to destinations in the current PDF document work.
|
// pointing to destinations in the current PDF document work.
|
||||||
var isInternalLink = (evt.target.href &&
|
let isInternalLink = (evt.target.href &&
|
||||||
evt.target.classList.contains('internalLink'));
|
evt.target.classList.contains('internalLink'));
|
||||||
if (!isInternalLink) {
|
if (!isInternalLink) {
|
||||||
// Unless an internal link was clicked, advance one page.
|
// Unless an internal link was clicked, advance one page.
|
||||||
@ -378,10 +378,10 @@ class PDFPresentationMode {
|
|||||||
if (this.touchSwipeState === null) {
|
if (this.touchSwipeState === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var delta = 0;
|
let delta = 0;
|
||||||
var dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
|
let dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
|
||||||
var dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
|
let dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
|
||||||
var absAngle = Math.abs(Math.atan2(dy, dx));
|
let absAngle = Math.abs(Math.atan2(dy, dx));
|
||||||
if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD &&
|
if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD &&
|
||||||
(absAngle <= SWIPE_ANGLE_THRESHOLD ||
|
(absAngle <= SWIPE_ANGLE_THRESHOLD ||
|
||||||
absAngle >= (Math.PI - SWIPE_ANGLE_THRESHOLD))) {
|
absAngle >= (Math.PI - SWIPE_ANGLE_THRESHOLD))) {
|
||||||
|
@ -138,7 +138,7 @@ class PDFSidebar {
|
|||||||
// immediately closing it would be bad UX.
|
// immediately closing it would be bad UX.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var isViewPreserved = (view === this.visibleView);
|
let isViewPreserved = (view === this.visibleView);
|
||||||
this.switchView(view, /* forceOpen */ true);
|
this.switchView(view, /* forceOpen */ true);
|
||||||
|
|
||||||
if (isViewPreserved) {
|
if (isViewPreserved) {
|
||||||
@ -159,8 +159,8 @@ class PDFSidebar {
|
|||||||
this.close();
|
this.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var isViewChanged = (view !== this.active);
|
let isViewChanged = (view !== this.active);
|
||||||
var shouldForceRendering = false;
|
let shouldForceRendering = false;
|
||||||
|
|
||||||
switch (view) {
|
switch (view) {
|
||||||
case SidebarView.THUMBS:
|
case SidebarView.THUMBS:
|
||||||
@ -290,19 +290,18 @@ class PDFSidebar {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_updateThumbnailViewer() {
|
_updateThumbnailViewer() {
|
||||||
var pdfViewer = this.pdfViewer;
|
let { pdfViewer, pdfThumbnailViewer, } = this;
|
||||||
var thumbnailViewer = this.pdfThumbnailViewer;
|
|
||||||
|
|
||||||
// Use the rendered pages to set the corresponding thumbnail images.
|
// Use the rendered pages to set the corresponding thumbnail images.
|
||||||
var pagesCount = pdfViewer.pagesCount;
|
let pagesCount = pdfViewer.pagesCount;
|
||||||
for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
|
for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
|
||||||
var pageView = pdfViewer.getPageView(pageIndex);
|
let pageView = pdfViewer.getPageView(pageIndex);
|
||||||
if (pageView && pageView.renderingState === RenderingStates.FINISHED) {
|
if (pageView && pageView.renderingState === RenderingStates.FINISHED) {
|
||||||
var thumbnailView = thumbnailViewer.getThumbnail(pageIndex);
|
let thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
|
||||||
thumbnailView.setImage(pageView);
|
thumbnailView.setImage(pageView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
|
pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,7 +346,7 @@ class PDFSidebar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var removeNotification = (view) => {
|
let removeNotification = (view) => {
|
||||||
switch (view) {
|
switch (view) {
|
||||||
case SidebarView.OUTLINE:
|
case SidebarView.OUTLINE:
|
||||||
this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
|
this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
|
||||||
@ -407,7 +406,7 @@ class PDFSidebar {
|
|||||||
|
|
||||||
// Disable/enable views.
|
// Disable/enable views.
|
||||||
this.eventBus.on('outlineloaded', (evt) => {
|
this.eventBus.on('outlineloaded', (evt) => {
|
||||||
var outlineCount = evt.outlineCount;
|
let outlineCount = evt.outlineCount;
|
||||||
|
|
||||||
this.outlineButton.disabled = !outlineCount;
|
this.outlineButton.disabled = !outlineCount;
|
||||||
|
|
||||||
@ -421,7 +420,7 @@ class PDFSidebar {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.eventBus.on('attachmentsloaded', (evt) => {
|
this.eventBus.on('attachmentsloaded', (evt) => {
|
||||||
var attachmentsCount = evt.attachmentsCount;
|
let attachmentsCount = evt.attachmentsCount;
|
||||||
|
|
||||||
this.attachmentsButton.disabled = !attachmentsCount;
|
this.attachmentsButton.disabled = !attachmentsCount;
|
||||||
|
|
||||||
|
@ -30,16 +30,16 @@ class ViewHistory {
|
|||||||
this.cacheSize = cacheSize;
|
this.cacheSize = cacheSize;
|
||||||
|
|
||||||
this._initializedPromise = this._readFromStorage().then((databaseStr) => {
|
this._initializedPromise = this._readFromStorage().then((databaseStr) => {
|
||||||
var database = JSON.parse(databaseStr || '{}');
|
let database = JSON.parse(databaseStr || '{}');
|
||||||
if (!('files' in database)) {
|
if (!('files' in database)) {
|
||||||
database.files = [];
|
database.files = [];
|
||||||
}
|
}
|
||||||
if (database.files.length >= this.cacheSize) {
|
if (database.files.length >= this.cacheSize) {
|
||||||
database.files.shift();
|
database.files.shift();
|
||||||
}
|
}
|
||||||
var index;
|
let index;
|
||||||
for (var i = 0, length = database.files.length; i < length; i++) {
|
for (let i = 0, length = database.files.length; i < length; i++) {
|
||||||
var branch = database.files[i];
|
let branch = database.files[i];
|
||||||
if (branch.fingerprint === this.fingerprint) {
|
if (branch.fingerprint === this.fingerprint) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
@ -55,7 +55,7 @@ class ViewHistory {
|
|||||||
|
|
||||||
_writeToStorage() {
|
_writeToStorage() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
var databaseStr = JSON.stringify(this.database);
|
let databaseStr = JSON.stringify(this.database);
|
||||||
|
|
||||||
if (typeof PDFJSDev !== 'undefined' &&
|
if (typeof PDFJSDev !== 'undefined' &&
|
||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||||
@ -73,16 +73,16 @@ class ViewHistory {
|
|||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||||
resolve(sessionStorage.getItem('pdfjs.history'));
|
resolve(sessionStorage.getItem('pdfjs.history'));
|
||||||
} else {
|
} else {
|
||||||
var value = localStorage.getItem('pdfjs.history');
|
let value = localStorage.getItem('pdfjs.history');
|
||||||
|
|
||||||
// TODO: Remove this key-name conversion after a suitable time-frame.
|
// TODO: Remove this key-name conversion after a suitable time-frame.
|
||||||
// Note that we only remove the old 'database' entry if it looks like
|
// Note that we only remove the old 'database' entry if it looks like
|
||||||
// it was created by PDF.js, to avoid removing someone else's data.
|
// it was created by PDF.js, to avoid removing someone else's data.
|
||||||
if (!value) {
|
if (!value) {
|
||||||
var databaseStr = localStorage.getItem('database');
|
let databaseStr = localStorage.getItem('database');
|
||||||
if (databaseStr) {
|
if (databaseStr) {
|
||||||
try {
|
try {
|
||||||
var database = JSON.parse(databaseStr);
|
let database = JSON.parse(databaseStr);
|
||||||
if (typeof database.files[0].fingerprint === 'string') {
|
if (typeof database.files[0].fingerprint === 'string') {
|
||||||
localStorage.setItem('pdfjs.history', databaseStr);
|
localStorage.setItem('pdfjs.history', databaseStr);
|
||||||
localStorage.removeItem('database');
|
localStorage.removeItem('database');
|
||||||
@ -105,7 +105,7 @@ class ViewHistory {
|
|||||||
|
|
||||||
setMultiple(properties) {
|
setMultiple(properties) {
|
||||||
return this._initializedPromise.then(() => {
|
return this._initializedPromise.then(() => {
|
||||||
for (var name in properties) {
|
for (let name in properties) {
|
||||||
this.file[name] = properties[name];
|
this.file[name] = properties[name];
|
||||||
}
|
}
|
||||||
return this._writeToStorage();
|
return this._writeToStorage();
|
||||||
@ -114,17 +114,17 @@ class ViewHistory {
|
|||||||
|
|
||||||
get(name, defaultValue) {
|
get(name, defaultValue) {
|
||||||
return this._initializedPromise.then(() => {
|
return this._initializedPromise.then(() => {
|
||||||
var val = this.file[name];
|
let val = this.file[name];
|
||||||
return val !== undefined ? val : defaultValue;
|
return val !== undefined ? val : defaultValue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getMultiple(properties) {
|
getMultiple(properties) {
|
||||||
return this._initializedPromise.then(() => {
|
return this._initializedPromise.then(() => {
|
||||||
var values = Object.create(null);
|
let values = Object.create(null);
|
||||||
|
|
||||||
for (var name in properties) {
|
for (let name in properties) {
|
||||||
var val = this.file[name];
|
let val = this.file[name];
|
||||||
values[name] = val !== undefined ? val : properties[name];
|
values[name] = val !== undefined ? val : properties[name];
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user