mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
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
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;
|
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
|
// https://dom.spec.whatwg.org/#dom-element-toggleattribute
|
||||||
WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force)
|
WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force)
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,6 +88,7 @@ public:
|
||||||
DeprecatedFlyString const& namespace_uri() const { return namespace_(); }
|
DeprecatedFlyString const& namespace_uri() const { return namespace_(); }
|
||||||
|
|
||||||
bool has_attribute(DeprecatedFlyString const& name) const;
|
bool has_attribute(DeprecatedFlyString const& name) const;
|
||||||
|
bool has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const;
|
||||||
bool has_attributes() const;
|
bool has_attributes() const;
|
||||||
DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); }
|
DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); }
|
||||||
DeprecatedString get_attribute(DeprecatedFlyString const& name) const;
|
DeprecatedString get_attribute(DeprecatedFlyString const& name) const;
|
||||||
|
|
|
@ -35,6 +35,7 @@ interface Element : Node {
|
||||||
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
|
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
|
||||||
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
|
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
|
||||||
boolean hasAttribute(DOMString qualifiedName);
|
boolean hasAttribute(DOMString qualifiedName);
|
||||||
|
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
|
||||||
boolean hasAttributes();
|
boolean hasAttributes();
|
||||||
[SameObject] readonly attribute NamedNodeMap attributes;
|
[SameObject] readonly attribute NamedNodeMap attributes;
|
||||||
sequence<DOMString> getAttributeNames();
|
sequence<DOMString> getAttributeNames();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue