Commit 49dee508 by Brian Wilson

first pass at chapter navigation

parent aee7d856
<%inherit file="main.html" /> <%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<%block name="title"> <%block name="title"><title>${course.number} Textbook</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>${course.number} Textbook</title>
</%block> </%block>
<%block name="headextra"> <%block name="headextra">
...@@ -13,6 +10,85 @@ ...@@ -13,6 +10,85 @@
<%block name="js_extra"> <%block name="js_extra">
<script type="text/javascript"> <script type="text/javascript">
(function($) {
$.fn.myHTMLViewer = function(options) {
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 anchorToLoad = null;
loadUrlAsIframe = function htmlViewLoadUrlAsIframe(url, anchorId) {
if (anchorId != null) {
var newurl = url + "#" + anchorId;
$("#bookpage").src = newurl;
} else {
// $("#bookpage").src = url;
// $("#bookpage").append("<iframe seamless id="bookpage-iframe" src=" + url + "\"></iframe>")
parentElement = document.getElementById('bookpage');
while (parentElement.hasChildNodes())
parentElement.removeChild(parentElement.lastChild);
$('<iframe id="bookpage-iframe" src="' + url + '"></iframe>"')
// .css({'height':'40px','width':'200px'})
.appendTo('#bookpage');
}
};
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);
$('#bookpage').load(newurl);
};
loadChapterUrl = function htmlViewLoadChapterUrl(chapterNum, anchorId) {
if (chapterNum < 1 || chapterNum > chapterUrls.length) {
return;
}
var chapterUrl = chapterUrls[chapterNum-1];
loadUrl(chapterUrl, anchorId);
};
// define navigation links for chapters:
if (chapterUrls != null) {
var loadChapterUrlHelper = function(i) {
return function(event) {
// when opening a new chapter, always open to the top:
loadChapterUrl(i, null);
};
};
for (var index = 1; index <= chapterUrls.length; index += 1) {
$("#htmlchapter-" + index).click(loadChapterUrlHelper(index));
}
}
// finally, load the appropriate url/page
if (urlToLoad != null) {
loadUrl(urlToLoad, anchorToLoad);
} else {
loadChapterUrl(chapterToLoad, anchorToLoad);
}
}
})(jQuery);
$(document).ready(function() { $(document).ready(function() {
var options = {}; var options = {};
...@@ -29,10 +105,8 @@ ...@@ -29,10 +105,8 @@
%if chapter is not None: %if chapter is not None:
options.chapterNum = ${chapter}; options.chapterNum = ${chapter};
%endif %endif
%if page is not None:
options.pageNum = ${page};
%endif
$('#outerContainer').myHTMLViewer(options);
}); });
</script> </script>
</%block> </%block>
...@@ -43,29 +117,29 @@ ...@@ -43,29 +117,29 @@
<div id="mainContainer" class="book-wrapper"> <div id="mainContainer" class="book-wrapper">
%if 'chapters' in textbook: %if 'chapters' in textbook:
<section aria-label="Textbook Navigation" class="book-sidebar"> <section aria-label="Textbook Navigation" class="book-sidebar">
<ul id="booknav" class="treeview-booknav"> <ul id="booknav" class="treeview-booknav">
<%def name="print_entry(entry, index_value)"> <%def name="print_entry(entry, index_value)">
<li id="htmlchapter-${index_value}"> <li id="htmlchapter-${index_value}">
<a class="chapter"> <a class="chapter">
${entry.get('title')} ${entry.get('title')}
</a> </a>
</li> </li>
</%def> </%def>
% for (index, entry) in enumerate(textbook['chapters']): %for (index, entry) in enumerate(textbook['chapters']):
${print_entry(entry, index+1)} ${print_entry(entry, index+1)}
% endfor % endfor
</ul> </ul>
</section> </section>
%endif %endif
<section id="viewerContainer" class="book"> <section id="viewerContainer" class="book">
<!-- <section class="page"> --> <section class="page">
<iframe class="page" id="bookpage" src="${ textbook['chapters'][0]['url'] }"> <div id="bookpage" />
<!-- </section> --> </section>
</section> </section>
</div> <!-- mainContainer --> </div>
</div>
</div> <!-- outerContainer -->
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