|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title> |
| 6 | + Linking To A Disclosure (Details) Element |
| 7 | + </title> |
| 8 | + <link rel="stylesheet" type="text/css" href="./main.css" /> |
| 9 | +</head> |
| 10 | +<body> |
| 11 | + |
| 12 | + <h1> |
| 13 | + Linking To A Disclosure (Details) Element |
| 14 | + </h1> |
| 15 | + |
| 16 | + <!-- |
| 17 | + Note: I'm linking to the SUMMARY element, not to the details element, since only |
| 18 | + the summary element is actionable: it acts as the toggle for the details control |
| 19 | + and can be triggered with Space key or Enter key. It also provides labeling and |
| 20 | + context to accessibility software. |
| 21 | + --> |
| 22 | + <ul> |
| 23 | + <li> |
| 24 | + <a href="#summary1">Markdown Syntax</a> |
| 25 | + </li> |
| 26 | + <li> |
| 27 | + <a href="#summary2">Keyboard Shortcuts</a> |
| 28 | + </li> |
| 29 | + <li> |
| 30 | + <a href="#summary3">Privacy Policy</a> |
| 31 | + </li> |
| 32 | + </ul> |
| 33 | + |
| 34 | + <details name="demo"> |
| 35 | + <summary id="summary1"> |
| 36 | + Markdown Syntax |
| 37 | + </summary> |
| 38 | + <section aria-labeledby="summary1"> |
| 39 | + You can use limited Markdown syntax in your content. |
| 40 | + </section> |
| 41 | + </details> |
| 42 | + |
| 43 | + <details name="demo"> |
| 44 | + <summary id="summary2"> |
| 45 | + Keyboard Shortcuts |
| 46 | + </summary> |
| 47 | + <section aria-labeledby="summary2"> |
| 48 | + You can use the following keyboard shortcuts in the application. |
| 49 | + </section> |
| 50 | + </details> |
| 51 | + |
| 52 | + <details name="demo"> |
| 53 | + <summary id="summary3"> |
| 54 | + Privacy Policy |
| 55 | + </summary> |
| 56 | + <section aria-labeledby="summary3"> |
| 57 | + All your data is belong to us! |
| 58 | + </section> |
| 59 | + </details> |
| 60 | + |
| 61 | + <script type="text/javascript"> |
| 62 | + |
| 63 | + // When the page first loads, or whenever the location hash changes, check to see |
| 64 | + // if the hash points to a disclosure summary. If so, ensure that the disclosure |
| 65 | + // is open. The browser will handle the focus automatically (via the hash). |
| 66 | + window.addEventListener( "load", applyHashEventToSummary ); |
| 67 | + window.addEventListener( "hashchange", applyHashEventToSummary ); |
| 68 | + |
| 69 | + // Expand details is the summary is the target of the hash. |
| 70 | + function applyHashEventToSummary( event ) { |
| 71 | + |
| 72 | + // The ":target" pseudo selector matches the element linked-to via the hash. |
| 73 | + var summary = document.querySelector( ":target:is(summary)" ); |
| 74 | + var details = summary?.parentElement; |
| 75 | + |
| 76 | + if ( details && ! details.open ) { |
| 77 | + |
| 78 | + details.open = true; |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + </script> |
| 85 | + |
| 86 | +</body> |
| 87 | +</html> |
0 commit comments