Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change var to let, and use object destructuring, in a couple of previously class converted web/*.js files #8594

Merged
merged 1 commit into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class AnnotationLayerBuilder {
/**
* @param {AnnotationLayerBuilderOptions} options
*/
constructor(options) {
this.pageDiv = options.pageDiv;
this.pdfPage = options.pdfPage;
this.renderInteractiveForms = options.renderInteractiveForms;
this.linkService = options.linkService;
this.downloadManager = options.downloadManager;
this.l10n = options.l10n || NullL10n;
constructor({ pageDiv, pdfPage, linkService, downloadManager,
renderInteractiveForms = false, l10n = NullL10n, }) {
this.pageDiv = pageDiv;
this.pdfPage = pdfPage;
this.linkService = linkService;
this.downloadManager = downloadManager;
this.renderInteractiveForms = renderInteractiveForms;
this.l10n = l10n;

this.div = null;
}
Expand All @@ -48,7 +49,7 @@ class AnnotationLayerBuilder {
*/
render(viewport, intent = 'display') {
this.pdfPage.getAnnotations({ intent, }).then((annotations) => {
var parameters = {
let parameters = {
viewport: viewport.clone({ dontFlip: true, }),
div: this.div,
annotations,
Expand All @@ -68,7 +69,6 @@ class AnnotationLayerBuilder {
if (annotations.length === 0) {
return;
}

this.div = document.createElement('div');
this.div.className = 'annotationLayer';
this.pageDiv.appendChild(this.div);
Expand Down Expand Up @@ -99,8 +99,7 @@ class DefaultAnnotationLayerFactory {
* @param {IL10n} l10n
* @returns {AnnotationLayerBuilder}
*/
createAnnotationLayerBuilder(pageDiv, pdfPage,
renderInteractiveForms = false,
createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false,
l10n = NullL10n) {
return new AnnotationLayerBuilder({
pageDiv,
Expand Down
2 changes: 1 addition & 1 deletion web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class PasswordPrompt {
}

verify() {
var password = this.input.value;
let password = this.input.value;
if (password && password.length > 0) {
this.close();
return this.updateCallback(password);
Expand Down
40 changes: 19 additions & 21 deletions web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import {

/**
* @typedef {Object} PDFAttachmentViewerRenderParameters
* @property {Array|null} attachments - An array of attachment objects.
* @property {Object|null} attachments - A lookup table of attachment objects.
*/

class PDFAttachmentViewer {
/**
* @param {PDFAttachmentViewerOptions} options
*/
constructor(options) {
constructor({ container, eventBus, downloadManager, }) {
this.attachments = null;

this.container = options.container;
this.eventBus = options.eventBus;
this.downloadManager = options.downloadManager;
this.container = container;
this.eventBus = eventBus;
this.downloadManager = downloadManager;

this._renderedCapability = createPromiseCapability();
this.eventBus.on('fileattachmentannotation',
Expand Down Expand Up @@ -79,12 +79,12 @@ class PDFAttachmentViewer {
throw new Error('bindPdfLink: ' +
'Unsupported "PDFJS.disableCreateObjectURL" value.');
}
var blobUrl;
let blobUrl;
button.onclick = function() {
if (!blobUrl) {
blobUrl = createObjectURL(content, 'application/pdf');
}
var viewerUrl;
let viewerUrl;
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
// The current URL is the viewer, let's use it and append the file.
viewerUrl = '?file=' + encodeURIComponent(blobUrl + '#' + filename);
Expand Down Expand Up @@ -116,33 +116,31 @@ class PDFAttachmentViewer {
/**
* @param {PDFAttachmentViewerRenderParameters} params
*/
render(params = {}) {
var attachments = params.attachments || null;
var attachmentsCount = 0;
render({ attachments, keepRenderedCapability = false, }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keepRenderedCapability is not in the documentation for PDFAttachmentViewerRenderParameters above. Could you add it for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a comment in

if (!keepRenderedCapability) {
// NOTE: The *only* situation in which the `_renderedCapability` should
// not be replaced is when appending file attachment annotations.
this._renderedCapability = createPromiseCapability();
}
, which was added as a result of the discussion in #7959 (comment).

Since that parameter should not be used unless you know what you're doing, I didn't want to add a too visible comment; do you no longer think that this was the right call here?

let attachmentsCount = 0;

if (this.attachments) {
var keepRenderedCapability = params.keepRenderedCapability === true;
this.reset(keepRenderedCapability);
this.reset(keepRenderedCapability === true);
}
this.attachments = attachments;
this.attachments = attachments || null;

if (!attachments) {
this._dispatchEvent(attachmentsCount);
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());
});
attachmentsCount = names.length;

for (var i = 0; i < attachmentsCount; i++) {
var item = attachments[names[i]];
var filename = removeNullCharacters(getFilenameFromUrl(item.filename));
for (let i = 0; i < attachmentsCount; i++) {
let item = attachments[names[i]];
let filename = removeNullCharacters(getFilenameFromUrl(item.filename));

var div = document.createElement('div');
let div = document.createElement('div');
div.className = 'attachmentsItem';
var button = document.createElement('button');
let button = document.createElement('button');
button.textContent = filename;
if (/\.pdf$/i.test(filename) && !PDFJS.disableCreateObjectURL) {
this._bindPdfLink(button, item.content, filename);
Expand All @@ -163,12 +161,12 @@ class PDFAttachmentViewer {
*/
_appendAttachment({ id, filename, content, }) {
this._renderedCapability.promise.then(() => {
var attachments = this.attachments;
let attachments = this.attachments;

if (!attachments) {
attachments = Object.create(null);
} else {
for (var name in attachments) {
for (let name in attachments) {
if (id === name) {
return; // Ignore the new attachment if it already exists.
}
Expand Down
24 changes: 12 additions & 12 deletions web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ class PDFDocumentProperties {
// Get all elements from the PDF date string.
// JavaScript's `Date` object expects the month to be between
// 0 and 11 instead of 1 and 12, so we're correcting for this.
var year = parseInt(dateToParse.substring(0, 4), 10);
var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
var day = parseInt(dateToParse.substring(6, 8), 10);
var hours = parseInt(dateToParse.substring(8, 10), 10);
var minutes = parseInt(dateToParse.substring(10, 12), 10);
var seconds = parseInt(dateToParse.substring(12, 14), 10);
var utRel = dateToParse.substring(14, 15);
var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
let year = parseInt(dateToParse.substring(0, 4), 10);
let month = parseInt(dateToParse.substring(4, 6), 10) - 1;
let day = parseInt(dateToParse.substring(6, 8), 10);
let hours = parseInt(dateToParse.substring(8, 10), 10);
let minutes = parseInt(dateToParse.substring(10, 12), 10);
let seconds = parseInt(dateToParse.substring(12, 14), 10);
let utRel = dateToParse.substring(14, 15);
let offsetHours = parseInt(dateToParse.substring(15, 17), 10);
let offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);

// As per spec, utRel = 'Z' means equal to universal time.
// The other cases ('-' and '+') have to be handled here.
Expand All @@ -252,9 +252,9 @@ class PDFDocumentProperties {
}

// Return the new date format from the user's locale.
var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
var dateString = date.toLocaleDateString();
var timeString = date.toLocaleTimeString();
let date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
let dateString = date.toLocaleDateString();
let timeString = date.toLocaleTimeString();
return this.l10n.get('document_properties_date_string',
{ date: dateString, time: timeString, },
'{{date}}, {{time}}');
Expand Down
10 changes: 5 additions & 5 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class PDFFindBar {
}

updateUIState(state, previous, matchCount) {
var notFound = false;
var findMsg = '';
var status = '';
let notFound = false;
let findMsg = '';
let status = '';

switch (state) {
case FindState.FOUND:
Expand Down Expand Up @@ -206,8 +206,8 @@ class PDFFindBar {
// wrapped). Here we detect and fix that.
this.bar.classList.remove('wrapContainers');

var findbarHeight = this.bar.clientHeight;
var inputContainerHeight = this.bar.firstElementChild.clientHeight;
let findbarHeight = this.bar.clientHeight;
let inputContainerHeight = this.bar.firstElementChild.clientHeight;

if (findbarHeight > inputContainerHeight) {
// The findbar is taller than the input container, which means that
Expand Down
45 changes: 22 additions & 23 deletions web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class PDFOutlineViewer {
/**
* @param {PDFOutlineViewerOptions} options
*/
constructor(options) {
constructor({ container, linkService, eventBus, }) {
this.outline = null;
this.lastToggleIsShow = true;

this.container = options.container;
this.linkService = options.linkService;
this.eventBus = options.eventBus;
this.container = container;
this.linkService = linkService;
this.eventBus = eventBus;
}

reset() {
Expand Down Expand Up @@ -77,7 +77,7 @@ class PDFOutlineViewer {
});
return;
}
var destination = item.dest;
let destination = item.dest;

element.href = this.linkService.getDestinationHash(destination);
element.onclick = () => {
Expand All @@ -92,7 +92,7 @@ class PDFOutlineViewer {
* @private
*/
_setStyles(element, item) {
var styleStr = '';
let styleStr = '';
if (item.bold) {
styleStr += 'font-weight: bold;';
}
Expand All @@ -112,14 +112,14 @@ class PDFOutlineViewer {
* @private
*/
_addToggleButton(div) {
var toggler = document.createElement('div');
let toggler = document.createElement('div');
toggler.className = 'outlineItemToggler';
toggler.onclick = (evt) => {
evt.stopPropagation();
toggler.classList.toggle('outlineItemsHidden');

if (evt.shiftKey) {
var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
let shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
this._toggleOutlineItem(div, shouldShowAll);
}
};
Expand All @@ -137,8 +137,8 @@ class PDFOutlineViewer {
*/
_toggleOutlineItem(root, show) {
this.lastToggleIsShow = show;
var togglers = root.querySelectorAll('.outlineItemToggler');
for (var i = 0, ii = togglers.length; i < ii; ++i) {
let togglers = root.querySelectorAll('.outlineItemToggler');
for (let i = 0, ii = togglers.length; i < ii; ++i) {
togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
}
}
Expand All @@ -156,32 +156,31 @@ class PDFOutlineViewer {
/**
* @param {PDFOutlineViewerRenderParameters} params
*/
render(params = {}) {
var outline = params.outline || null;
var outlineCount = 0;
render({ outline, }) {
let outlineCount = 0;

if (this.outline) {
this.reset();
}
this.outline = outline;
this.outline = outline || null;

if (!outline) {
this._dispatchEvent(outlineCount);
return;
}

var fragment = document.createDocumentFragment();
var queue = [{ parent: fragment, items: this.outline, }];
var hasAnyNesting = false;
let fragment = document.createDocumentFragment();
let queue = [{ parent: fragment, items: this.outline, }];
let hasAnyNesting = false;
while (queue.length > 0) {
var levelData = queue.shift();
for (var i = 0, len = levelData.items.length; i < len; i++) {
var item = levelData.items[i];
let levelData = queue.shift();
for (let i = 0, len = levelData.items.length; i < len; i++) {
let item = levelData.items[i];

var div = document.createElement('div');
let div = document.createElement('div');
div.className = 'outlineItem';

var element = document.createElement('a');
let element = document.createElement('a');
this._bindLink(element, item);
this._setStyles(element, item);
element.textContent =
Expand All @@ -193,7 +192,7 @@ class PDFOutlineViewer {
hasAnyNesting = true;
this._addToggleButton(div);

var itemsDiv = document.createElement('div');
let itemsDiv = document.createElement('div');
itemsDiv.className = 'outlineItems';
div.appendChild(itemsDiv);
queue.push({ parent: itemsDiv, items: item.items, });
Expand Down
Loading