Fix regression in CSS styles and JS toggle

Resolves #4437
This commit is contained in:
Mahmoud Ben Hassine
2023-11-21 12:21:23 +01:00
parent 936563543e
commit 2fe81ce9e0
3 changed files with 39 additions and 117 deletions

View File

@@ -726,16 +726,13 @@ asciidoctor {
options doctype: 'book', eruby: 'erubis'
logDocuments = true
attributes 'docinfo': 'shared',
'backend-html5': true,
// use provided stylesheet
stylesdir: "css/",
stylesheet: 'spring.css',
'linkcss': true,
'icons': 'font',
'sectanchors': '',
// use provided highlighter
'source-highlighter': 'highlight.js',
'highlightjsdir': 'js/highlight',
'highlightjs-theme': 'github',
'sectanchors': '',
'idprefix': '',
'idseparator': '-',
'spring-version': project.version,
@@ -832,8 +829,12 @@ task docsZip(type: Zip) {
from (asciidoctor) {
include "*.html"
include "css/**"
include "fonts/**"
include "footer/**"
include "header/**"
include "js/**"
include "images/**"
include "img/**"
into 'reference/html'
}
}

View File

@@ -1,79 +1,62 @@
$(document).ready(function(){
var BATCH_LANGUAGES = ["java", "xml", "both"];
var $xmlButton = $("#xmlButton");
var $javaButton = $("#javaButton");
var $bothButton = $("#bothButton");
// Make Java the default
setJava();
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);
// 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();
}
if (lang === "java") {
$javaButton.prop("checked", true);
} else if (docToggleCookieString === "java") {
$("#javaButton").prop("checked", true);
setJava();
}
if (lang === "both") {
$javaButton.prop("checked", true);
} else if (docToggleCookieString === "both") {
$("#bothButton").prop("checked", true);
setBoth();
}
}
// Click handlers
$xmlButton.on("click", function() {
$("#xmlButton").on("click", function() {
setXml();
});
$javaButton.on("click", function() {
$("#javaButton").on("click", function() {
setJava();
});
$bothButton.on("click", function() {
$("#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");
$("*.xmlContent").show();
$("*.javaContent").hide();
$("*.javaContent > *").addClass("js-toc-ignore");
$("*.xmlContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
tocbot.refresh();
window.localStorage.setItem('docToggle', 'xml');
}
Cookies.set('docToggle', 'xml', { expires: 3652 });
};
function setJava() {
$javaContent.show();
$xmlContent.hide();
$xmlContentAll.addClass("js-toc-ignore");
$javaContentAll.removeClass("js-toc-ignore");
$("*.javaContent").show();
$("*.xmlContent").hide();
$("*.xmlContent > *").addClass("js-toc-ignore");
$("*.javaContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
tocbot.refresh();
window.localStorage.setItem('docToggle', 'java');
}
Cookies.set('docToggle', 'java', { expires: 3652 });
};
function setBoth() {
$javaContent.show();
$xmlContent.show();
$javaContentAll.removeClass("js-toc-ignore");
$xmlContentAll.removeClass("js-toc-ignore");
$("*.javaContent").show();
$("*.xmlContent").show();
$("*.javaContent > *").removeClass("js-toc-ignore");
$("*.xmlContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
tocbot.refresh();
window.localStorage.setItem('docToggle', 'both');
}
Cookies.set('docToggle', 'both', { expires: 3652 });
};
});

View File

@@ -1,62 +0,0 @@
$(document).ready(function(){
// Make Java the default
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();
$("*.javaContent > *").addClass("js-toc-ignore");
$("*.xmlContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
Cookies.set('docToggle', 'xml', { expires: 3652 });
};
function setJava() {
$("*.javaContent").show();
$("*.xmlContent").hide();
$("*.xmlContent > *").addClass("js-toc-ignore");
$("*.javaContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
Cookies.set('docToggle', 'java', { expires: 3652 });
};
function setBoth() {
$("*.javaContent").show();
$("*.xmlContent").show();
$("*.javaContent > *").removeClass("js-toc-ignore");
$("*.xmlContent > *").removeClass("js-toc-ignore");
window.dispatchEvent(new Event("tocRefresh"));
Cookies.set('docToggle', 'both', { expires: 3652 });
};
});