File size: 1,347 Bytes
7f8e190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* 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));
    });
  }
})();