1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // The rust-book JavaScript in string form.
13 pub static JAVASCRIPT: &'static str = r#"
14 <script type="text/javascript">
15 document.addEventListener("DOMContentLoaded", function(event) {
16 document.getElementById("toggle-nav").onclick = toggleNav;
17 function toggleNav() {
18 var toc = document.getElementById("toc");
19 var pagewrapper = document.getElementById("page-wrapper");
20 toggleClass(toc, "mobile-hidden");
21 toggleClass(pagewrapper, "mobile-hidden");
24 function toggleClass(el, className) {
25 // from http://youmightnotneedjquery.com/
27 el.classList.toggle(className);
29 var classes = el.className.split(' ');
30 var existingIndex = classes.indexOf(className);
32 if (existingIndex >= 0) {
33 classes.splice(existingIndex, 1);
35 classes.push(className);
38 el.className = classes.join(' ');