Merge pull request #8024 from Rob--W/issue-6643-pdf-attachment-in-pdfjs

Open PDF attachments in the viewer instead of an unconditional download
This commit is contained in:
Tim van der Meij 2017-02-18 21:52:29 +01:00 committed by GitHub
commit cf73f4bc2d
5 changed files with 66 additions and 14 deletions

View file

@ -574,14 +574,17 @@ var PDFViewerApplication = {
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
this.url = url;
this.baseUrl = url.split('#')[0];
try {
this.setTitle(decodeURIComponent(
pdfjsLib.getFilenameFromUrl(url)) || url);
} catch (e) {
// decodeURIComponent may throw URIError,
// fall back to using the unprocessed url in that case
this.setTitle(url);
var title = getPDFFileNameFromURL(url, '');
if (!title) {
try {
title = decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url;
} catch (e) {
// decodeURIComponent may throw URIError,
// fall back to using the unprocessed url in that case
title = url;
}
}
this.setTitle(title);
},
setTitle: function pdfViewSetTitle(title) {
@ -742,7 +745,9 @@ var PDFViewerApplication = {
}
var url = this.baseUrl;
var filename = getPDFFileNameFromURL(url);
// Use this.url instead of this.baseUrl to perform filename detection based
// on the reference fragment as ultimate fallback if needed.
var filename = getPDFFileNameFromURL(this.url);
var downloadManager = this.downloadManager;
downloadManager.onerror = function (err) {
// This error won't really be helpful because it's likely the