Files
spring-batch/spring-batch-docs/asciidoc/js/DocumentToggle.js
Drummond Dawson 53ec8f6084 Polish DocumentToggle.js
* Declare duplicate jQuery selectors as variables
* Remove extra semicolons after function declarations
* Remove leftover jquery.js from Java/XML toggle implementation

When the Java/XML toggle implementation was introduced,
jquery-3.2.1.min.js replaced the old jquery script in toggle.adoc
and the old jquery script was accidentally leftover as a result.
2019-11-26 14:15:36 +01:00

75 lines
2.3 KiB
JavaScript

$(document).ready(function(){
var $xmlButton = $("#xmlButton");
var $javaButton = $("#javaButton");
var $bothButton = $("#bothButton");
var $xmlContent = $("*.xmlContent");
var $xmlContentAll = $("*.xmlContent > *");
var $javaContent = $("*.javaContent");
var $javaContentAll = $("*.javaContent > *");
setJava();
// Initial cookie handler. This part remembers the reader's choice and sets the toggle
// accordingly.
var docToggleCookieString = Cookies.get("docToggle");
if (docToggleCookieString != null) {
if (docToggleCookieString === "xml") {
$xmlButton.prop("checked", true);
setXml();
} else if (docToggleCookieString === "java") {
$javaButton.prop("checked", true);
setJava();
} else if (docToggleCookieString === "both") {
$bothButton.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();
Cookies.set('docToggle', 'xml', { expires: 3652 });
}
function setJava() {
$javaContent.show();
$xmlContent.hide();
$xmlContentAll.addClass("js-toc-ignore");
$javaContentAll.removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
tocbot.refresh();
Cookies.set('docToggle', 'java', { expires: 3652 });
}
function setBoth() {
$javaContent.show();
$xmlContent.show();
$javaContentAll.removeClass("js-toc-ignore");
$xmlContentAll.removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
tocbot.refresh();
Cookies.set('docToggle', 'both', { expires: 3652 });
}
});