static_htmlbook.html 4.07 KB
Newer Older
Brian Wilson committed
1 2
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
3
<%block name="title"><title>${course.number} Textbook</title>
Brian Wilson committed
4 5 6 7 8 9 10 11 12
</%block>

<%block name="headextra">
<%static:css group='course'/>
<%static:js group='courseware'/>
</%block>

<%block name="js_extra">
  <script type="text/javascript">
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(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;
30 31 32
        if (options.chapters) {
            anchorToLoad = options.anchor_id;
        }
33 34 35 36 37 38

        loadUrl = function htmlViewLoadUrl(url, anchorId) {
            // clear out previous load, if any:
            parentElement = document.getElementById('bookpage');
            while (parentElement.hasChildNodes())
                parentElement.removeChild(parentElement.lastChild);
39 40
	    // load new URL in:
            $('#bookpage').load(url);
41

42 43 44 45
	    // if there is an anchor set, then go to that location:
            if (anchorId != null) {
		// TODO: add implementation....
            } 
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

        }; 

        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);
Brian Wilson committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

    $(document).ready(function() {
        var options = {};
        %if 'url' in textbook:
            options.url = "${textbook['url']}";
        %endif
        %if 'chapters' in textbook:
            var chptrs = [];
            %for chap in textbook['chapters']:
                chptrs.push("${chap['url']}");
            %endfor
            options.chapters = chptrs;
        %endif
        %if chapter is not None:
            options.chapterNum = ${chapter};
        %endif
95 96 97
        %if anchor_id is not None:
            options.anchor_id = ${anchor_id};
        %endif
Brian Wilson committed
98

99
        $('#outerContainer').myHTMLViewer(options);
Brian Wilson committed
100 101 102 103 104 105 106 107 108 109
    });
  </script>  
</%block>

<%include file="/courseware/course_navigation.html" args="active_page='htmltextbook/{0}'.format(book_index)" />

    <div id="outerContainer">
      <div id="mainContainer" class="book-wrapper">

        %if 'chapters' in textbook:
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        <section aria-label="Textbook Navigation" class="book-sidebar">
          <ul id="booknav" class="treeview-booknav">
            <%def name="print_entry(entry, index_value)">
              <li id="htmlchapter-${index_value}">
                <a class="chapter">
                  ${entry.get('title')}
                </a>
              </li>
            </%def>

            %for (index, entry) in enumerate(textbook['chapters']):
              ${print_entry(entry, index+1)}
            % endfor
          </ul>
        </section>
Brian Wilson committed
125 126 127
        %endif

        <section id="viewerContainer" class="book">
128 129 130
          <section class="page"> 
            <div id="bookpage" />
          </section> 
Brian Wilson committed
131 132
        </section>

133 134
      </div>
    </div>
Brian Wilson committed
135