AgPerry's picture
Add files using upload-large-folder tool
7f8e190 verified
Raw History Blame Contribute Delete
1.35 kB
/* Home page: the Developer section's Playground sample switcher.
* The captured desktop page uses a list of links; the captured mobile page
* uses a native select. Both drive the same code panel here. */
(function () {
"use strict";
var panel = document.querySelector("[data-playground-code]");
if (!panel) {
return;
}
var sources = Array.prototype.map.call(
document.querySelectorAll("[data-playground-source]"),
function (node) {
return node.innerHTML;
}
);
var tabs = Array.prototype.slice.call(
document.querySelectorAll("[data-playground-tab]")
);
var select = document.querySelector("[data-playground-select]");
function show(index) {
if (index < 0 || index >= sources.length) {
return;
}
panel.innerHTML = sources[index];
tabs.forEach(function (tab, position) {
var active = position === index;
tab.classList.toggle("is-active", active);
tab.setAttribute("aria-selected", active ? "true" : "false");
});
if (select && Number(select.value) !== index) {
select.value = String(index);
}
}
tabs.forEach(function (tab, index) {
tab.addEventListener("click", function () {
show(index);
});
});
if (select) {
select.addEventListener("change", function () {
show(Number(select.value));
});
}
})();