about summary refs log tree commit diff
path: root/src/rustbook/javascript.rs
diff options
context:
space:
mode:
authorSeth Faxon <seth.faxon@gmail.com>2015-01-12 16:51:31 -0800
committerSeth Faxon <seth.faxon@gmail.com>2015-01-13 09:41:26 -0800
commit9af8a646a964985fe42a91ea34672266c91ae295 (patch)
treea51757aa155dafe7f28be7e5b73b36532c4b5c5d /src/rustbook/javascript.rs
parent3d5fbae33897a8340542f21b6ded913148ca9199 (diff)
downloadrust-9af8a646a964985fe42a91ea34672266c91ae295.tar.gz
rust-9af8a646a964985fe42a91ea34672266c91ae295.zip
Make the Rust Book more mobile friendly
Diffstat (limited to 'src/rustbook/javascript.rs')
-rw-r--r--src/rustbook/javascript.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs
new file mode 100644
index 00000000000..eb4401e1835
--- /dev/null
+++ b/src/rustbook/javascript.rs
@@ -0,0 +1,43 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// The rust-book JavaScript in string form.
+
+pub static JAVASCRIPT: &'static str = r#"
+<script type="text/javascript">
+document.addEventListener("DOMContentLoaded", function(event) {
+  document.getElementById("toggle-nav").onclick = toggleNav;
+  function toggleNav() {
+    var toc = document.getElementById("toc");
+    var pagewrapper = document.getElementById("page-wrapper");
+    toggleClass(toc, "mobile-hidden");
+    toggleClass(pagewrapper, "mobile-hidden");
+  };
+
+  function toggleClass(el, className) {
+     // from http://youmightnotneedjquery.com/
+     if (el.classList) {
+       el.classList.toggle(className);
+     } else {
+       var classes = el.className.split(' ');
+       var existingIndex = classes.indexOf(className);
+
+       if (existingIndex >= 0) {
+         classes.splice(existingIndex, 1);
+       } else {
+         classes.push(className);
+       }
+
+       el.className = classes.join(' ');
+     }
+  }
+});
+</script>
+"#;