Class: Dommy::Element
- Inherits:
-
Object
- Object
- Dommy::Element
- Includes:
- Bridge::Methods, EventTarget, Internal::ParentNode, Node
- Defined in:
- lib/dommy/element.rb
Direct Known Subclasses
Constant Summary collapse
- HTML_NAMESPACE =
"http://www.w3.org/1999/xhtml"- REFLECTED_TOKEN_LIST_HOSTS =
Element + namespace combinations for which a reflected DOMTokenList IDL attribute is defined; elsewhere the attribute does not exist (→ undefined).
{ "relList" => {html: %w[a area link], svg: %w[a]}, "htmlFor" => {html: %w[output]}, "sandbox" => {html: %w[iframe]}, "sizes" => {html: %w[link]} }.freeze
- SVG_NAMESPACE =
"http://www.w3.org/2000/svg"- SHADOW_HOST_TAGS =
Elements that may host a Shadow DOM tree per the HTML spec. Custom-element-style names (containing "-") are also allowed.
%w[ article aside blockquote body div footer h1 h2 h3 h4 h5 h6 header main nav p section span ] .freeze
- ADJACENT_POSITIONS =
el.insertAdjacentElement(position, element)— DOM spec positions: "beforebegin", "afterbegin", "beforeend", "afterend". Returns the inserted element or nil if position has no anchor (root cases). %w[beforebegin afterbegin beforeend afterend].freeze
- ELEMENT_NODE =
Node type / NodeFilter bitmask constants — DOM Level 3 says these are exposed on both the constructor and every instance. Defined at the bottom of the class so subclasses inherit them too.
1- ATTRIBUTE_NODE =
2- TEXT_NODE =
3- CDATA_SECTION_NODE =
4- PROCESSING_INSTRUCTION_NODE =
7- COMMENT_NODE =
8- DOCUMENT_NODE =
9- DOCUMENT_TYPE_NODE =
10- DOCUMENT_FRAGMENT_NODE =
11- DOCUMENT_POSITION_DISCONNECTED =
0x01- DOCUMENT_POSITION_PRECEDING =
0x02- DOCUMENT_POSITION_FOLLOWING =
0x04- DOCUMENT_POSITION_CONTAINS =
0x08- DOCUMENT_POSITION_CONTAINED_BY =
0x10- DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC =
0x20- INLINE_TAGS =
Estimate y, width, height (CSS px) without laying out the page: block elements fill the viewport width; inline elements are sized to their text; height is the wrapped line count × a nominal line height. Position is the origin (we don't position elements). Used only when approximate_layout?.
%w[a span b i em strong small code label abbr cite q sub sup time mark u s tt var samp kbd bdi bdo wbr big font nobr].freeze
- APPROX_CHAR_PX =
8- APPROX_LINE_PX =
20
Constants included from Node
Node::XMLNS_NAMESPACE, Node::XML_NAMESPACE
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#[](key) ⇒ Object
el[:foo]/el[:foo] = ...bracket shortcut for the JS-style property access pattern. - #[]=(key, value) ⇒ Object
- #__dommy_backend_node__ ⇒ Object
- #__internal_approx_box ⇒ Object
- #__internal_case_sensitive_attribute_names__? ⇒ Boolean
-
#__internal_created_namespace__ ⇒ Object
The [namespace, prefix, local_name] explicitly assigned via createElementNS, or nil when the element wasn't created with an explicit namespace.
-
#__internal_normalize_attr_key__(name) ⇒ Object
Public bridges to the attribute-name case machinery, for NamedNodeMap.
-
#__internal_set_namespace__(namespace, prefix, local_name, qualified_name) ⇒ Object
Record the namespace/prefix/localName an element was created with via createElementNS, so the getters report them faithfully (Nokogiri can't always round-trip a foreign-namespace prefix).
-
#__internal_shadow_root__ ⇒ Object
Internal — gives access to the shadow root regardless of mode.
-
#__js_attribute_snapshot__ ⇒ Object
A plain => value snapshot of ALL attributes, for the JS bridge's per-proxy attribute cache (see host_runtime.js): one crossing answers every subsequent getAttribute/hasAttribute until the DOM epoch moves.
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #__js_set__(key, value) ⇒ Object
-
#__run_click_activation_behavior__(event) ⇒ Object
Run the activation target's activation behavior after a non-canceled click.
-
#__test_scroll_log__ ⇒ Object
Test inspector for scroll calls (no real layout to scroll).
-
#access_key_label ⇒ Object
accessKeyLabel— the assigned access key's platform label. -
#accessibility_tree ⇒ Object
(also: #aria_tree)
The accessibility tree rooted at this element (a synthetic root whose children are this element's accessible nodes).
-
#activation_behavior(_event) ⇒ Object
Activation behavior: the default action of a non-canceled click (a hyperlink navigates; a submit button submits its form — added later).
-
#activation_target ⇒ Object
The activation target for a click on this element: the nearest inclusive ancestor that is an activation target, or nil — so clicking a inside an activates the anchor.
-
#activation_target? ⇒ Boolean
An element is an "activation target" when it carries its own activation behavior (a hyperlink).
- #after(*args) ⇒ Object
-
#anchor_href ⇒ Object
Anchor / area
hrefIDL attribute reflects the attribute resolved against the document base URL (browser semantics). -
#animate(keyframes, options = nil) ⇒ Object
Web Animations: start an animation on this element.
- #approximate_layout? ⇒ Boolean
-
#aria_content_attr(key) ⇒ Object
The content attribute a role/ARIA IDL attribute reflects, or nil for a non-ARIA key.
-
#aria_element_attr(key) ⇒ Object
The content attribute an ARIA element-reference IDL attribute reflects (
ariaActiveDescendantElement→ "aria-activedescendant",ariaErrorMessageElement→ "aria-errormessage"), or nil. -
#aria_element_get(content_attr, key) ⇒ Object
Read an ARIA element reference: an explicitly-set Element wins; otherwise the content attribute is resolved as an IDREF (the element with that id in this element's tree), or null.
-
#aria_element_set(content_attr, key, value) ⇒ Object
Set an ARIA element reference: null/undefined clears it and removes the content attribute; an Element stores the explicit reference and sets the content attribute to the empty string (per the reflection spec).
-
#aria_elements_attr(key) ⇒ Object
The content attribute a plural ARIA element-references IDL attribute reflects (
ariaDescribedByElements→ "aria-describedby",ariaLabelledByElements→ "aria-labelledby"), or nil. -
#aria_elements_current(content_attr, key) ⇒ Object
The current resolved element list for a plural ARIA element reference, or nil when neither explicit elements nor the content attribute are present.
-
#aria_elements_get(content_attr, key) ⇒ Object
Read a plural ARIA element references value (a list of Elements): the explicitly-set array wins; otherwise the content attribute is split as a space-separated IDREF list and each resolved (missing ids dropped).
-
#aria_elements_set(content_attr, key, value) ⇒ Object
Set a plural ARIA element references value: null/undefined clears it and removes the content attribute; an array of Elements is stored and the content attribute is set to the empty string.
-
#aria_find_in_root(id) ⇒ Object
Resolve an ARIA IDREF within this element's tree ROOT (its topmost ancestor) rather than the document — so references keep working when the subtree is disconnected from the document.
-
#aria_get(content_attr) ⇒ Object
Read a reflected nullable DOMString: the content attribute value, or nil (→ JS null) when the attribute is absent.
-
#aria_ref_in_valid_scope?(attr_element) ⇒ Boolean
WHATWG "reflecting element references" scope check:
attr_elementis valid iff its root is this element's root or a shadow-including-ancestor root (reached by hopping each shadow root to its host). -
#aria_set(content_attr, value) ⇒ Object
Write a reflected nullable DOMString: null / undefined removes the content attribute; any other value is ToString-coerced and set.
-
#aria_snapshot ⇒ Object
A Playwright-compatible ARIA snapshot (indented YAML outline) of this element's accessibility subtree.
-
#assigned_slot ⇒ Object
assignedSlot— for a slottable (a direct light-DOM child of a shadow host), the<slot>in the host's open shadow tree it composes into, else null. -
#at_xpath(expression) ⇒ Object
XPath queries scoped to this element, returning wrapped nodes.
-
#attach_shadow(options = nil) ⇒ Object
el.attachShadow({ mode: "open" | "closed" })— creates and attaches a ShadowRoot. -
#attributes ⇒ Object
NamedNodeMap of attributes.
-
#base_uri ⇒ Object
Node.baseURI— resolves against the document's base URL, which in turn honors the first<base href>element (seeDocument#base_uri). -
#before(*args) ⇒ Object
ChildNode mixin — before / after / replaceWith with mixed args.
- #blur ⇒ Object
- #child_element_count ⇒ Object
- #child_nodes ⇒ Object
- #children ⇒ Object
- #class_list ⇒ Object
- #class_name ⇒ Object
- #class_name=(value) ⇒ Object
-
#clear_aria_element_ref_for(content_attr) ⇒ Object
Drop any explicit ARIA element reference (singular or plural) whose content attribute was just set directly (so the IDL getter re-resolves the IDREF).
-
#click ⇒ Object
click()runs the HTML activation behavior around the dispatched event: pre-click activation may change state (e.g. toggle a checkbox), the click is dispatched, and then either the activation behavior runs (not canceled) or the pre-click state is restored (default prevented). - #clone_node(deep_arg) ⇒ Object
- #closest(selector) ⇒ Object
-
#computed_description ⇒ Object
The WAI-ARIA accessible description: aria-describedby / aria-description / title (title only when not already used as the accessible name).
-
#computed_label ⇒ Object
The WAI-ARIA accessible name (WPT's get_computed_label): aria-labelledby / aria-label / native label / name-from-content / title.
-
#computed_role ⇒ Object
The WAI-ARIA computed role (what
getByRole/ WPT's get_computed_role report): an explicit validroleattribute, else the implicit HTML role. -
#contains?(other) ⇒ Boolean
el.contains(other)— true ifotheriselitself or any descendant. - #dataset ⇒ Object
- #element_prefix ⇒ Object
-
#equal_node?(other) ⇒ Boolean
Structural equality — same nodeType, same tagName, same attribute set, and recursively-equal children.
- #first_child ⇒ Object
- #first_element_child ⇒ Object
-
#focus ⇒ Object
focus()— the HTML focusing steps, minus layout: Dommy treats any element as focusable (except a disabled form control), then updates document.activeElement AND fires the focus-change events a real browser would — blur/focusout on the previously focused element, then focus/focusin here, with relatedTarget linking the two. - #get_animations(_options = nil) ⇒ Object (also: #getAnimations)
- #get_attribute(name) ⇒ Object
- #get_attribute_names ⇒ Object
- #get_attribute_node(name) ⇒ Object
- #get_attribute_node_ns(namespace, local_name) ⇒ Object
-
#get_attribute_ns(namespace, local_name) ⇒ Object
----- Namespaced attributes (DOM *AttributeNS) -----.
-
#get_bounding_client_rect ⇒ Object
No real layout engine.
- #get_client_rects ⇒ Object
- #get_elements_by_class_name(name) ⇒ Object
- #get_elements_by_tag_name(name) ⇒ Object
- #get_elements_by_tag_name_ns(namespace, local_name) ⇒ Object
- #get_html(_options = nil) ⇒ Object
-
#get_inner_html(_options = nil) ⇒ Object
getInnerHTML()— happy-dom alias for theinnerHTMLgetter. - #has_attribute?(name) ⇒ Boolean
- #has_attribute_ns?(namespace, local_name) ⇒ Boolean
- #has_attributes? ⇒ Boolean
- #has_child_nodes? ⇒ Boolean
- #hide_popover ⇒ Object
- #id ⇒ Object
- #id=(value) ⇒ Object
-
#initialize(document, nokogiri_node) ⇒ Element
constructor
A new instance of Element.
- #inner_html ⇒ Object
- #inner_html=(value) ⇒ Object
- #insert_adjacent_element(position, element) ⇒ Object
- #insert_adjacent_html(position, html) ⇒ Object
- #insert_adjacent_text(position, text) ⇒ Object
- #insert_before(child, reference) ⇒ Object
-
#insertion_parent! ⇒ Object
The parent that a beforebegin/afterend insertion targets.
-
#is_connected? ⇒ Boolean
(also: #connected?)
Walks parents up to the Document (or false when the chain dead-ends).
- #last_child ⇒ Object
- #last_element_child ⇒ Object
-
#live_child_nodes ⇒ Object
Live NodeList over this element's children.
- #local_name ⇒ Object
-
#mark_fragment_scripts_started(backend_nodes) ⇒ Object
Per the HTML fragment parsing algorithm, a