3232//
3333// Page decoration functions
3434//
35+ /*
36+ Maybe something like this at the top:
37+
38+ Active assignment: [Ch 15 reading] [Exit assignment link]
39+ On page (3 of 7) [Select input showing current page, can select others]
40+ Becoming this if not on a page in assignment
3541
42+ Active assignment: [Ch 15 reading] [Exit assignment link]
43+ This page is not part of that assignment. Select a page to return to it:
44+ [Select input]
45+ */
3646function addReadingList ( ) {
37- if ( eBookConfig . readings ) {
38- var l , nxt , path_parts , nxt_link ;
47+ let assignment_info_string = localStorage . getItem ( "currentAssignmentInfo" )
48+
49+ if ( assignment_info_string && eBookConfig . readings ) {
50+ var top , bottom , active , page_name , exit_link , fst , snd , new_pos , path_parts , new_pos_link ;
51+ let assignment_info = JSON . parse ( assignment_info_string ) ;
52+ let assignment_id = assignment_info . id ;
53+ let assignment_name = assignment_info . name ;
54+ let reading_names = assignment_info . readingNames ;
55+
56+ active = document . createElement ( "div" ) ;
57+ active . textContent = "Active assignment: "
58+
59+ page_name = document . createElement ( "a" ) ;
60+ page_name . textContent = assignment_name ;
61+ page_name . href = `/assignment/student/doAssignment?assignment_id=${ assignment_id } ` ;
62+
63+ active . append ( page_name ) ;
64+
65+ exit_link = document . createElement ( "a" ) ;
66+ exit_link . textContent = "Exit Assignment" ;
67+ exit_link . href = window . location . pathname ;
68+
69+ exit_link . addEventListener ( 'click' , function ( event ) {
70+ localStorage . removeItem ( "currentAssignmentInfo" ) ;
71+ } ) ;
72+
73+ //active.append(exit_link)
74+
3975 let cur_path_parts = window . location . pathname . split ( "/" ) ;
4076 let name =
4177 cur_path_parts [ cur_path_parts . length - 2 ] +
@@ -54,42 +90,118 @@ function addReadingList() {
5490
5591 let position = eBookConfig . readings . indexOf ( name ) ;
5692 let num_readings = eBookConfig . readings . length ;
93+ // get prev name
94+ if ( position > 0 ) {
95+ new_pos = eBookConfig . readings [ position - 1 ] ;
96+ path_parts = cur_path_parts . slice ( 0 , cur_path_parts . length - endLop ) ;
97+ path_parts . push ( new_pos ) ;
98+ new_pos_link = path_parts . join ( "/" ) ;
99+ fst = active . cloneNode ( true ) ;
100+ let txt = document . createElement ( "p" ) ;
101+ txt . textContent = `Page ${ position + 1 } of ${ num_readings } , ` ;
102+ var fst_lnk = document . createElement ( "a" ) ;
103+ //fst_lnk.className = "btn btn-lg reading-navigation prev-reading";
104+ fst_lnk . href = new_pos_link ;
105+ fst_lnk . textContent = `Back to page ${
106+ position
107+ } of ${ num_readings } : ${ reading_names [ position - 1 ] } .`;
108+ txt . append ( fst_lnk ) ;
109+ fst . append ( txt ) ;
110+
111+ } else if ( position == 0 ) {
112+ fst = active . cloneNode ( true ) ;
113+ let txt = document . createElement ( "p" ) ;
114+ txt . textContent = `Page 1 of ${ num_readings } .` ;
115+ fst . append ( txt ) ;
116+ } else {
117+ new_pos = eBookConfig . readings [ 0 ] ;
118+ path_parts = cur_path_parts . slice ( 0 , cur_path_parts . length - endLop ) ;
119+ path_parts . push ( new_pos ) ;
120+ new_pos_link = path_parts . join ( "/" ) ;
121+ fst = active . cloneNode ( true ) ;
122+ let txt = document . createElement ( "p" ) ;
123+ txt . textContent = "Notice: this page is not part of the assignment. To remove this warning click " ;
124+ txt . append ( exit_link ) ;
125+ fst . append ( txt ) ;
126+ }
57127 if ( position == eBookConfig . readings . length - 1 ) {
58128 // no more readings
59- l = document . createElement ( "div" ) ;
60- l . textContent = `Finished reading assignment. Page ${ num_readings } of ${ num_readings } .` ;
129+ snd = active ;
130+ let txt = document . createElement ( "p" ) ;
131+ txt . textContent = `Page ${ num_readings } of ${ num_readings } : ${ reading_names [ position ] } ` ;
132+ snd . append ( txt ) ;
61133 } else if ( position >= 0 ) {
62134 // get next name
63- nxt = eBookConfig . readings [ position + 1 ] ;
135+ new_pos = eBookConfig . readings [ position + 1 ] ;
64136 path_parts = cur_path_parts . slice ( 0 , cur_path_parts . length - endLop ) ;
65- path_parts . push ( nxt ) ;
66- nxt_link = path_parts . join ( "/" ) ;
67- l = document . createElement ( "a" ) ;
68- l . name = "link" ;
69- l . className = "btn btn-lg reading-navigation next-reading" ;
70- l . href = nxt_link ;
71- l . textContent = `Continue to page ${
137+ path_parts . push ( new_pos ) ;
138+ new_pos_link = path_parts . join ( "/" ) ;
139+ snd = active ;
140+ var snd_lnk = document . createElement ( "a" ) ;
141+ //snd_lnk .className = "btn btn-lg reading-navigation next-reading";
142+ snd_lnk . href = new_pos_link ;
143+ snd_lnk . textContent = `Continue to page ${
72144 position + 2
73- } of ${ num_readings } in the reading assignment.`;
145+ } of ${ num_readings } : ${ reading_names [ position + 1 ] } `;
146+ let txt = document . createElement ( "p" ) ;
147+ txt . append ( snd_lnk ) ;
148+ snd . append ( txt ) ;
149+
74150 } else {
75- l = document . createElement ( "div" ) ;
76- l . className = "reading-navigation no-assignment" ;
77- l . textContent =
78- "This page is not part of the last reading assignment you visited." ;
151+ snd = active . cloneNode ( true ) ;
152+ let txt = document . createElement ( "p" ) ;
153+ txt . textContent = "Notice: this page is not part of the assignment. To remove this warning click " ;
154+ let exit_clone = exit_link . cloneNode ( true ) ;
155+
156+ exit_clone . addEventListener ( 'click' , function ( event ) {
157+ localStorage . removeItem ( "currentAssignmentInfo" ) ;
158+ } ) ;
159+ txt . append ( exit_clone ) ;
160+ snd . append ( txt ) ;
161+
162+
79163 }
164+
165+ top = document . createElement ( "div" ) ;
166+ top . className = "ptx-runestone-container"
167+ fst . className = "runestone assignment-nav top-assignment-nav"
168+ //top.style.backgroundColor = "var(--componentBgColor)"
169+ //top.style.borderColor = "var(--componentBorderColor)"
170+ //top.style.borderWidth = "1px"
171+ top . append ( fst ) ;
172+ //top.append(snd);
173+
174+ bottom = document . createElement ( "div" ) ;
175+ bottom . className = "ptx-runestone-container"
176+ snd . className = "runestone assignment-nav bottom-assignment-nav"
177+ //bottom.style.backgroundColor = "var(--componentBgColor)"
178+ //bottom.style.borderColor = "var(--componentBorderColor)"
179+ //bottom.style.borderWidth = "1px"
180+
181+ //bottom.append(active.cloneNode(true));
182+ //bottom.append(fst.cloneNode(true));
183+ bottom . append ( snd ) ;
184+
185+
80186 // check the body tag to see if it has a pretext class (no jquery)
81187 if ( ptxbook ) {
82- //append l to the body
188+ //append parts to the header and progress container
189+ let content = document . getElementById ( "ptx-content" ) ;
190+ if ( content ) {
191+ content . insertBefore ( top , content . firstChild ) ;
192+ }
83193 let pc = document . getElementById ( "scprogresscontainer" ) ;
84194 if ( pc ) {
85195 pc . style . marginBottom = "20px" ;
86- pc . appendChild ( l ) ;
196+ pc . appendChild ( bottom ) ;
87197 }
88198 return ;
89199 }
90200 const mainContent = document . getElementById ( "main-content" ) ;
91- if ( mainContent && l ) {
92- mainContent . appendChild ( l ) ;
201+ if ( mainContent && snd ) {
202+ mainContent . insertBefore ( top , mainContent . firstChild )
203+ mainContent . appendChild ( bottom ) ;
204+
93205 }
94206 }
95207}
0 commit comments