about summary refs log tree commit diff
path: root/src/rustbook/javascript.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-31 03:57:01 +0000
committerbors <bors@rust-lang.org>2015-01-31 03:57:01 +0000
commit474b324eda10440d6568ef872a7307d38e7de95b (patch)
tree53fc5aaa615f1c6e5abd757e42a75b3d19ce3abb /src/rustbook/javascript.rs
parent1d00c545ede609b9d43fdf9f252c15da5a66dac7 (diff)
parente8fd9d3d0bf0f4974460337df29c0d3ceb514987 (diff)
downloadrust-474b324eda10440d6568ef872a7307d38e7de95b.tar.gz
rust-474b324eda10440d6568ef872a7307d38e7de95b.zip
Auto merge of #21791 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/rustbook/javascript.rs')
-rw-r--r--src/rustbook/javascript.rs31
1 files changed, 31 insertions, 0 deletions
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>
 "#;