From 02e90a8645d34389d737718d72573947110e681a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 7 Feb 2020 11:16:02 +0000 Subject: [PATCH] Upgrade to Spring Asciidoctor Extensions 0.4.0.RELEASE 0.4.0 provides built-in support for remembering a user's selections using local storage. This replaces the custom switch language JavaScript. The selection is stored using a key derived from the options that were available. Concretely, when the options are Java or Kotlin, the local storage key is java-kotlin. Similarly, if the choices were Java, Kotlin, and XML, the key would be java-kotlin-xml. Given local storage's domain and protocol scoping, the nature of the key that's used for storage will allow a user's selections to be applied across all documentation hosted on https://docs.spring.io that offer the same options. Closes gh-24481 --- gradle/docs.gradle | 11 ++++++- src/docs/asciidoc/docinfo-footer.html | 1 - src/docs/asciidoc/js/switch-language.js | 43 ------------------------- 3 files changed, 10 insertions(+), 45 deletions(-) delete mode 100644 src/docs/asciidoc/js/switch-language.js diff --git a/gradle/docs.gradle b/gradle/docs.gradle index 1772212c50..e0be846ea4 100644 --- a/gradle/docs.gradle +++ b/gradle/docs.gradle @@ -3,7 +3,16 @@ configurations { } dependencies { - asciidoctorExt("io.spring.asciidoctor:spring-asciidoctor-extensions:0.2.0.RELEASE") + asciidoctorExt("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.4.0.RELEASE") +} + +repositories { + maven { + url "https://repo.spring.io/release" + mavenContent { + group "io.spring.asciidoctor" + } + } } /** diff --git a/src/docs/asciidoc/docinfo-footer.html b/src/docs/asciidoc/docinfo-footer.html index dad243ed6f..a7a58d584a 100644 --- a/src/docs/asciidoc/docinfo-footer.html +++ b/src/docs/asciidoc/docinfo-footer.html @@ -1,3 +1,2 @@ - \ No newline at end of file diff --git a/src/docs/asciidoc/js/switch-language.js b/src/docs/asciidoc/js/switch-language.js deleted file mode 100644 index c3ba7a8560..0000000000 --- a/src/docs/asciidoc/js/switch-language.js +++ /dev/null @@ -1,43 +0,0 @@ -function globalSwitch() { - - var SPRING_LANGUAGES = ["Java", "Kotlin"]; - var preferredLanguage = initPreferredLanguage(); - - function initPreferredLanguage() { - var lang = window.localStorage.getItem("preferred-spring-language"); - if (SPRING_LANGUAGES.indexOf(lang) === -1) { - window.localStorage.setItem("preferred-spring-language", SPRING_LANGUAGES[0]); - lang = SPRING_LANGUAGES[0]; - } - return lang; - } - - function switchItem(text, index) { - if (SPRING_LANGUAGES.indexOf(text) !== -1) { - window.localStorage.setItem("preferred-spring-language", text); - } - $(".switch--item").filter(function() { return ($(this).text() === text) }).each(function() { - $(this).addClass('selected'); - $(this).siblings().removeClass('selected'); - var selectedContent = $(this).parent().siblings(".content").eq(index) - selectedContent.removeClass('hidden'); - selectedContent.siblings().addClass('hidden'); - }); - } - - $('.switch--item').each(function() { - $(this).off('click'); - $(this).on('click', function() { - var selectedText = $(this).text() - var selectedIndex = $(this).index() - switchItem(selectedText, selectedIndex); - }); - }); - - var languageIndex = SPRING_LANGUAGES.indexOf(preferredLanguage); - if (languageIndex != 0) { - switchItem(preferredLanguage, languageIndex); - } -} - -$(globalSwitch); \ No newline at end of file