<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>thingjs-examples</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
  <style type="text/css">
    * {
      box-sizing: border-box;
    }

    html {
      height: 100%;
    }

    body {
      background-color: #ffffff;
      margin: 0px;
      height: 100%;
      color: #555;
      font-size: 15px;
      line-height: 18px;
      overflow: hidden;
    }

    h1 {
      margin-top: 30px;
      margin-bottom: 40px;
      margin-left: 20px;
      font-size: 25px;
      font-weight: normal;
    }

    h2 {
      font-size: 20px;
      font-weight: normal;
    }

    a {
      color: #2194ce;
      text-decoration: none;
    }

    #panel {
      position: fixed;
      left: 0px;
      width: 310px;
      height: 100%;
      overflow: auto;
      background: #fafafa;
    }

    #panel #content {
      padding: 0px 20px 20px 20px;
    }

    #panel #content .link {
      color: #2194ce;
      text-decoration: none;
      cursor: pointer;
      display: block;
    }

    #panel #content .selected {
      color: #ff0000;
    }

    #panel #content .link:hover {
      text-decoration: underline;
    }

    #viewer {
      position: absolute;
      border: 0px;
      left: 310px;
      width: calc(100% - 310px);
      height: 100%;
      overflow: auto;
    }

    #button {
      position: fixed;
      bottom: 20px;
      right: 20px;
      padding: 8px;
      color: #fff;
      background-color: #555;
      opacity: 0.7;
    }

    #button:hover {
      cursor: pointer;
      opacity: 1;
    }

    /* mobile */

    #expandButton {
      display: none;
      position: absolute;
      right: 20px;
      top: 12px;
      width: 32px;
      height: 32px;
    }

    #expandButton span {
      height: 2px;
      background-color: #2194ce;
      width: 16px;
      position: absolute;
      left: 8px;
      top: 10px;
    }

    #expandButton span:nth-child(1) {
      top: 16px;
    }

    #expandButton span:nth-child(2) {
      top: 22px;
    }

    @media all and (max-width: 640px) {
      h1 {
        margin-top: 20px;
        margin-bottom: 20px;
      }

      #panel {
        position: absolute;
        left: 0;
        top: 0;
        height: 480px;
        width: 100%;
        right: 0;
        z-index: 100;
        overflow: hidden;
        border-bottom: 1px solid #dedede;
      }

      #content {
        position: absolute;
        left: 0;
        top: 90px;
        right: 0;
        bottom: 0;
        font-size: 17px;
        line-height: 22px;
        overflow: auto;
      }

      #viewer {
        position: absolute;
        left: 0;
        top: 56px;
        width: 100%;
        height: calc(100% - 56px);
      }

      #expandButton {
        display: block;
      }

      #panel.collapsed {
        height: 56px;
      }
    }
  </style>
</head>

<body>
  <div id="panel" class="">
    <h1><a href="http://www.thingjs.com">thing.js</a> / examples</h1>
    <a id="expandButton" href="#">
      <span></span>
      <span></span>
      <span></span>
    </a>
    <div id="content"></div>
  </div>
  <iframe id="viewer" title="" name="viewer" allowfullscreen allowvr onmousewheel=""></iframe>

  <script src="files.js"></script>

  <script>
    var viewer = document.getElementById("viewer");
    var content = document.getElementById("content");

    // iOS iframe auto-resize workaround

    if (/(iPad|iPhone|iPod)/g.test(navigator.userAgent)) {
      viewer.style.width = getComputedStyle(viewer).width;
      viewer.style.height = getComputedStyle(viewer).height;
      viewer.setAttribute("scrolling", "no");
    }

    var expandButton = document.getElementById("expandButton");
    expandButton.addEventListener("click", function (event) {
      panel.classList.toggle("collapsed");
      event.preventDefault();
    });

    var container = document.createElement("div");
    content.appendChild(container);

    var button = document.createElement("div");
    button.id = "button";
    button.textContent = "View source";
    button.addEventListener(
      "click",
      function (event) {
        // open source page
        // window.open( 'https:/..//master/examples/' + selected + '.html' );
      },
      false
    );
    button.style.display = "none";
    document.body.appendChild(button);
    var links = {};
    var selected = null;

    for (var key in files) {
      var section = files[key];

      var header = document.createElement("h2");
      header.textContent = key;
      header.setAttribute("data-category", key);
      container.appendChild(header);

      for (var i = 0; i < section.length; i++) {
        (function (file) {
          var link = document.createElement("a");
          link.className = "link";
          link.textContent = file.content;
          link.href = file.herf + ".html";
          link.setAttribute("target", "viewer");
          link.addEventListener("click", function (event) {
            if (event.button === 0) {
              selectFile(file.herf);
            }
          });
          container.appendChild(link);

          links[file.herf] = link;
        })(section[i]);
      }
    }

    function loadFile(file) {
      selectFile(file);
      viewer.src = file + ".html";
    }

    function selectFile(file) {
      if (selected !== null) links[selected].classList.remove("selected");

      links[file].classList.add("selected");

      window.location.hash = file;
      viewer.focus();

      button.style.display = "";
      panel.classList.toggle("collapsed");

      selected = file;
    }

    if (window.location.hash !== "") {
      loadFile(window.location.hash.substring(1));
    }
  </script>
</body>

</html>