static_htmlbook.html 5.07 KB
Newer Older
1 2
<%! from django.utils.translation import ugettext as _ %>

Brian Wilson committed
3 4
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
5
<%block name="pagetitle">${_('{course_number} Textbook').format(course_number=course.display_number_with_default) | h}</%block>
Brian Wilson committed
6 7

<%block name="headextra">
8 9
<%static:css group='style-course-vendor'/>
<%static:css group='style-course'/>
Brian Wilson committed
10 11 12 13
<%static:js group='courseware'/>
</%block>

<%block name="js_extra">
14 15
  <script type="text/javascript" src="${static.url('js/vendor/tinymce/js/tinymce/tinymce.full.min.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/tinymce/js/tinymce/jquery.tinymce.min.js')}"></script>
Brian Wilson committed
16
  <script type="text/javascript">
17 18 19 20 21 22 23 24 25 26 27 28
(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) {
29
            // TODO: this should only be specified if there are
30 31 32 33
            // chapters, and it should be in-bounds.
            chapterToLoad = options.chapterNum;
        }
        var anchorToLoad = null;
34 35 36
        if (options.chapters) {
            anchorToLoad = options.anchor_id;
        }
37

38 39 40 41
        var onComplete = function() {};
        if(options.notesEnabled) {
            onComplete = function(url) {
                return function() {
42
                    $('#viewerContainer').trigger('notes:init', [url, "${storage}", "${token}"]);
43 44 45
                }
            };
        }
Arthur Barrett committed
46

47 48 49 50 51
        loadUrl = function htmlViewLoadUrl(url, anchorId) {
            // clear out previous load, if any:
            parentElement = document.getElementById('bookpage');
            while (parentElement.hasChildNodes())
                parentElement.removeChild(parentElement.lastChild);
52
	    // load new URL in:
Arthur Barrett committed
53
            $('#bookpage').load(url, null, onComplete(url));
54

55 56 57
	    // if there is an anchor set, then go to that location:
            if (anchorId != null) {
		// TODO: add implementation....
58
            }
59

60
        };
61 62 63 64 65 66 67 68 69

        loadChapterUrl = function htmlViewLoadChapterUrl(chapterNum, anchorId) {
            if (chapterNum < 1 || chapterNum > chapterUrls.length) {
                return;
            }
            var chapterUrl = chapterUrls[chapterNum-1];
            loadUrl(chapterUrl, anchorId);
        };

70
        // define navigation links for chapters:
71 72 73 74 75 76 77 78 79
        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));
80
            }
81 82 83 84 85 86 87
        }

        // finally, load the appropriate url/page
        if (urlToLoad != null) {
            loadUrl(urlToLoad, anchorToLoad);
        } else {
            loadChapterUrl(chapterToLoad, anchorToLoad);
88
        }
89 90 91

    }
})(jQuery);
Brian Wilson committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    $(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
108
        %if anchor_id is not UNDEFINED and anchor_id is not None:
109 110
            options.anchor_id = ${anchor_id};
        %endif
Brian Wilson committed
111

112 113 114 115 116
        options.notesEnabled = false;
        %if notes_enabled is not UNDEFINED and notes_enabled:
            options.notesEnabled = true;
        %endif

117
        $('#outerContainer').myHTMLViewer(options);
Brian Wilson committed
118
    });
119
  </script>
Brian Wilson committed
120 121 122 123 124 125 126 127
</%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:
128
        <section aria-label="${_('Textbook Navigation')}" class="book-sidebar">
129 130 131 132 133 134 135 136 137 138 139 140 141 142
          <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
143 144 145
        %endif

        <section id="viewerContainer" class="book">
146
          <section class="page">
147
            <div id="bookpage" />
148
          </section>
Brian Wilson committed
149
        </section>
daniel cebrian committed
150 151
		<span class="idU" style="display:none">${student.id}</span>
		<span class="idDU" style="display:none">${student.username}</span>
152 153
      </div>
    </div>
Brian Wilson committed
154