-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor toggle attribute #663
base: main
Are you sure you want to change the base?
Changes from all commits
9c8351b
63a9c3e
543336c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6189,6 +6189,40 @@ in an <a for="/">element</a> <var>element</var>, run these steps: | |
|
||
<hr> | ||
|
||
|
||
To <dfn export id=concept-element-attributes-set-by-name>create an attribute by value</dfn> | ||
given a <var>qualifiedName</var>, <var>value</var> and <a for="/">element</a> <var>element</var>, run these steps: | ||
|
||
<ol> | ||
<li><p>Create an <a>attribute</a> whose | ||
<a for="Attr">local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is | ||
<var>value</var>, and <a for=Node>node document</a> is <a>context object</a>'s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the context object* throughout |
||
<a for=Node>node document</a>. | ||
|
||
<li><a lt="append an attribute">Append</a> this <a>attribute</a> to | ||
<a>element</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want |
||
|
||
<li>Return. | ||
</ol> | ||
|
||
To <dfn export id=concept-element-attributes-get-valid-by-name>get a valid attribute by name</dfn> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "validate and get an attribute by name" perhaps? |
||
given a <var>qualifiedName</var>, and <a for="/">element</a> <var>element</var>, 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 <var>element</var> 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>. | ||
|
||
<!-- This is step 2 of "get an attribute by name", modified as appropriate --> | ||
<li><p>Let <var>attribute</var> be the first <a>attribute</a> in <var>element</var>'s <a for=Element>attribute list</a> | ||
whose <a for=Attr>qualified name</a> is <var>qualifiedName</var>, and null otherwise. | ||
|
||
<li>Return <var>qualifiedName</var>, and <var>attribute</var>. | ||
</ol> | ||
|
||
To <dfn export id=concept-element-attributes-get-by-name>get an attribute by name</dfn> given a | ||
<var>qualifiedName</var> and <a for="/">element</a> <var>element</var>, run these steps: | ||
|
||
|
@@ -6528,23 +6562,10 @@ method, when invoked, must these steps: | |
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>qualifiedName</var> and <var>attribute</var> be the result of running <a>get a valid attribute by name</a> given the <var>qualifiedName</var> and <a>context object</a> | ||
|
||
<li><p>Let <var>attribute</var> be the first <a>attribute</a> in <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, create an <a>attribute</a> whose | ||
<a for="Attr">local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is | ||
<var>value</var>, and <a for=Node>node document</a> is <a>context object</a>'s | ||
<a for=Node>node document</a>, then <a lt="append an attribute">append</a> this <a>attribute</a> to | ||
<a>context object</a>, and then return. | ||
<li><p>If <var>attribute</var> is null, run <a>create an attribute by value</a> given the <var>qualifiedName</var>, <var>value</var> and <a>context object</a>, and then return. | ||
|
||
<li><p><a lt="change an attribute">Change</a> <var>attribute</var> from <a>context object</a> to | ||
<var>value</var>. | ||
|
@@ -6590,36 +6611,25 @@ when invoked, must run these steps: | |
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>Let <var>qualifiedName</var> and <var>attribute</var> be the result of running <a>get a valid attribute by name</a> given the <var>qualifiedName</var> and <a>context object</a> | ||
|
||
<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>If <var>force</var> is given and is false, return false. | ||
|
||
<li><p>Return false. | ||
<li><p>Run <a>create an attribute by value</a> given the <var>qualifiedName</var>, <var>the empty string</var> and <a>context object</a>. | ||
|
||
<li>Return true. | ||
</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>Otherwise, if <var>force</var> is given and is true, return true. | ||
|
||
<li><p>Return true. | ||
<li><p><a lt="remove an attribute by name">Remove an attribute</a> given <var>qualifiedName</var> and the | ||
<a>context object</a>. | ||
|
||
<li>Return false. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</ol> | ||
|
||
<p>The | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should name this "create and append an attribute"? Or maybe I don't understand "by value".
The other thing I'm thinking is that it would be nice if https://dom.spec.whatwg.org/#concept-element-attributes-set-value could invoke this algorithm as well. That would require additional arguments for namespace/prefix, but seems doable.