From af4bd10c705afb76ee497897e6d5d7cda0b33f21 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Thu, 26 Jul 2012 12:11:28 -0500 Subject: [PATCH] Allow relative URLs in getDocument --- src/api.js | 12 +++++++++++- src/util.js | 1 - web/viewer.js | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/api.js b/src/api.js index 7429c4779..3a5b8678d 100644 --- a/src/api.js +++ b/src/api.js @@ -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; }; diff --git a/src/util.js b/src/util.js index ad915b03f..df91f6064 100644 --- a/src/util.js +++ b/src/util.js @@ -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. diff --git a/web/viewer.js b/web/viewer.js index 8bd0c485c..e24e694f2 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -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; }