sub-menu.html 3.5 KB
Newer Older
Clément's avatar
Clément committed
1 2 3 4 5 6 7 8
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>SIB test: sib-router</title>
    <script type="module" src="../src/index.js"></script>
9 10 11 12 13 14 15 16 17
    <a href="." id="reload">reload</a>
    <script>
      reload.href = location.pathname;
      window.addEventListener('keydown', ev => {
        if(!ev.ctrlKey || ev.key !== 'r') return;
        ev.preventDefault();
        reload.click();
      });
    </script>
Clément's avatar
Clément committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    <style>
      sib-router {
        display: block;
        text-align: center;
      }
      sib-route,
      sib-link {
        display: inline-block;
        padding: 0.5em;
        margin: 0.2em;
        background-color: #ccc;
        cursor: pointer;
      }
      [active] {
        background-color: #afa;
      }
    </style>
  </head>

  <body>
38 39 40 41
    <details>
      <summary>use-hash</summary>
      <h1>Musical Instruments</h1>
      <sib-link next="ukulele">→ Go to ukulele</sib-link>
Clément's avatar
Clément committed
42 43
      <sib-link next="brass" data-src="myID">→ Go to brass</sib-link>
      <hr>
44 45 46 47
      <sib-router default-route="keyboard" route-prefix="examples/sub-menu.html" use-hash>
        <sib-route name="keyboard">Keyboard</sib-route>
        <sib-route name="string">String</sib-route>
        <sib-route name="brass">Brass</sib-route>
Clément's avatar
Clément committed
48 49
      </sib-router>

50 51 52 53 54 55 56 57 58 59
      <div id="keyboard" hidden>
        <sib-router default-route="piano" route-prefix="titi" use-hash>
          <sib-route name="piano">Piano</sib-route>
          <sib-route name="harpsichord">Harpsichord</sib-route>
          <sib-route name="organ">Organ</sib-route>
        </sib-router>
        <div hidden id="piano"><h2>Piano</h2></div>
        <div hidden id="harpsichord"><h2>Harpsichord</h2></div>
        <div hidden id="organ"><h2>Organ</h2></div>
      </div>
Clément's avatar
Clément committed
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      <div id="string" hidden>
        <sib-router default-route="violin" use-hash>
          <sib-route name="violin">Violin</sib-route>
          <sib-route name="contrabass">Contrabass</sib-route>
          <sib-route name="guitar">Guitar</sib-route>
          <sib-route name="ukulele">Ukulele</sib-route>
        </sib-router>
        <div hidden id="violin"><h2>Violin</h2></div>
        <div hidden id="contrabass"><h2>Contrabass</h2></div>
        <div hidden id="guitar"><h2>Guitar</h2></div>
        <div hidden id="ukulele"><h2>Ukulele</h2></div>
      </div>

      <div id="brass" hidden>
        <sib-router default-route="trumpet" use-hash>
          <sib-route name="trumpet">Trumpet</sib-route>
          <sib-route name="trombone">Trombone</sib-route>
          <sib-route name="tuba">Tuba</sib-route>
        </sib-router>
        <div hidden id="trumpet"><h2>Trumpet</h2></div>
        <div hidden id="trombone"><h2>Trombone</h2></div>
        <div hidden id="tuba"><h2>Tuba</h2></div>
      </div>
    </details>
    <script>
      const details0 = document.querySelector('details');
      const details = details0.cloneNode(true);
      details.querySelector('summary').textContent = 'no use-hash';
      Array.from(details.querySelectorAll('[use-hash]')).forEach(elm =>
        elm.removeAttribute('use-hash'),
      );

      ['default-route', 'name', 'id', 'next'].forEach(attr => {
        Array.from(details.querySelectorAll(`[${attr}]`)).forEach(elm => {
          elm.setAttribute(attr, '_' + elm.getAttribute(attr));
        });
      });
      details0.parentElement.insertBefore(details, details0.nextSibling);
    </script>
Clément's avatar
Clément committed
100 101
  </body>
</html>