')
var buybox = document.querySelector("[data-id=id_"+ timestamp +"]").parentNode
var buyboxMaxSingleColumnWidth = 480
// springerPlus roll out 10% starts here
var springerPlusGroup = setLocalStorageSpringerPlus();
var rollOutSpringerPlus = springerPlusGroup === "B"
function setLocalStorageSpringerPlus() {
var selectUserKey = "springerPlusRollOut";
var springerPlusGroup = "X";
if (!window.localStorage) return springerPlusGroup;
try {
var selectUserValue = window.localStorage.getItem(selectUserKey)
springerPlusGroup = selectUserValue || randomDistributionSpringerPlus(selectUserKey)
} catch (err) {
console.log(err)
}
return springerPlusGroup;
}
function randomDistributionSpringerPlus(selectUserKey) {
var randomGroup = Math.random() < 0.7 ? "A" : "B"
window.localStorage.setItem(selectUserKey, randomGroup)
return randomGroup
}
if (rollOutSpringerPlus) {
revealSpringerPlus();
}
function revealSpringerPlus() {
if(buybox) {
document.querySelectorAll(".c-springer-plus").forEach(function(node) {
node.style.display = "block"
})
}
}
//springerPlus ends here
;[].slice.call(buybox.querySelectorAll(".buying-option")).forEach(initCollapsibles)
function initCollapsibles(buyingOption, index) {
var toggle = buyingOption.querySelector(".buying-option-price")
buyingOption.classList.remove("expanded")
var form = buyingOption.querySelector(".buying-option-form")
var priceInfo = buyingOption.querySelector(".price-info")
if (toggle && form && priceInfo) {
toggle.setAttribute("role", "button")
toggle.setAttribute("tabindex", "0")
toggle.addEventListener("click", function (event) {
var expandedBuyingOptions = buybox.querySelectorAll(".buying-option.expanded")
var buyboxWidth = buybox.offsetWidth
;[].slice.call(expandedBuyingOptions).forEach(function(option) {
if (buyboxWidth <= buyboxMaxSingleColumnWidth && option != buyingOption) {
hideBuyingOption(option)
}
})
var expanded = toggle.getAttribute("aria-expanded") === "true" || false
toggle.setAttribute("aria-expanded", !expanded)
form.hidden = expanded
if (!expanded) {
buyingOption.classList.add("expanded")
} else {
buyingOption.classList.remove("expanded")
}
priceInfo.hidden = expanded
}, false)
}
}
function hideBuyingOption(buyingOption) {
var toggle = buyingOption.querySelector(".buying-option-price")
var form = buyingOption.querySelector(".buying-option-form")
var priceInfo = buyingOption.querySelector(".price-info")
toggle.setAttribute("aria-expanded", false)
form.hidden = true
buyingOption.classList.remove("expanded")
priceInfo.hidden = true
}
function initKeyControls() {
document.addEventListener("keydown", function (event) {
if (document.activeElement.classList.contains("buying-option-price") && (event.code === "Space" || event.code === "Enter")) {
if (document.activeElement) {
event.preventDefault()
document.activeElement.click()
}
}
}, false)
}
function initialStateOpen() {
var buyboxWidth = buybox.offsetWidth
var narrowBuyboxArea = buyboxWidth <= buyboxMaxSingleColumnWidth
var allOptionsInitiallyCollapsed = buybox.className.indexOf("all-options-initially-collapsed") > -1
;[].slice.call(buybox.querySelectorAll(".buying-option")).forEach(function (option, index) {
var toggle = option.querySelector(".buying-option-price")
var form = option.querySelector(".buying-option-form")
var priceInfo = option.querySelector(".price-info")
if (allOptionsInitiallyCollapsed || narrowBuyboxArea && index > 0) {
toggle.setAttribute("aria-expanded", "false")
form.hidden = "hidden"
priceInfo.hidden = "hidden"
} else {
toggle.click()
}
})
}
initialStateOpen()
if (window.buyboxInitialised) return
window.buyboxInitialised = true
initKeyControls()
})()