Set title using logic similar as download name
The download method (and the PDF document properties) detect the file name using `getPDFFileNameFromURL`. The title ought to also display the PDF filename if available.
This commit is contained in:
parent
228d253f30
commit
c67edabcb3
17
web/app.js
17
web/app.js
@ -569,14 +569,17 @@ var PDFViewerApplication = {
|
|||||||
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
|
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.baseUrl = url.split('#')[0];
|
this.baseUrl = url.split('#')[0];
|
||||||
try {
|
var title = getPDFFileNameFromURL(url, '');
|
||||||
this.setTitle(decodeURIComponent(
|
if (!title) {
|
||||||
pdfjsLib.getFilenameFromUrl(url)) || url);
|
try {
|
||||||
} catch (e) {
|
title = decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url;
|
||||||
// decodeURIComponent may throw URIError,
|
} catch (e) {
|
||||||
// fall back to using the unprocessed url in that case
|
// decodeURIComponent may throw URIError,
|
||||||
this.setTitle(url);
|
// fall back to using the unprocessed url in that case
|
||||||
|
title = url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.setTitle(title);
|
||||||
},
|
},
|
||||||
|
|
||||||
setTitle: function pdfViewSetTitle(title) {
|
setTitle: function pdfViewSetTitle(title) {
|
||||||
|
@ -368,9 +368,13 @@ function noContextMenuHandler(e) {
|
|||||||
/**
|
/**
|
||||||
* Returns the filename or guessed filename from the url (see issue 3455).
|
* Returns the filename or guessed filename from the url (see issue 3455).
|
||||||
* url {String} The original PDF location.
|
* url {String} The original PDF location.
|
||||||
|
* defaultFilename {string} The value to return if the file name is unknown.
|
||||||
* @return {String} Guessed PDF file name.
|
* @return {String} Guessed PDF file name.
|
||||||
*/
|
*/
|
||||||
function getPDFFileNameFromURL(url) {
|
function getPDFFileNameFromURL(url, defaultFilename) {
|
||||||
|
if (typeof defaultFilename === 'undefined') {
|
||||||
|
defaultFilename = 'document.pdf';
|
||||||
|
}
|
||||||
var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
||||||
// SCHEME HOST 1.PATH 2.QUERY 3.REF
|
// SCHEME HOST 1.PATH 2.QUERY 3.REF
|
||||||
// Pattern to get last matching NAME.pdf
|
// Pattern to get last matching NAME.pdf
|
||||||
@ -392,7 +396,7 @@ function getPDFFileNameFromURL(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return suggestedFilename || 'document.pdf';
|
return suggestedFilename || defaultFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeWheelEventDelta(evt) {
|
function normalizeWheelEventDelta(evt) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user