|
1 |
| -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 1 | +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT |
2 | 2 | // file at the top-level directory of this distribution and at
|
3 | 3 | // http://rust-lang.org/COPYRIGHT.
|
4 | 4 | //
|
|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
| 11 | +/*jslint browser: true, es5: true */ |
| 12 | +/*globals $: true, rootPath: true */ |
11 | 13 |
|
12 |
| -document.addEventListener("DOMContentLoaded", function(event) { |
| 14 | +document.addEventListener('DOMContentLoaded', function() { |
| 15 | + 'use strict'; |
13 | 16 |
|
14 |
| - document.getElementById("toggle-nav").onclick = toggleNav; |
| 17 | + document.getElementById('toggle-nav').onclick = function(e) { |
| 18 | + var toc = document.getElementById('toc'); |
| 19 | + var pagewrapper = document.getElementById('page-wrapper'); |
| 20 | + toggleClass(toc, 'mobile-hidden'); |
| 21 | + toggleClass(pagewrapper, 'mobile-hidden'); |
| 22 | + }; |
15 | 23 |
|
16 |
| - function toggleNav() { |
17 |
| - var toc = document.getElementById("toc"); |
18 |
| - var pagewrapper = document.getElementById("page-wrapper"); |
19 |
| - toggleClass(toc, "mobile-hidden"); |
20 |
| - toggleClass(pagewrapper, "mobile-hidden"); |
21 |
| - } |
| 24 | + function toggleClass(el, className) { |
| 25 | + // from http://youmightnotneedjquery.com/ |
| 26 | + if (el.classList) { |
| 27 | + el.classList.toggle(className); |
| 28 | + } else { |
| 29 | + var classes = el.className.split(' '); |
| 30 | + var existingIndex = classes.indexOf(className); |
22 | 31 |
|
23 |
| - function toggleClass(el, className) { |
24 |
| - // from http://youmightnotneedjquery.com/ |
25 |
| - if (el.classList) { |
26 |
| - el.classList.toggle(className); |
27 |
| - } else { |
28 |
| - var classes = el.className.split(' '); |
29 |
| - var existingIndex = classes.indexOf(className); |
| 32 | + if (existingIndex >= 0) { |
| 33 | + classes.splice(existingIndex, 1); |
| 34 | + } else { |
| 35 | + classes.push(className); |
| 36 | + } |
30 | 37 |
|
31 |
| - if (existingIndex >= 0) { |
32 |
| - classes.splice(existingIndex, 1); |
33 |
| - } else { |
34 |
| - classes.push(className); |
35 |
| - } |
36 |
| - |
37 |
| - el.className = classes.join(' '); |
38 |
| - } |
39 |
| - } |
| 38 | + el.className = classes.join(' '); |
| 39 | + } |
| 40 | + } |
40 | 41 |
|
41 |
| - // The below code is used to add prev and next navigation links to the bottom |
42 |
| - // of each of the sections. |
43 |
| - // It works by extracting the current page based on the url and iterates over |
44 |
| - // the menu links until it finds the menu item for the current page. We then |
45 |
| - // create a copy of the preceding and following menu links and add the |
46 |
| - // correct css class and insert them into the bottom of the page. |
47 |
| - var toc = document.getElementById('toc').getElementsByTagName('a'); |
48 |
| - var href = document.location.pathname.split('/').pop(); |
49 |
| - if (href === 'index.html' || href === '') { |
50 |
| - href = 'README.html'; |
51 |
| - } |
| 42 | + // The below code is used to add prev and next navigation links to the |
| 43 | + // bottom of each of the sections. |
| 44 | + // It works by extracting the current page based on the url and iterates |
| 45 | + // over the menu links until it finds the menu item for the current page. We |
| 46 | + // then create a copy of the preceding and following menu links and add the |
| 47 | + // correct css class and insert them into the bottom of the page. |
| 48 | + var toc = document.getElementById('toc').getElementsByTagName('a'); |
| 49 | + var href = document.location.pathname.split('/').pop(); |
52 | 50 |
|
53 |
| - for (var i = 0; i < toc.length; i++) { |
54 |
| - if (toc[i].attributes.href.value.split('/').pop() === href) { |
55 |
| - var nav = document.createElement('p'); |
56 |
| - if (i > 0) { |
57 |
| - var prevNode = toc[i-1].cloneNode(true); |
58 |
| - prevNode.className = 'left'; |
59 |
| - prevNode.setAttribute('rel', 'prev'); |
60 |
| - nav.appendChild(prevNode); |
61 |
| - } |
62 |
| - if (i < toc.length - 1) { |
63 |
| - var nextNode = toc[i+1].cloneNode(true); |
64 |
| - nextNode.className = 'right'; |
65 |
| - nextNode.setAttribute('rel', 'next'); |
66 |
| - nav.appendChild(nextNode); |
67 |
| - } |
68 |
| - document.getElementById('page').appendChild(nav); |
69 |
| - break; |
| 51 | + if (href === 'index.html' || href === '') { |
| 52 | + href = 'README.html'; |
70 | 53 | }
|
71 |
| - } |
72 | 54 |
|
| 55 | + for (var i = 0; i < toc.length; i++) { |
| 56 | + if (toc[i].attributes.href.value.split('/').pop() === href) { |
| 57 | + var nav = document.createElement('p'); |
| 58 | + |
| 59 | + if (i > 0) { |
| 60 | + var prevNode = toc[i-1].cloneNode(true); |
| 61 | + prevNode.className = 'left'; |
| 62 | + prevNode.setAttribute('rel', 'prev'); |
| 63 | + nav.appendChild(prevNode); |
| 64 | + } |
| 65 | + |
| 66 | + if (i < toc.length - 1) { |
| 67 | + var nextNode = toc[i+1].cloneNode(true); |
| 68 | + nextNode.className = 'right'; |
| 69 | + nextNode.setAttribute('rel', 'next'); |
| 70 | + nav.appendChild(nextNode); |
| 71 | + } |
| 72 | + |
| 73 | + document.getElementById('page').appendChild(nav); |
| 74 | + |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
73 | 78 | });
|
0 commit comments