From bed7dbdb6bf3bae7f51d8c1012f4fb82cebd44ae Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Fri, 8 Mar 2013 18:25:33 -0500 Subject: [PATCH] fix plumbing for anchors and chapters. --- lms/djangoapps/staticbook/views.py | 4 ++-- lms/templates/static_htmlbook.html | 34 +++++++++++------------------- lms/urls.py | 6 +++++- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/lms/djangoapps/staticbook/views.py b/lms/djangoapps/staticbook/views.py index 8e973ac97d..72c72e3154 100644 --- a/lms/djangoapps/staticbook/views.py +++ b/lms/djangoapps/staticbook/views.py @@ -69,7 +69,7 @@ def pdf_index(request, course_id, book_index, chapter=None, page=None): 'staff_access': staff_access}) @login_required -def html_index(request, course_id, book_index, chapter=None, page=None): +def html_index(request, course_id, book_index, chapter=None, anchor_id=None): course = get_course_with_access(request.user, course_id, 'load') staff_access = has_access(request.user, course, 'staff') @@ -99,5 +99,5 @@ def html_index(request, course_id, book_index, chapter=None, page=None): 'course': course, 'textbook': textbook, 'chapter': chapter, - 'page': page, + 'anchor_id': anchor_id, 'staff_access': staff_access}) diff --git a/lms/templates/static_htmlbook.html b/lms/templates/static_htmlbook.html index 2cdec8c109..9500a379ac 100644 --- a/lms/templates/static_htmlbook.html +++ b/lms/templates/static_htmlbook.html @@ -27,35 +27,22 @@ chapterToLoad = options.chapterNum; } var anchorToLoad = null; - - loadUrlAsIframe = function htmlViewLoadUrlAsIframe(url, anchorId) { - if (anchorId != null) { - var newurl = url + "#" + anchorId; - $("#bookpage").src = newurl; - } else { - // $("#bookpage").src = url; - // $("#bookpage").append("") - parentElement = document.getElementById('bookpage'); - while (parentElement.hasChildNodes()) - parentElement.removeChild(parentElement.lastChild); - - $('"') - // .css({'height':'40px','width':'200px'}) - .appendTo('#bookpage'); - } - }; + if (options.chapters) { + anchorToLoad = options.anchor_id; + } loadUrl = function htmlViewLoadUrl(url, anchorId) { - var newurl = url; - if (anchorId != null) { - newurl = url + "#" + anchorId; - } // clear out previous load, if any: parentElement = document.getElementById('bookpage'); while (parentElement.hasChildNodes()) parentElement.removeChild(parentElement.lastChild); + // load new URL in: + $('#bookpage').load(url); - $('#bookpage').load(newurl); + // if there is an anchor set, then go to that location: + if (anchorId != null) { + // TODO: add implementation.... + } }; @@ -105,6 +92,9 @@ %if chapter is not None: options.chapterNum = ${chapter}; %endif + %if anchor_id is not None: + options.anchor_id = ${anchor_id}; + %endif $('#outerContainer').myHTMLViewer(options); }); diff --git a/lms/urls.py b/lms/urls.py index b85bc3d458..3377fa54c0 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -287,7 +287,11 @@ if settings.COURSEWARE_ENABLED: url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/htmlbook/(?P[^/]*)/$', 'staticbook.views.html_index', name="html_book"), - url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/htmlbook/(?P[^/]*)/(?P[^/]*)$', + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/htmlbook/(?P[^/]*)/chapter/(?P[^/]*)/$', + 'staticbook.views.html_index'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/htmlbook/(?P[^/]*)/chapter/(?P[^/]*)/(?P[^/]*)/$', + 'staticbook.views.html_index'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/htmlbook/(?P[^/]*)/(?P[^/]*)/$', 'staticbook.views.html_index'), url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/courseware/?$',