@@ -176,6 +176,7 @@ $(function() {
176176
177177 var $parentDiv = $ ( '.tabs-content' ) ;
178178 $parentDiv . animate ( { scrollTop : 0 } ) ;
179+ genPrevNextLevelNN ( ) ;
179180 } ) ;
180181
181182 // and this one for the left sub sub navs.
@@ -230,16 +231,52 @@ $(function() {
230231
231232
232233 function genPrevNextLevelN ( ) {
233- console . log ( 'genprevnext' ) ;
234+ console . log ( 'genprevnext level 1 ' ) ;
234235 var nextsection = $ ( '.content.visible' ) . next ( )
235236 var nextsectionid = nextsection . attr ( 'internal-destination' ) ;
236237 var nextsectiontitle = nextsection . find ( '.section-title' ) . text ( ) ;
237- $ ( '.content.visible .prevnextnav .next .nexttext' ) . text ( nextsectiontitle ) ;
238+ if ( ! nextsectionid ) {
239+ $ ( '.content.visible .prevnextnav .next .nexttext' ) . text ( '' ) ;
240+ } else {
241+ $ ( '.content.visible .prevnextnav .next .nexttext' ) . text ( nextsectiontitle ) ;
242+ }
238243
239244 var prevsection = $ ( '.content.visible' ) . prev ( )
240245 var prevsectionid = prevsection . attr ( 'internal-destination' ) ;
241246 var prevsectiontitle = prevsection . find ( '.section-title' ) . text ( ) ;
242- $ ( '.content.visible .prevnextnav .prev .prevtext' ) . text ( prevsectiontitle ) ;
247+ if ( ! prevsectionid ) {
248+ $ ( '.content.visible .prevnextnav .prev .prevtext' ) . text ( '' ) ;
249+ } else {
250+ $ ( '.content.visible .prevnextnav .prev .prevtext' ) . text ( prevsectiontitle ) ;
251+ }
252+ }
253+
254+ function genPrevNextLevelNN ( ) {
255+ console . log ( 'genprevnext level 2' ) ;
256+ var nextchapter = $ ( '.chapters.visible' ) . next ( )
257+ var nextchapterid = nextchapter . attr ( 'internal-destination' ) ;
258+ var nextchaptertitle = nextchapter . find ( 'h3:first' ) . text ( ) ;
259+ if ( ! nextchapterid ) {
260+ // check for next section since we are at last chapter
261+ var nextsection = $ ( '.content.visible' ) . next ( )
262+ var nextsectionid = nextsection . attr ( 'internal-destination' ) ;
263+ var nextsectiontitle = nextsection . find ( '.section-title' ) . text ( ) ;
264+ $ ( '.content.visible .prevnextnav .next .nexttext' ) . text ( nextsectiontitle ) ;
265+ } else {
266+ $ ( '.content.visible .prevnextnav .next .nexttext' ) . text ( nextchaptertitle ) ;
267+ }
268+
269+ var prevchapter = $ ( '.chapters.visible' ) . prev ( )
270+ var prevchapterid = prevchapter . attr ( 'internal-destination' ) ;
271+ var prevchaptertitle = prevchapter . find ( 'h3:first' ) . text ( ) ;
272+ if ( ! prevchapterid ) {
273+ var prevsection = $ ( '.content.visible' ) . prev ( )
274+ var prevsectionid = prevsection . attr ( 'internal-destination' ) ;
275+ var prevsectiontitle = prevsection . find ( '.section-title' ) . text ( ) ;
276+ $ ( '.content.visible .prevnextnav .prev .prevtext' ) . text ( prevsectiontitle ) ;
277+ } else {
278+ $ ( '.content.visible .prevnextnav .prev .prevtext' ) . text ( prevchaptertitle ) ;
279+ }
243280 }
244281
245282
@@ -248,6 +285,9 @@ $(function() {
248285 // search querystring for error param value
249286 var matches = window . location . search . match ( / x r e f = ( [ \w . ] + ) / ) ;
250287
288+
289+ genPrevNextLevelN ( ) ;
290+
251291 if ( matches ) {
252292 // show the matching element
253293
@@ -278,6 +318,7 @@ $(function() {
278318
279319 $ ( '.tabs-nav nav.top-nav[internal-destination="' + id + '"]' ) . addClass ( 'selected' ) ;
280320 $ ( '.tabs-nav nav.top-nav[internal-destination="' + id + '"] > a' ) . addClass ( 'selected' ) ;
321+ genPrevNextLevelN ( ) ;
281322 }
282323 if ( levels >= 2 ) {
283324
@@ -305,6 +346,7 @@ $(function() {
305346
306347 $ ( '.tabs-nav nav.sub-nav[internal-destination="' + id + '"]' ) . addClass ( 'selected' ) ;
307348 $ ( '.tabs-nav nav.sub-nav[internal-destination="' + id + '"] > a' ) . addClass ( 'selected' ) ;
349+ genPrevNextLevelNN ( ) ;
308350 }
309351 if ( levels >= 3 ) {
310352 id = 'sec' + parts [ 0 ] + '.' + parts [ 1 ] + '.' + parts [ 2 ] ;
0 commit comments