Commit fc9ab346 by Brian Wilson

fix loading of specific pages.

parent dde2cd0b
...@@ -27,25 +27,28 @@ PDFJS.disableWorker = true; ...@@ -27,25 +27,28 @@ PDFJS.disableWorker = true;
var pdfViewer = this; var pdfViewer = this;
var pdfDocument = null; var pdfDocument = null;
var url = null; var urlToLoad = null;
if (options.url) { if (options.url) {
url = options.url; urlToLoad = options.url;
} }
var chapter_urls = null; var chapterUrls = null;
if (options.chapters) { if (options.chapters) {
chapter_urls = options.chapters; chapterUrls = options.chapters;
} }
var chapterNum = 1; var chapterToLoad = 1;
if (options.chapterNum) { if (options.chapterNum) {
chapterNum = options.chapterNum;
// TODO: this should only be specified if there are // TODO: this should only be specified if there are
// chapters, and it should be in-bounds. // chapters, and it should be in-bounds.
chapterToLoad = options.chapterNum;
} }
var pageNum = 1; var pageToLoad = 1;
if (options.pageNum) { if (options.pageNum) {
pageNum = options.pageNum; pageToLoad = options.pageNum;
} }
var chapterNum = 1;
var pageNum = 1;
var viewerElement = document.getElementById('viewer'); var viewerElement = document.getElementById('viewer');
var ANNOT_MIN_SIZE = 10; var ANNOT_MIN_SIZE = 10;
var DEFAULT_SCALE_DELTA = 1.1; var DEFAULT_SCALE_DELTA = 1.1;
...@@ -280,13 +283,21 @@ PDFJS.disableWorker = true; ...@@ -280,13 +283,21 @@ PDFJS.disableWorker = true;
// //
// Asynchronously download PDF as an ArrayBuffer // Asynchronously download PDF as an ArrayBuffer
// //
loadUrl = function pdfViewLoadUrl(url_to_load) { loadUrl = function pdfViewLoadUrl(url, page) {
PDFJS.getDocument(url_to_load).then( PDFJS.getDocument(url).then(
function getDocument(_pdfDocument) { function getDocument(_pdfDocument) {
pdfDocument = _pdfDocument; pdfDocument = _pdfDocument;
// display the current page with a default scale value: pageNum = page;
currentScale = UNKNOWN_SCALE; // if the scale has not been set before, set it now.
parseScale(DEFAULT_SCALE_VALUE); // Otherwise, don't change the current scale,
// but make sure it gets refreshed.
if (currentScale == UNKNOWN_SCALE) {
parseScale(DEFAULT_SCALE_VALUE);
} else {
var preservedScale = currentScale;
currentScale = UNKNOWN_SCALE;
parseScale(preservedScale);
}
}, },
function getDocumentError(message, exception) { function getDocumentError(message, exception) {
// placeholder: don't expect errors :) // placeholder: don't expect errors :)
...@@ -296,9 +307,12 @@ PDFJS.disableWorker = true; ...@@ -296,9 +307,12 @@ PDFJS.disableWorker = true;
}); });
}; };
loadChapterUrl = function pdfViewLoadChapterUrl(chapter_index) { loadChapterUrl = function pdfViewLoadChapterUrl(chapterNum, pageVal) {
var chapter_url = chapter_urls[chapter_index]; if (chapterNum < 1 || chapterNum > chapterUrls.length) {
loadUrl(chapter_url); return;
}
var chapterUrl = chapterUrls[chapterNum-1];
loadUrl(chapterUrl, pageVal);
} }
$("#previous").click(function(event) { $("#previous").click(function(event) {
...@@ -329,22 +343,23 @@ PDFJS.disableWorker = true; ...@@ -329,22 +343,23 @@ PDFJS.disableWorker = true;
}); });
// define navigation links for chapters: // define navigation links for chapters:
if (chapter_urls != null) { if (chapterUrls != null) {
var loadChapterUrlHelper = function(i) { var loadChapterUrlHelper = function(i) {
return function(event) { return function(event) {
loadChapterUrl(i); // when opening a new chapter, always open the first page:
loadChapterUrl(i, 1);
}; };
}; };
for (var index = 1; index <= chapter_urls.length; index += 1) { for (var index = 1; index <= chapterUrls.length; index += 1) {
$("#pdfchapter-" + index).click(loadChapterUrlHelper(index)); $("#pdfchapter-" + index).click(loadChapterUrlHelper(index));
} }
} }
// finally, load the appropriate page // finally, load the appropriate url/page
if (url != null) { if (urlToLoad != null) {
loadUrl(url); loadUrl(urlToLoad, pageToLoad);
} else { } else {
loadChapterUrl(chapterNum); loadChapterUrl(chapterToLoad, pageToLoad);
} }
return pdfViewer; return pdfViewer;
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
options.chapters = chptrs; options.chapters = chptrs;
%endif %endif
%if chapter is not None: %if chapter is not None:
options.chapterNum : ${chapter}; options.chapterNum = ${chapter};
%endif %endif
%if page is not None: %if page is not None:
options.pageNum : ${page}; options.pageNum = ${page};
%endif %endif
$('#outerContainer').PDFViewer(options); $('#outerContainer').PDFViewer(options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment