Skip to content

Commit

Permalink
Add toggleAttribute() to Element
Browse files Browse the repository at this point in the history
Tests: see https://bugzilla.mozilla.org/show_bug.cgi?id=1469592. Will be upstreamed soonish.

Fixes #461.
  • Loading branch information
jonathanKingston authored and annevk committed Jun 21, 2018
1 parent c69d7c0 commit 980a633
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -6464,6 +6465,14 @@ namespace.</p>
<dd><p>Removes <var>element</var>'s <a>attribute</a> whose <a for=Attr>namespace</a> is
<var>namespace</var> and <a for=Attr>local name</a> is <var>localName</var>.

<dt><code><var>element</var> . <a method for=Element lt=toggleAttribute()>toggleAttribute</a>(<var>qualifiedName</var> [, <var>force</var>])</code>
<dd>
<p>If <var>force</var> is not given, "toggles" <var>qualifiedName</var>, removing it if it is
present and adding it if it is not present. If <var>force</var> is true, adds
<var>qualifiedName</var>. If <var>force</var> is false, removes <var>qualifiedName</var>.

<p>Returns true if <var>qualifiedName</var> is now present, and false otherwise.

<dt><code><var>element</var> . <a method for=Element lt=hasAttribute()>hasAttribute</a>(<var>qualifiedName</var>)</code>
<dd><p>Returns true if <var>element</var> has an <a>attribute</a> whose
<a for=Attr>qualified name</a> is <var>qualifiedName</var>, and false otherwise.
Expand Down Expand Up @@ -6577,6 +6586,42 @@ when invoked, must run these steps:
otherwise.
</ol>

<p>The <dfn method for=Element><code>toggleAttribute(<var>qualifiedName</var>, <var>force</var>)</code></dfn>
method, when invoked, must run these steps:

<ol>
<li><p>If <var>qualifiedName</var> does not match the <code><a type>Name</a></code> production in
XML, then <a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

<li><p>If the <a>context object</a> is in the <a>HTML namespace</a> and its
<a for=Node>node document</a> is an <a>HTML document</a>, then set <var>qualifiedName</var> to
<var>qualifiedName</var> in <a>ASCII lowercase</a>.

<li><p>Let <var>attribute</var> be the first <a>attribute</a> in the <a>context object</a>'s
<a for=Element>attribute list</a> whose <a for=Attr>qualified name</a> is <var>qualifiedName</var>,
and null otherwise.
<!-- This is step 2 of "get an attribute by name", modified as appropriate -->

<li>
<p>If <var>attribute</var> is null, then:

<ol>
<li><p>If <var>force</var> is not given or is true, create an <a>attribute</a> whose
<a for="Attr">local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is the empty
string, and <a for=Node>node document</a> is the <a>context object</a>'s
<a for=Node>node document</a>, then <a lt="append an attribute">append</a> this <a>attribute</a>
to the <a>context object</a>, and then return true.

<li><p>Return false.
</ol>

<li><p>Otherwise, if <var>force</var> is not given or is false,
<a lt="remove an attribute by name">remove an attribute</a> given <var>qualifiedName</var> and the
<a>context object</a>, and then return false.

<li><p>Return true.
</ol>

<p>The
<dfn method for=Element><code>hasAttributeNS(<var>namespace</var>, <var>localName</var>)</code></dfn>
method, when invoked, must run these steps:
Expand Down Expand Up @@ -9629,7 +9674,7 @@ method, when invoked, must run these steps:
<var>token</var> from <a>context object</a>'s <a>token set</a>, run the <a>update steps</a> and
return false.

<li><p>Otherwise, return true.
<li><p>Return true.
</ol>

<li><p>Otherwise, if <var>force</var> not given or is true, <a for=set>append</a> <var>token</var>
Expand Down Expand Up @@ -9915,6 +9960,7 @@ Joe Kesselman,
John Atkins,
John Dai,
Jonas Sicking,
Jonathan Kingston,
Jonathan Robie,
Joris van der Wel,
Joshua Bell,
Expand Down

0 comments on commit 980a633

Please sign in to comment.