function onSwitch()

in content/js/flink.js [29:51]


function onSwitch(tabId) {
    var selectorForId = "[data-tab-group='flink-tabs'][data-tab-item='" + tabId + "']";

    Array
        // find all tab group elements on the page
        .from(document.getElementsByClassName("book-tabs"))
        // filter out any elements that do not contain 
        // the specific tab the user wants to switch to.
        // these tabs should remain on their current selection
        .filter(div => div.querySelectorAll(selectorForId).length > 0)
        // extract the input elements for all tab groups
        // that do contain the target tab id
        .flatMap(div => Array.from(div.querySelectorAll("[data-tab-group='flink-tabs']")))
        // check input elements that contain the selected tabId
        // and uncheck all others
        .forEach(input => {
            if (input.matches(selectorForId)) {
                input.setAttribute("checked", "checked")
            } else {
                input.removeAttribute("checked")
            }
        });
}