text-fragments-ts/ demo.html
154 lines
9.9 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>Text Fragments playground</title>
  6. <script src="./lib/polyfill.js" type="module"></script>
  7. <script>
  8. (async function () {
  9. const { applyFragDir } = await import('./lib/polyfill.js');
  10. globalThis.applyFragDir = applyFragDir;
  11. console.log(`You can try out fragment directives using applyFragDir(…); e.g. applyFragDir(':~:text=bla')`);
  12. })();
  13. </script>
  14. <style>
  15. body {
  16. margin: 0;
  17. line-height: 1.8;
  18. font-family: sans-serif;
  19. }
  20. main {
  21. max-width: 30em;
  22. margin: auto;
  23. font-family: serif;
  24. }
  25. header {
  26. background-color: linen;
  27. padding: 1em;
  28. }
  29. header div {
  30. max-width: 48em;
  31. margin: auto;
  32. }
  33. aside {
  34. background-color:floralwhite;
  35. padding: 1em;
  36. }
  37. h2 {
  38. font-size: 1em;
  39. }
  40. a {
  41. text-decoration: none;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <header>
  47. <div>
  48. <h1>Text Fragments playground</h1>
  49. <p>
  50. This page demonstrates <a href="https://wicg.github.io/scroll-to-text-fragment/">Text Fragments</a> using the <a href="https://code.treora.com/gerben/text-fragments-ts">text-fragments-ts</a> implementation as a polyfill</a>.
  51. </p>
  52. <p style="background: whitesmoke; padding: 1em;">
  53. Is this page currently using the polyfill?
  54. <b id="usingPolyfill">
  55. <em>Detecting failed (or page is loading?)</em>
  56. <script>
  57. window.addEventListener('load', () => {
  58. const fragmentDirective = document.fragmentDirective || window.location.fragmentDirective;
  59. const message = (fragmentDirective
  60. ? fragmentDirective._implementation === 'text-fragments-ts'
  61. ? 'Yes'
  62. : 'Partially <em>(your browser appears to support text fragments already! But it might not work when clicking links that point to fragments within this same page, so the polyfill is invoked when clicking the links below)</em>'
  63. : 'No <em>(something went wrong?)</em>'
  64. );
  65. usingPolyfill.innerHTML = message;
  66. });
  67. </script>
  68. <noscript>No <em>(Javascript is disabled)</em></noscript>
  69. </b>
  70. </p>
  71. <p>
  72. Try click some of the links below: they point at specific quotes within this text, which the browser should then scroll to and highlight.
  73. </p>
  74. <ul>
  75. <li>
  76. <a href="#:~:text=semper ut commodo">Simple quote</a>
  77. </li>
  78. <li>
  79. <a href="#:~:text=placerat.%20Vivamus">Text spanning multiple elements</a>
  80. </li>
  81. <li>
  82. <a href="#:~:text=Cras%20et-,ipsum">Using prefix (pointing a specific occurrence of ‘ipsum’ by providing words before it)</a>
  83. </li>
  84. <li>
  85. <a href="#:~:text=ipsum,-sollicitudin">Using suffix (for the same ‘ipsum’)</a>
  86. </li>
  87. <li>
  88. <a href="#:~:text=sit-,amet,-auctor">Both prefix and suffix</a>
  89. </li>
  90. <li>
  91. <a href="#:~:text=GATTACAGACTGCGATACGT-,TACT,-AGTTAGGACTACGGGATCATATTAC">Point at letters within a word.</a> (possible since <a href="https://github.com/WICG/scroll-to-text-fragment/pull/148">spec update of October 2020</a>; requires quoting the whole word in prefix&suffix)
  92. </li>
  93. <li>
  94. <a href="#:~:text=Fusce%20quis,est.">Select text between two given phrases</a>
  95. </li>
  96. <li>
  97. <a href="#:~:text=Aliquam%20urna,scelerisque.">Text between two phrases in different block elements</a>
  98. </li>
  99. <li>
  100. <a href="#:~:text=GATTACA,CATATTAC">Select text between start and end of a long, uninterrupted string</a> <a href="https://github.com/WICG/scroll-to-text-fragment/issues/137">(not possible)</a>
  101. </li>
  102. <li>
  103. <a href="#:~:text=And more.-,And more.">Text making up a whole, reoccurring block element</a>
  104. </li>
  105. <li>
  106. <a href="#:~:text=Phasellus%20tempus%20dui&text=venenatis%20leo&text=ipsum,-eget">Multiple pieces of text (only works in Firefox)</a>
  107. </li>
  108. </ul>
  109. <p>
  110. You can also try write your own target quotes in the URL bar.
  111. </p>
  112. </div>
  113. </header>
  114. <!-- <aside>
  115. <h2>Options</h2>
  116. <input type="checkbox" id="checkboxWide" onchange="main.style.whiteSpace = this.checked ? 'nowrap' : null"> <label for="checkboxWide">Horizonal layout (to test scrolling)</label>
  117. <script>checkboxWide.checked = false; // To ensure consistency when page is refreshed.</script>
  118. </aside> -->
  119. <main id="main">
  120. <h1>Bla bla bla</h1>
  121. <p>
  122. Lorem ipsum dolor sit amet, <i>consectetur adipiscing elit</i>. Morbi ligula magna, semper a quam sit amet, malesuada tristique dui. Ut vitae diam massa. Proin gravida neque nec libero suscipit placerat. <b>Vivamus viverra <i>ligula vitae</i> orci fringilla vulputate</b>. Vivamus venenatis leo at venenatis venenatis. Mauris quam sem, sagittis sit amet mi quis, placerat laoreet eros. Suspendisse porta neque sit amet bibendum condimentum. Proin <a href="#:~:text=efficitur%20nulla%20aliquam">posuere purus</a> tellus, ac condimentum justo sollicitudin rhoncus. Integer nisl elit, convallis a velit nec, tristique convallis enim. Pellentesque placerat et purus <a href="#:~:text=semper%20ut%20commodo">porttitor tincidunt</a>.
  123. </p>
  124. <p>
  125. Phasellus tempus dui vitae velit efficitur, nec volutpat lorem imperdiet. Aliquam hendrerit lectus at erat molestie, a porta ipsum interdum. Donec justo ex, porta sit amet ipsum eget, commodo ultrices ex. Integer dapibus euismod ante non ultrices. Donec commodo magna id turpis condimentum convallis. Quisque tincidunt quam vitae fringilla mattis. Aenean mattis commodo dolor ac imperdiet. Maecenas libero est, placerat porttitor libero quis, mollis condimentum nunc. Praesent in quam vel velit gravida cursus. Cras facilisis lectus in lectus pellentesque, at imperdiet odio elementum. Suspendisse pulvinar dui et ligula sagittis, nec tristique tellus congue. Aenean sed nulla in quam malesuada elementum in nec nulla. Aliquam sed cursus metus. Cras a molestie augue, id sodales velit. Proin blandit justo sed ante placerat consectetur. Aliquam urna purus, tempor eu cursus at, pharetra ac velit.
  126. </p>
  127. <p>
  128. Proin accumsan mollis scelerisque. Sed id magna consectetur, tincidunt ipsum nec, semper velit. Morbi aliquam quis nisi non volutpat. Pellentesque a ultrices ante. In congue volutpat odio, vitae efficitur nulla aliquam quis. Vivamus cursus venenatis efficitur. Sed at ornare purus. Maecenas est justo, tincidunt ac convallis at, accumsan nec ipsum. Vestibulum tortor ligula, vestibulum a nisl sit amet, lobortis consectetur eros. Sed augue dui, porta at justo sit amet, venenatis convallis sapien. Praesent vel malesuada tortor, at iaculis diam.
  129. </p>
  130. <p>
  131. Integer egestas, justo at vestibulum consequat, metus turpis aliquam felis, a tincidunt dui lorem eget orci. Fusce quis feugiat sapien, quis pharetra nulla. Sed suscipit mauris non tincidunt suscipit. Vestibulum nec mollis est. Donec eget interdum urna. Cras placerat nulla nec orci pretium blandit. Phasellus eget odio imperdiet, interdum tortor vel, convallis ante. Pellentesque tristique convallis ultrices. Cras et ipsum sollicitudin, elementum nulla tempus, tempor tellus. In hac habitasse platea dictumst. Nam in aliquam neque.
  132. </p>
  133. <p>
  134. Vestibulum eu tristique elit. Sed ac ipsum sed sapien ultricies dapibus. Cras efficitur aliquet luctus. Aliquam sit amet auctor tellus, nec rhoncus nisl. Integer at lobortis sapien. Nunc mattis tristique libero, sed ultrices nunc imperdiet eu. Pellentesque accumsan, eros non auctor eleifend, felis massa bibendum lacus, non venenatis orci sapien eu sapien. Integer eu eros fringilla lectus vestibulum aliquam. Cras consectetur nunc nisi, vel molestie justo congue at. Duis eros neque, semper ut commodo in, molestie ut nunc. Vivamus vitae bibendum magna, suscipit sollicitudin elit. Praesent id rhoncus enim, sit amet suscipit velit. Aenean euismod purus velit, et consectetur nulla gravida vitae.
  135. </p>
  136. <p>
  137. The Chrome-osome is GATTACAGACTGCGATACGTTACTAGTTAGGACTACGGGATCATATTAC. Can we select it without quoting the whole thing? Nope.
  138. </p>
  139. <p>
  140. More.
  141. </p>
  142. <p>
  143. And more.
  144. </p>
  145. <p>
  146. And more.
  147. </p>
  148. <p>
  149. Finally, <a href="#:~:text=Text%20Fragments%20playground">a link to scroll back up.</a>
  150. </p>
  151. </main>
  152. </body>
  153. </html>