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
This commit is contained in:
parent
c640d28a82
commit
02e90a8645
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
<script type="text/javascript" src="js/tocbot/tocbot.min.js"></script>
|
||||
<script type="text/javascript" src="js/toc.js"></script>
|
||||
<script type="text/javascript" src="js/switch-language.js"></script>
|
|
@ -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);
|
Loading…
Reference in New Issue