Merge pull request #1926 from yurydelendik/fix-relative-url

Allow relative URLs in getDocument
This commit is contained in:
Brendan Dahl 2012-07-26 13:52:05 -07:00
commit 09acd7b2b2
3 changed files with 12 additions and 3 deletions

View File

@ -32,11 +32,21 @@ PDFJS.getDocument = function getDocument(source) {
if (!source.url && !source.data)
error('Invalid parameter array, need either .data or .url');
// copy/use all keys as is except 'url' -- full path is required
var params = {};
for (var key in source) {
if (key === 'url' && typeof window !== 'undefined') {
params[key] = combineUrl(window.location.href, source[key]);
continue;
}
params[key] = source[key];
}
workerInitializedPromise = new PDFJS.Promise();
workerReadyPromise = new PDFJS.Promise();
transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise);
workerInitializedPromise.then(function transportInitialized() {
transport.fetchDocument(source);
transport.fetchDocument(params);
});
return workerReadyPromise;
};

View File

@ -78,7 +78,6 @@ function combineUrl(baseUrl, url) {
return baseUrl.substring(0, prefixLength + 1) + url;
}
}
PDFJS.combineUrl = combineUrl;
// In a well-formed PDF, |cond| holds. If it doesn't, subsequent
// behavior is undefined.

View File

@ -395,7 +395,7 @@ var PDFView = {
if (typeof url === 'string') { // URL
this.url = url;
document.title = decodeURIComponent(getFileName(url)) || url;
parameters.url = PDFJS.combineUrl(window.location.href, url);
parameters.url = url;
} else if (url && 'byteLength' in url) { // ArrayBuffer
parameters.data = url;
}