|
1 | 1 | $(document).ready(function(){
|
2 | 2 |
|
3 |
| - var BATCH_LANGUAGES = ["java", "xml", "both"]; |
4 |
| - var $xmlButton = $("#xmlButton"); |
5 |
| - var $javaButton = $("#javaButton"); |
6 |
| - var $bothButton = $("#bothButton"); |
7 |
| - |
8 |
| - var $xmlContent = $("*.xmlContent"); |
9 |
| - var $xmlContentAll = $("*.xmlContent > *"); |
10 |
| - |
11 |
| - var $javaContent = $("*.javaContent"); |
12 |
| - var $javaContentAll = $("*.javaContent > *"); |
13 |
| - |
14 |
| - // Initial cookie handler. This part remembers the |
15 |
| - // reader's choice and sets the toggle accordingly. |
16 |
| - var lang = window.localStorage.getItem("docToggle"); |
17 |
| - if (BATCH_LANGUAGES.indexOf(lang) === -1) { |
18 |
| - lang = "java"; |
19 |
| - $javaButton.prop("checked", true); |
20 |
| - setJava(); |
21 |
| - } else { |
22 |
| - if (lang === "xml") { |
23 |
| - $xmlButton.prop("checked", true); |
| 3 | + // Make Java the default |
| 4 | + setJava(); |
| 5 | + |
| 6 | + // Initial cookie handler. This part remembers the reader's choice and sets the toggle |
| 7 | + // accordingly. |
| 8 | + var docToggleCookieString = Cookies.get("docToggle"); |
| 9 | + if (docToggleCookieString != null) { |
| 10 | + if (docToggleCookieString === "xml") { |
| 11 | + $("#xmlButton").prop("checked", true); |
24 | 12 | setXml();
|
25 |
| - } |
26 |
| - if (lang === "java") { |
27 |
| - $javaButton.prop("checked", true); |
| 13 | + } else if (docToggleCookieString === "java") { |
| 14 | + $("#javaButton").prop("checked", true); |
28 | 15 | setJava();
|
29 |
| - } |
30 |
| - if (lang === "both") { |
31 |
| - $javaButton.prop("checked", true); |
| 16 | + } else if (docToggleCookieString === "both") { |
| 17 | + $("#bothButton").prop("checked", true); |
32 | 18 | setBoth();
|
33 | 19 | }
|
34 | 20 | }
|
35 | 21 |
|
36 | 22 | // Click handlers
|
37 |
| - $xmlButton.on("click", function() { |
| 23 | + $("#xmlButton").on("click", function() { |
38 | 24 | setXml();
|
39 | 25 | });
|
40 |
| - $javaButton.on("click", function() { |
| 26 | + $("#javaButton").on("click", function() { |
41 | 27 | setJava();
|
42 | 28 | });
|
43 |
| - $bothButton.on("click", function() { |
| 29 | + $("#bothButton").on("click", function() { |
44 | 30 | setBoth();
|
45 | 31 | });
|
46 | 32 |
|
47 | 33 | // Functions to do the work of handling the reader's choice, whether through a click
|
48 | 34 | // or through a cookie. 3652 days is 10 years, give or take a leap day.
|
49 | 35 | function setXml() {
|
50 |
| - $xmlContent.show(); |
51 |
| - $javaContent.hide(); |
52 |
| - $javaContentAll.addClass("js-toc-ignore"); |
53 |
| - $xmlContentAll.removeClass("js-toc-ignore"); |
| 36 | + $("*.xmlContent").show(); |
| 37 | + $("*.javaContent").hide(); |
| 38 | + $("*.javaContent > *").addClass("js-toc-ignore"); |
| 39 | + $("*.xmlContent > *").removeClass("js-toc-ignore"); |
54 | 40 | window.dispatchEvent(new Event("tocRefresh"));
|
55 |
| - tocbot.refresh(); |
56 |
| - window.localStorage.setItem('docToggle', 'xml'); |
57 |
| - } |
| 41 | + Cookies.set('docToggle', 'xml', { expires: 3652 }); |
| 42 | + }; |
58 | 43 |
|
59 | 44 | function setJava() {
|
60 |
| - $javaContent.show(); |
61 |
| - $xmlContent.hide(); |
62 |
| - $xmlContentAll.addClass("js-toc-ignore"); |
63 |
| - $javaContentAll.removeClass("js-toc-ignore"); |
| 45 | + $("*.javaContent").show(); |
| 46 | + $("*.xmlContent").hide(); |
| 47 | + $("*.xmlContent > *").addClass("js-toc-ignore"); |
| 48 | + $("*.javaContent > *").removeClass("js-toc-ignore"); |
64 | 49 | window.dispatchEvent(new Event("tocRefresh"));
|
65 |
| - tocbot.refresh(); |
66 |
| - window.localStorage.setItem('docToggle', 'java'); |
67 |
| - } |
| 50 | + Cookies.set('docToggle', 'java', { expires: 3652 }); |
| 51 | + }; |
68 | 52 |
|
69 | 53 | function setBoth() {
|
70 |
| - $javaContent.show(); |
71 |
| - $xmlContent.show(); |
72 |
| - $javaContentAll.removeClass("js-toc-ignore"); |
73 |
| - $xmlContentAll.removeClass("js-toc-ignore"); |
| 54 | + $("*.javaContent").show(); |
| 55 | + $("*.xmlContent").show(); |
| 56 | + $("*.javaContent > *").removeClass("js-toc-ignore"); |
| 57 | + $("*.xmlContent > *").removeClass("js-toc-ignore"); |
74 | 58 | window.dispatchEvent(new Event("tocRefresh"));
|
75 |
| - tocbot.refresh(); |
76 |
| - window.localStorage.setItem('docToggle', 'both'); |
77 |
| - } |
| 59 | + Cookies.set('docToggle', 'both', { expires: 3652 }); |
| 60 | + }; |
78 | 61 |
|
79 | 62 | });
|
0 commit comments