From c930f75979d036537edc0f8ac4401c5bd0dc94f0 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Fri, 31 Jul 2020 16:43:00 +0300 Subject: [PATCH] Define TreeNode mixin and add .closest() to more nodes --- dom.bs | 78 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/dom.bs b/dom.bs index 0e351d14e..342f95291 100644 --- a/dom.bs +++ b/dom.bs @@ -3075,6 +3075,53 @@ steps: +

Mixin {{TreeNode}}

+ +
+interface mixin TreeNode {
+  [Unscopable] Element? closest(DOMString selectors);
+};
+Element includes TreeNode;
+CharacterData includes TreeNode;
+Document includes TreeNode;
+DocumentType includes TreeNode;
+DocumentFragment includes TreeNode;
+
+ +
+
node . {{closest(selectors)}} +
+

Returns the first (starting at node) inclusive ancestor + that matches selectors, and null otherwise. +

+ +

The +closest(selectors) method, when invoked, must run these steps: + +

    +
  1. Let s be the result of parse a selector from selectors. + [[!SELECTORS4]] + +

  2. If s is failure, throw a "{{SyntaxError!!exception}}" {{DOMException}}. + +

  3. Let elements be this's inclusive ancestors that are + elements, in reverse tree order. + +

  4. If elements is not empty, then: + +

      +
    1. Let scopeElement be the first element in elements. + +

    2. For each element in elements, + if match a selector against an element, using s, element, + and :scope element scopeElement, returns success, return element. + [[!SELECTORS4]] +

    + +
  5. Return null. +

+ +

Mixin {{Slottable}}

@@ -5861,7 +5908,6 @@ interface Element : Node {
   ShadowRoot attachShadow(ShadowRootInit init);
   readonly attribute ShadowRoot? shadowRoot;
 
-  Element? closest(DOMString selectors);
   boolean matches(DOMString selectors);
   boolean webkitMatchesSelector(DOMString selectors); // historical alias of .matches
 
@@ -6776,42 +6822,12 @@ steps:
 
-
element . {{closest(selectors)}} -
Returns the first (starting at element) - inclusive ancestor that matches - selectors, and null otherwise. -
element . {{matches(selectors)}}
Returns true if matching selectors against element's root yields element, and false otherwise.
-The closest(selectors) -method, when invoked, must run these steps: - -
    -
  1. Let s be the result of - parse a selector from selectors. - [[!SELECTORS4]] - -
  2. If s is failure, throw a - "{{SyntaxError!!exception}}" {{DOMException}}. - -
  3. Let elements be this's - inclusive ancestors that are - elements, in reverse - tree order. - -
  4. For each element in elements, if - match a selector against an element, using - s, element, and - :scope element this, - returns success, return element. [[!SELECTORS4]] - -
  5. Return null. -
- The matches(selectors) and webkitMatchesSelector(selectors) methods, when invoked, must run these steps: