From 2fe81ce9e0754ce7cda4ee2fde9a3dfe1ebd51e9 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Tue, 21 Nov 2023 12:21:23 +0100 Subject: [PATCH] Fix regression in CSS styles and JS toggle Resolves #4437 --- build.gradle | 11 +-- .../asciidoc/js/DocumentToggle.js | 83 ++++++++----------- .../asciidoc/jsfiles/DocumentToggle.js | 62 -------------- 3 files changed, 39 insertions(+), 117 deletions(-) delete mode 100644 spring-batch-docs/asciidoc/jsfiles/DocumentToggle.js diff --git a/build.gradle b/build.gradle index 2c80357c2..a61fb985c 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } diff --git a/spring-batch-docs/asciidoc/js/DocumentToggle.js b/spring-batch-docs/asciidoc/js/DocumentToggle.js index ca720afbe..9402920d8 100644 --- a/spring-batch-docs/asciidoc/js/DocumentToggle.js +++ b/spring-batch-docs/asciidoc/js/DocumentToggle.js @@ -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 }); + }; }); diff --git a/spring-batch-docs/asciidoc/jsfiles/DocumentToggle.js b/spring-batch-docs/asciidoc/jsfiles/DocumentToggle.js deleted file mode 100644 index 9402920d8..000000000 --- a/spring-batch-docs/asciidoc/jsfiles/DocumentToggle.js +++ /dev/null @@ -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 }); - }; - -});