LibWeb: Implement Element.hasAttributeNS
Particularly needed by xkcd's Right Click comic. https://xkcd.com/1975/
This commit is contained in:
parent
3a98c48f20
commit
5694981352
Notes:
sideshowbarker
2024-07-16 23:13:25 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/5694981352 Pull-request: https://github.com/SerenityOS/serenity/pull/20463
3 changed files with 13 additions and 0 deletions
|
@ -234,6 +234,17 @@ bool Element::has_attribute(DeprecatedFlyString const& name) const
|
|||
return m_attributes->get_attribute(name) != nullptr;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-hasattributens
|
||||
bool Element::has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const
|
||||
{
|
||||
// 1. If namespace is the empty string, then set it to null.
|
||||
if (namespace_.is_empty())
|
||||
namespace_ = {};
|
||||
|
||||
// 2. Return true if this has an attribute whose namespace is namespace and local name is localName; otherwise false.
|
||||
return m_attributes->get_attribute_ns(namespace_, name) != nullptr;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-toggleattribute
|
||||
WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force)
|
||||
{
|
||||
|
|
|
@ -88,6 +88,7 @@ public:
|
|||
DeprecatedFlyString const& namespace_uri() const { return namespace_(); }
|
||||
|
||||
bool has_attribute(DeprecatedFlyString const& name) const;
|
||||
bool has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const;
|
||||
bool has_attributes() const;
|
||||
DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); }
|
||||
DeprecatedString get_attribute(DeprecatedFlyString const& name) const;
|
||||
|
|
|
@ -35,6 +35,7 @@ interface Element : Node {
|
|||
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
|
||||
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
|
||||
boolean hasAttribute(DOMString qualifiedName);
|
||||
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
|
||||
boolean hasAttributes();
|
||||
[SameObject] readonly attribute NamedNodeMap attributes;
|
||||
sequence<DOMString> getAttributeNames();
|
||||
|
|
Loading…
Add table
Reference in a new issue