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