diff options
| author | jatinn <jatinn@users.noreply.github.com> | 2015-01-21 21:53:43 -0500 |
|---|---|---|
| committer | jatinn <jatinn@users.noreply.github.com> | 2015-01-22 23:11:14 -0500 |
| commit | e371d23486a5b42f41cd220ebef1689d49e3fe94 (patch) | |
| tree | d708be5559e07a790961eb2fdc01b9193edcd7f2 | |
| parent | 6869645e86c91544b8737b89809bdf10bef536d9 (diff) | |
| download | rust-e371d23486a5b42f41cd220ebef1689d49e3fe94.tar.gz rust-e371d23486a5b42f41cd220ebef1689d49e3fe94.zip | |
add next/prev section links in the book -- using js
| -rw-r--r-- | src/rustbook/css.rs | 9 | ||||
| -rw-r--r-- | src/rustbook/javascript.rs | 31 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs index 65ba031a2d6..74219bc9bfc 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/css.rs @@ -46,6 +46,7 @@ body { margin-left: auto; margin-right:auto; max-width: 750px; + padding-bottom: 50px; } .chapter { @@ -123,4 +124,12 @@ body { padding: 0; } +.left { + float: left; +} + +.right { + float: right; +} + "#; diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs index eb4401e1835..d34887d2b08 100644 --- a/src/rustbook/javascript.rs +++ b/src/rustbook/javascript.rs @@ -38,6 +38,37 @@ document.addEventListener("DOMContentLoaded", function(event) { el.className = classes.join(' '); } } + + // The below code is used to add prev and next navigation links to the bottom + // of each of the sections. + // It works by extracting the current page based on the url and iterates over + // the menu links until it finds the menu item for the current page. We then + // create a copy of the preceeding and following menu links and add the + // correct css class and insert them into the bottom of the page. + var toc = document.getElementById('toc').getElementsByTagName('a'); + var href = document.location.pathname.split('/').pop(); + if (href === 'index.html' || href === '') { + href = 'README.html'; + } + + for (var i = 0; i < toc.length; i++) { + if (toc[i].attributes['href'].value === href) { + var nav = document.createElement('p'); + if (i > 0) { + var prevNode = toc[i-1].cloneNode(true); + prevNode.className = 'left'; + nav.appendChild(prevNode); + } + if (i < toc.length - 1) { + var nextNode = toc[i+1].cloneNode(true); + nextNode.className = 'right'; + nav.appendChild(nextNode); + } + document.getElementById('page').appendChild(nav); + break; + } + } + }); </script> "#; |
