From 980a633468b56577313021e0c38e74df44affe84 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Thu, 21 Jun 2018 11:17:32 +0100 Subject: [PATCH] Add toggleAttribute() to Element Tests: see https://bugzilla.mozilla.org/show_bug.cgi?id=1469592. Will be upstreamed soonish. Fixes #461. --- dom.bs | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 494e1769c..ad8b27a3c 100644 --- a/dom.bs +++ b/dom.bs @@ -5789,6 +5789,7 @@ interface Element : Node { [CEReactions] void setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value); [CEReactions] void removeAttribute(DOMString qualifiedName); [CEReactions] void removeAttributeNS(DOMString? namespace, DOMString localName); + [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); boolean hasAttribute(DOMString qualifiedName); boolean hasAttributeNS(DOMString? namespace, DOMString localName); @@ -6464,6 +6465,14 @@ namespace.

Removes element's attribute whose namespace is namespace and local name is localName. +

element . toggleAttribute(qualifiedName [, force]) +
+

If force is not given, "toggles" qualifiedName, removing it if it is + present and adding it if it is not present. If force is true, adds + qualifiedName. If force is false, removes qualifiedName. + +

Returns true if qualifiedName is now present, and false otherwise. +

element . hasAttribute(qualifiedName)

Returns true if element has an attribute whose qualified name is qualifiedName, and false otherwise. @@ -6577,6 +6586,42 @@ when invoked, must run these steps: otherwise. +

The toggleAttribute(qualifiedName, force) +method, when invoked, must run these steps: + +

    +
  1. If qualifiedName does not match the Name production in + XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. + +

  2. If the context object is in the HTML namespace and its + node document is an HTML document, then set qualifiedName to + qualifiedName in ASCII lowercase. + +

  3. Let attribute be the first attribute in the context object's + attribute list whose qualified name is qualifiedName, + and null otherwise. + + +

  4. +

    If attribute is null, then: + +

      +
    1. If force is not given or is true, create an attribute whose + local name is qualifiedName, value is the empty + string, and node document is the context object's + node document, then append this attribute + to the context object, and then return true. + +

    2. Return false. +

    + +
  5. Otherwise, if force is not given or is false, + remove an attribute given qualifiedName and the + context object, and then return false. + +

  6. Return true. +

+

The hasAttributeNS(namespace, localName) method, when invoked, must run these steps: @@ -9629,7 +9674,7 @@ method, when invoked, must run these steps: token from context object's token set, run the update steps and return false. -

  • Otherwise, return true. +

  • Return true.

  • Otherwise, if force not given or is true, append token @@ -9915,6 +9960,7 @@ Joe Kesselman, John Atkins, John Dai, Jonas Sicking, +Jonathan Kingston, Jonathan Robie, Joris van der Wel, Joshua Bell,