Browse Source

Update to spec version of 13 August 2020

Moves window.location.fragmentDirective to document.fragmentDirective
tags/v0.1.0-src
Gerben 8 months ago
parent
commit
484ef3bd45
3 changed files with 15 additions and 13 deletions
  1. +1
    -1
      demo.html
  2. +13
    -11
      src/index.ts
  3. +1
    -1
      src/polyfill.ts

+ 1
- 1
demo.html View File

@@ -48,7 +48,7 @@
<em>Detecting failed (or page is loading?)</em>
<script>
window.addEventListener('load', () => {
const fragmentDirective = window.location.fragmentDirective;
const fragmentDirective = document.fragmentDirective;
const message = (fragmentDirective
? fragmentDirective._implementation === 'text-fragments-ts'
? 'Yes'


+ 13
- 11
src/index.ts View File

@@ -4,7 +4,7 @@

// An implementation of (most of) the Text Fragments draft spec.
// See https://wicg.github.io/scroll-to-text-fragment/
// Based on the version of 12 August 2020. <https://raw.githubusercontent.com/WICG/scroll-to-text-fragment/60f5f63b4997bde7e688cacf897e1167c622e100/index.html>
// Based on the version of 13 August 2020. <https://raw.githubusercontent.com/WICG/scroll-to-text-fragment/2dcfbd6e272f51e5b250c58076b6d1cc57656fce/index.html>

// Some terms used in the spec (would be great if these could be expressed more precisely in TypeScript)
type nonEmptyString = string;
@@ -1005,26 +1005,28 @@ function isWordBounded(text: string, startPosition: integer, count: number, star

// https://wicg.github.io/scroll-to-text-fragment/#feature-detectability
// § 3.8. Feature Detectability
// “For feature detectability, we propose adding a new FragmentDirective interface that is exposed via window.location.fragmentDirective if the UA supports the feature.
// [Exposed=Window]
// “For feature detectability, we propose adding a new FragmentDirective interface that is exposed via document.fragmentDirective if the UA supports the feature.
// [Exposed=Document]
// interface FragmentDirective {
// };
// We amend the Location interface to include a fragmentDirective property:
// partial interface Location {
// [SameObject] readonly attribute FragmentDirective fragmentDirective
// ;
// };
// We amend the Document interface to include a fragmentDirective property:
// partial interface Document {
// [SameObject] readonly attribute FragmentDirective fragmentDirective;
// };”
export interface FragmentDirective {
};
// TODO Can and should we modify the Location interface?
// TODO Can and should we modify the Document interface?

export function browserSupportsTextFragments(): boolean {
return ('fragmentDirective' in window.location);
return (
'fragmentDirective' in Document
// Also check in window.location, which was in the spec until & including the version of 12 August 2020. See commit <https://github.com/WICG/scroll-to-text-fragment/commit/2dcfbd6e272f51e5b250c58076b6d1cc57656fce>.
|| 'fragmentDirective' in window.location
);
}




/////////////////////////////////////////////
// Required pieces of the WHATWG DOM spec ///
/////////////////////////////////////////////


+ 1
- 1
src/polyfill.ts View File

@@ -45,7 +45,7 @@ function pretendBrowserSupportsTextFragments(): void {
enumerable: false,
});

Object.defineProperty(window.location, 'fragmentDirective', {
Object.defineProperty(document, 'fragmentDirective', {
value: fragmentDirective,
writable: false,
});


Loading…
Cancel
Save