Replace unnecessary bind(this)
statements with arrow functions in web/
files
By using `let`, which is block-scoped, instead of `var` in a couple of places we're able to get rid of additional `bind` calls.
This commit is contained in:
parent
3adda80f97
commit
f27b5013e2
@ -833,10 +833,10 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
this.loadingBar.show();
|
this.loadingBar.show();
|
||||||
|
|
||||||
this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
|
this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
|
||||||
this.loadingBar.hide();
|
this.loadingBar.hide();
|
||||||
this.disableAutoFetchLoadingBarTimeout = null;
|
this.disableAutoFetchLoadingBarTimeout = null;
|
||||||
}.bind(this), DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
}, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -149,11 +149,11 @@ var FontInspector = (function FontInspectorClosure() {
|
|||||||
fonts.appendChild(font);
|
fonts.appendChild(font);
|
||||||
// Somewhat of a hack, should probably add a hook for when the text layer
|
// Somewhat of a hack, should probably add a hook for when the text layer
|
||||||
// is done rendering.
|
// is done rendering.
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
if (this.active) {
|
if (this.active) {
|
||||||
resetSelection();
|
resetSelection();
|
||||||
}
|
}
|
||||||
}.bind(this), 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -105,20 +105,19 @@ var DownloadManager = (function DownloadManagerClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
download: function DownloadManager_download(blob, url, filename) {
|
download: function DownloadManager_download(blob, url, filename) {
|
||||||
var blobUrl = window.URL.createObjectURL(blob);
|
let blobUrl = window.URL.createObjectURL(blob);
|
||||||
|
let onResponse = (err) => {
|
||||||
|
if (err && this.onerror) {
|
||||||
|
this.onerror(err);
|
||||||
|
}
|
||||||
|
window.URL.revokeObjectURL(blobUrl);
|
||||||
|
};
|
||||||
|
|
||||||
FirefoxCom.request('download', {
|
FirefoxCom.request('download', {
|
||||||
blobUrl,
|
blobUrl,
|
||||||
originalUrl: url,
|
originalUrl: url,
|
||||||
filename,
|
filename,
|
||||||
},
|
}, onResponse);
|
||||||
function response(err) {
|
|
||||||
if (err && this.onerror) {
|
|
||||||
this.onerror(err);
|
|
||||||
}
|
|
||||||
window.URL.revokeObjectURL(blobUrl);
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,16 +53,16 @@ var HandTool = (function HandToolClosure() {
|
|||||||
}
|
}
|
||||||
}).catch(function rejected(reason) { });
|
}).catch(function rejected(reason) { });
|
||||||
|
|
||||||
this.eventBus.on('presentationmodechanged', function (e) {
|
this.eventBus.on('presentationmodechanged', (evt) => {
|
||||||
if (e.switchInProgress) {
|
if (evt.switchInProgress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.active) {
|
if (evt.active) {
|
||||||
this.enterPresentationMode();
|
this.enterPresentationMode();
|
||||||
} else {
|
} else {
|
||||||
this.exitPresentationMode();
|
this.exitPresentationMode();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
HandTool.prototype = {
|
HandTool.prototype = {
|
||||||
|
@ -30,9 +30,8 @@ var OverlayManager = {
|
|||||||
* @returns {Promise} A promise that is resolved when the overlay has been
|
* @returns {Promise} A promise that is resolved when the overlay has been
|
||||||
* registered.
|
* registered.
|
||||||
*/
|
*/
|
||||||
register: function overlayManagerRegister(name, element,
|
register(name, element, callerCloseMethod, canForceClose) {
|
||||||
callerCloseMethod, canForceClose) {
|
return new Promise((resolve) => {
|
||||||
return new Promise(function (resolve) {
|
|
||||||
var container;
|
var container;
|
||||||
if (!name || !element || !(container = element.parentNode)) {
|
if (!name || !element || !(container = element.parentNode)) {
|
||||||
throw new Error('Not enough parameters.');
|
throw new Error('Not enough parameters.');
|
||||||
@ -46,7 +45,7 @@ var OverlayManager = {
|
|||||||
canForceClose: (canForceClose || false),
|
canForceClose: (canForceClose || false),
|
||||||
};
|
};
|
||||||
resolve();
|
resolve();
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,8 +53,8 @@ var OverlayManager = {
|
|||||||
* @returns {Promise} A promise that is resolved when the overlay has been
|
* @returns {Promise} A promise that is resolved when the overlay has been
|
||||||
* unregistered.
|
* unregistered.
|
||||||
*/
|
*/
|
||||||
unregister: function overlayManagerUnregister(name) {
|
unregister(name) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise((resolve) => {
|
||||||
if (!this.overlays[name]) {
|
if (!this.overlays[name]) {
|
||||||
throw new Error('The overlay does not exist.');
|
throw new Error('The overlay does not exist.');
|
||||||
} else if (this.active === name) {
|
} else if (this.active === name) {
|
||||||
@ -64,7 +63,7 @@ var OverlayManager = {
|
|||||||
delete this.overlays[name];
|
delete this.overlays[name];
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,8 +71,8 @@ var OverlayManager = {
|
|||||||
* @returns {Promise} A promise that is resolved when the overlay has been
|
* @returns {Promise} A promise that is resolved when the overlay has been
|
||||||
* opened.
|
* opened.
|
||||||
*/
|
*/
|
||||||
open: function overlayManagerOpen(name) {
|
open(name) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise((resolve) => {
|
||||||
if (!this.overlays[name]) {
|
if (!this.overlays[name]) {
|
||||||
throw new Error('The overlay does not exist.');
|
throw new Error('The overlay does not exist.');
|
||||||
} else if (this.active) {
|
} else if (this.active) {
|
||||||
@ -91,7 +90,7 @@ var OverlayManager = {
|
|||||||
|
|
||||||
window.addEventListener('keydown', this._keyDown);
|
window.addEventListener('keydown', this._keyDown);
|
||||||
resolve();
|
resolve();
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,8 +98,8 @@ var OverlayManager = {
|
|||||||
* @returns {Promise} A promise that is resolved when the overlay has been
|
* @returns {Promise} A promise that is resolved when the overlay has been
|
||||||
* closed.
|
* closed.
|
||||||
*/
|
*/
|
||||||
close: function overlayManagerClose(name) {
|
close(name) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise((resolve) => {
|
||||||
if (!this.overlays[name]) {
|
if (!this.overlays[name]) {
|
||||||
throw new Error('The overlay does not exist.');
|
throw new Error('The overlay does not exist.');
|
||||||
} else if (!this.active) {
|
} else if (!this.active) {
|
||||||
@ -114,13 +113,13 @@ var OverlayManager = {
|
|||||||
|
|
||||||
window.removeEventListener('keydown', this._keyDown);
|
window.removeEventListener('keydown', this._keyDown);
|
||||||
resolve();
|
resolve();
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_keyDown: function overlayManager_keyDown(evt) {
|
_keyDown(evt) {
|
||||||
var self = OverlayManager;
|
var self = OverlayManager;
|
||||||
if (self.active && evt.keyCode === 27) { // Esc key.
|
if (self.active && evt.keyCode === 27) { // Esc key.
|
||||||
self._closeThroughCaller();
|
self._closeThroughCaller();
|
||||||
@ -131,7 +130,7 @@ var OverlayManager = {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_closeThroughCaller: function overlayManager_closeThroughCaller() {
|
_closeThroughCaller() {
|
||||||
if (this.overlays[this.active].callerCloseMethod) {
|
if (this.overlays[this.active].callerCloseMethod) {
|
||||||
this.overlays[this.active].callerCloseMethod();
|
this.overlays[this.active].callerCloseMethod();
|
||||||
}
|
}
|
||||||
|
@ -161,8 +161,8 @@ class PDFAttachmentViewer {
|
|||||||
* Used to append FileAttachment annotations to the sidebar.
|
* Used to append FileAttachment annotations to the sidebar.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_appendAttachment(item) {
|
_appendAttachment({ id, filename, content, }) {
|
||||||
this._renderedCapability.promise.then(function (id, filename, content) {
|
this._renderedCapability.promise.then(() => {
|
||||||
var attachments = this.attachments;
|
var attachments = this.attachments;
|
||||||
|
|
||||||
if (!attachments) {
|
if (!attachments) {
|
||||||
@ -182,7 +182,7 @@ class PDFAttachmentViewer {
|
|||||||
attachments,
|
attachments,
|
||||||
keepRenderedCapability: true,
|
keepRenderedCapability: true,
|
||||||
});
|
});
|
||||||
}.bind(this, item.id, item.filename, item.content));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
this.updateUIState(FindStates.FIND_PENDING);
|
this.updateUIState(FindStates.FIND_PENDING);
|
||||||
|
|
||||||
this._firstPagePromise.then(function() {
|
this._firstPagePromise.then(() => {
|
||||||
this.extractText();
|
this.extractText();
|
||||||
|
|
||||||
clearTimeout(this.findTimeout);
|
clearTimeout(this.findTimeout);
|
||||||
@ -287,7 +287,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
} else {
|
} else {
|
||||||
this.nextMatch();
|
this.nextMatch();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePage: function PDFFindController_updatePage(index) {
|
updatePage: function PDFFindController_updatePage(index) {
|
||||||
|
@ -127,7 +127,7 @@ PDFPrintService.prototype = {
|
|||||||
|
|
||||||
renderPages() {
|
renderPages() {
|
||||||
var pageCount = this.pagesOverview.length;
|
var pageCount = this.pagesOverview.length;
|
||||||
var renderNextPage = function (resolve, reject) {
|
var renderNextPage = (resolve, reject) => {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
if (++this.currentPage >= pageCount) {
|
if (++this.currentPage >= pageCount) {
|
||||||
renderProgress(pageCount, pageCount);
|
renderProgress(pageCount, pageCount);
|
||||||
@ -141,7 +141,7 @@ PDFPrintService.prototype = {
|
|||||||
.then(function () {
|
.then(function () {
|
||||||
renderNextPage(resolve, reject);
|
renderNextPage(resolve, reject);
|
||||||
}, reject);
|
}, reject);
|
||||||
}.bind(this);
|
};
|
||||||
return new Promise(renderNextPage);
|
return new Promise(renderNextPage);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -172,11 +172,11 @@ PDFPrintService.prototype = {
|
|||||||
|
|
||||||
performPrint() {
|
performPrint() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
return new Promise(function (resolve) {
|
return new Promise((resolve) => {
|
||||||
// Push window.print in the macrotask queue to avoid being affected by
|
// Push window.print in the macrotask queue to avoid being affected by
|
||||||
// the deprecation of running print() code in a microtask, see
|
// the deprecation of running print() code in a microtask, see
|
||||||
// https://github.com/mozilla/pdf.js/issues/7547.
|
// https://github.com/mozilla/pdf.js/issues/7547.
|
||||||
setTimeout(function () {
|
setTimeout(() => {
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
@ -184,8 +184,8 @@ PDFPrintService.prototype = {
|
|||||||
print.call(window);
|
print.call(window);
|
||||||
// Delay promise resolution in case print() was not synchronous.
|
// Delay promise resolution in case print() was not synchronous.
|
||||||
setTimeout(resolve, 20); // Tidy-up.
|
setTimeout(resolve, 20); // Tidy-up.
|
||||||
}.bind(this), 0);
|
}, 0);
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
get active() {
|
get active() {
|
||||||
|
@ -138,10 +138,10 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return pdfDocument.getPage(1).then(function (firstPage) {
|
return pdfDocument.getPage(1).then((firstPage) => {
|
||||||
var pagesCount = pdfDocument.numPages;
|
var pagesCount = pdfDocument.numPages;
|
||||||
var viewport = firstPage.getViewport(1.0);
|
var viewport = firstPage.getViewport(1.0);
|
||||||
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||||
var thumbnail = new PDFThumbnailView({
|
var thumbnail = new PDFThumbnailView({
|
||||||
container: this.container,
|
container: this.container,
|
||||||
id: pageNum,
|
id: pageNum,
|
||||||
@ -152,7 +152,7 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
|||||||
});
|
});
|
||||||
this.thumbnails.push(thumbnail);
|
this.thumbnails.push(thumbnail);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,8 +383,8 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var getPagesLeft = pagesCount;
|
var getPagesLeft = pagesCount;
|
||||||
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||||
pdfDocument.getPage(pageNum).then(function(pageNum, pdfPage) {
|
pdfDocument.getPage(pageNum).then((pdfPage) => {
|
||||||
var pageView = this._pages[pageNum - 1];
|
var pageView = this._pages[pageNum - 1];
|
||||||
if (!pageView.pdfPage) {
|
if (!pageView.pdfPage) {
|
||||||
pageView.setPdfPage(pdfPage);
|
pageView.setPdfPage(pdfPage);
|
||||||
@ -393,7 +393,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
if (--getPagesLeft === 0) {
|
if (--getPagesLeft === 0) {
|
||||||
pagesCapability.resolve();
|
pagesCapability.resolve();
|
||||||
}
|
}
|
||||||
}.bind(this, pageNum));
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -139,19 +139,17 @@ var SecondaryToolbar = (function SecondaryToolbarClosure() {
|
|||||||
this.toggleButton.addEventListener('click', this.toggle.bind(this));
|
this.toggleButton.addEventListener('click', this.toggle.bind(this));
|
||||||
|
|
||||||
// All items within the secondary toolbar.
|
// All items within the secondary toolbar.
|
||||||
for (var button in this.buttons) {
|
for (let button in this.buttons) {
|
||||||
var element = this.buttons[button].element;
|
let { element, eventName, close, } = this.buttons[button];
|
||||||
var eventName = this.buttons[button].eventName;
|
|
||||||
var close = this.buttons[button].close;
|
|
||||||
|
|
||||||
element.addEventListener('click', function (eventName, close) {
|
element.addEventListener('click', (evt) => {
|
||||||
if (eventName !== null) {
|
if (eventName !== null) {
|
||||||
this.eventBus.dispatch(eventName, { source: this, });
|
this.eventBus.dispatch(eventName, { source: this, });
|
||||||
}
|
}
|
||||||
if (close) {
|
if (close) {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}.bind(this, eventName, close));
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
timeout,
|
timeout,
|
||||||
enhanceTextSelection: this.enhanceTextSelection,
|
enhanceTextSelection: this.enhanceTextSelection,
|
||||||
});
|
});
|
||||||
this.textLayerRenderTask.promise.then(function () {
|
this.textLayerRenderTask.promise.then(() => {
|
||||||
this.textLayerDiv.appendChild(textLayerFrag);
|
this.textLayerDiv.appendChild(textLayerFrag);
|
||||||
this._finishRendering();
|
this._finishRendering();
|
||||||
this.updateMatches();
|
this.updateMatches();
|
||||||
}.bind(this), function (reason) {
|
}, function (reason) {
|
||||||
// cancelled or failed to render text layer -- skipping errors
|
// cancelled or failed to render text layer -- skipping errors
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user