diff --git a/common/static/css/pdfviewer.css b/common/static/css/pdfviewer.css index 716db251f0..656bc47c29 100644 --- a/common/static/css/pdfviewer.css +++ b/common/static/css/pdfviewer.css @@ -85,13 +85,16 @@ select { } #viewerContainer { - overflow: auto; +/* overflow: auto; */ box-shadow: inset 1px 0 0 hsla(0,0%,100%,.05); /* position: absolute; top: 32px; right: 0; bottom: 0; left: 0; */ +/* switch to using these instead: */ + position: relative; + overflow: hidden; } .toolbar { diff --git a/common/static/js/pdfviewer.js b/common/static/js/pdfviewer.js index c25b1b2e4e..c81709fa0f 100644 --- a/common/static/js/pdfviewer.js +++ b/common/static/js/pdfviewer.js @@ -27,11 +27,27 @@ PDFJS.disableWorker = true; var pdfViewer = this; var pdfDocument = null; - var url = options['url']; - var pageNum = 1; - if (options.pageNum) { - pageNum = options.pageNum; + var urlToLoad = null; + if (options.url) { + urlToLoad = options.url; } + var chapterUrls = null; + if (options.chapters) { + chapterUrls = options.chapters; + } + var chapterToLoad = 1; + if (options.chapterNum) { + // TODO: this should only be specified if there are + // chapters, and it should be in-bounds. + chapterToLoad = options.chapterNum; + } + var pageToLoad = 1; + if (options.pageNum) { + pageToLoad = options.pageNum; + } + + var chapterNum = 1; + var pageNum = 1; var viewerElement = document.getElementById('viewer'); var ANNOT_MIN_SIZE = 10; @@ -44,31 +60,28 @@ PDFJS.disableWorker = true; var currentScaleValue = "0"; var DEFAULT_SCALE_VALUE = "1"; - // TESTING: - var destinations = null; - var setupText = function setupText(textdiv, content, viewport) { function getPageNumberFromDest(dest) { - var destPage = 1; - if (dest instanceof Array) { - var destRef = dest[0]; - if (destRef instanceof Object) { - // we would need to look this up in the - // list of all pages that have been loaded, - // but we're trying to not have to load all the pages - // right now. - // destPage = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R']; - } else { - destPage = (destRef + 1); - } - } - return destPage; - } + var destPage = 1; + if (dest instanceof Array) { + var destRef = dest[0]; + if (destRef instanceof Object) { + // we would need to look this up in the + // list of all pages that have been loaded, + // but we're trying to not have to load all the pages + // right now. + // destPage = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R']; + } else { + destPage = (destRef + 1); + } + } + return destPage; + } function bindLink(link, dest) { - // get page number from dest: - destPage = getPageNumberFromDest(dest); + // get page number from dest: + destPage = getPageNumberFromDest(dest); link.href = '#page=' + destPage; link.onclick = function pageViewSetupLinksOnclick() { if (dest && dest instanceof Array ) @@ -138,10 +151,10 @@ PDFJS.disableWorker = true; // Get page info from document, resize canvas accordingly, and render page // renderPage = function(num) { - // don't try to render a page that cannot be rendered - if (num < 1 || num > pdfDocument.numPages) { - return; - } + // don't try to render a page that cannot be rendered + if (num < 1 || num > pdfDocument.numPages) { + return; + } // Update logging: log_event("book", { "type" : "gotopage", "old" : pageNum, "new" : num }); @@ -270,18 +283,37 @@ PDFJS.disableWorker = true; // // Asynchronously download PDF as an ArrayBuffer // - PDFJS.getDocument(url).then( - function getDocument(_pdfDocument) { - pdfDocument = _pdfDocument; - // display the current page with a default scale value: - parseScale(DEFAULT_SCALE_VALUE); - }, - function getDocumentError(message, exception) { - // placeholder: don't expect errors :) - }, - function getDocumentProgress(progressData) { - // placeholder: not yet ready to display loading progress - }); + loadUrl = function pdfViewLoadUrl(url, page) { + PDFJS.getDocument(url).then( + function getDocument(_pdfDocument) { + pdfDocument = _pdfDocument; + pageNum = page; + // if the scale has not been set before, set it now. + // 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) { + // placeholder: don't expect errors :) + }, + function getDocumentProgress(progressData) { + // placeholder: not yet ready to display loading progress + }); + }; + + loadChapterUrl = function pdfViewLoadChapterUrl(chapterNum, pageVal) { + if (chapterNum < 1 || chapterNum > chapterUrls.length) { + return; + } + var chapterUrl = chapterUrls[chapterNum-1]; + loadUrl(chapterUrl, pageVal); + } $("#previous").click(function(event) { prevPage(); @@ -302,11 +334,34 @@ PDFJS.disableWorker = true; parseScale(this.value); }); + $('#pageNumber').change(function(event) { - var newPageVal = parseInt(this.value); - if (newPageVal) { - renderPage(newPageVal); - } + var newPageVal = parseInt(this.value); + if (newPageVal) { + renderPage(newPageVal); + } }); + + // define navigation links for chapters: + if (chapterUrls != null) { + var loadChapterUrlHelper = function(i) { + return function(event) { + // when opening a new chapter, always open the first page: + loadChapterUrl(i, 1); + }; + }; + for (var index = 1; index <= chapterUrls.length; index += 1) { + $("#pdfchapter-" + index).click(loadChapterUrlHelper(index)); + } + } + + // finally, load the appropriate url/page + if (urlToLoad != null) { + loadUrl(urlToLoad, pageToLoad); + } else { + loadChapterUrl(chapterToLoad, pageToLoad); + } + + return pdfViewer; } })(jQuery); diff --git a/lms/djangoapps/staticbook/views.py b/lms/djangoapps/staticbook/views.py index be7e272596..a391b1cb32 100644 --- a/lms/djangoapps/staticbook/views.py +++ b/lms/djangoapps/staticbook/views.py @@ -52,13 +52,18 @@ def pdf_index(request, course_id, book_index, chapter=None, page=None): # strip off the quotes again... return output_url[1:-1] - textbook['url'] = remap_static_url(textbook['url'], course) + if 'url' in textbook: + textbook['url'] = remap_static_url(textbook['url'], course) # then remap all the chapter URLs as well, if they are provided. - + if 'chapters' in textbook: + for entry in textbook['chapters']: + entry['url'] = remap_static_url(entry['url'], course) + + return render_to_response('static_pdfbook.html', {'book_index': book_index, 'course': course, 'textbook': textbook, - 'page': page, 'chapter': chapter, + 'page': page, 'staff_access': staff_access}) diff --git a/lms/static/sass/course/_textbook.scss b/lms/static/sass/course/_textbook.scss index 4bda5a46d6..af9c2493fd 100644 --- a/lms/static/sass/course/_textbook.scss +++ b/lms/static/sass/course/_textbook.scss @@ -102,6 +102,7 @@ div.book-wrapper { position: absolute; height: 100%; width: flex-grid(2, 8); + z-index: 1; a { background-color: rgba(#000, .7); diff --git a/lms/templates/static_pdfbook.html b/lms/templates/static_pdfbook.html index 386d921b90..013413b62d 100644 --- a/lms/templates/static_pdfbook.html +++ b/lms/templates/static_pdfbook.html @@ -17,37 +17,39 @@ <%block name="js_extra"> <%include file="/courseware/course_navigation.html" args="active_page='pdftextbook/{0}'.format(book_index)" /> -
-
+
+
-
- -
- -
@@ -88,7 +90,38 @@
-
+%if 'chapters' in textbook: +
+ +
    + <%def name="print_entry(entry, index_value)"> +
  • + + ${entry.get('title')} + +
  • + + + % for (index, entry) in enumerate(textbook['chapters']): + ${print_entry(entry, index+1)} + % endfor +
+
+%endif + +
+ + +
diff --git a/lms/urls.py b/lms/urls.py index 4d9798f360..e8b4b17c3c 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -280,11 +280,10 @@ if settings.COURSEWARE_ENABLED: url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P[^/]*)/(?P[^/]*)$', 'staticbook.views.pdf_index'), -# Doesn't yet support loading individual chapters... -# url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P[^/]*)/chapter/(?P[^/]*)/$', -# 'staticbook.views.pdf_index'), -# url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P[^/]*)/chapter/(?P[^/]*)/(?P[^/]*)$', -# 'staticbook.views.pdf_index'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P[^/]*)/chapter/(?P[^/]*)/$', + 'staticbook.views.pdf_index'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/pdfbook/(?P[^/]*)/chapter/(?P[^/]*)/(?P[^/]*)$', + 'staticbook.views.pdf_index'), url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/courseware/?$', 'courseware.views.index', name="courseware"),