Brr.ElSourceDOM elements.
The type El.t technically represents DOM Node objects. However most of DOM processing happens on elements. So we make it as if El.t values were just elements and most of the functions of this module will fail on text nodes. Except on El.children where you may see them you'll likely never run into problems. The El.is_txt function can be used to check for textiness.
See Brr.Document.t this is a forward declaration.
See Brr.Window.t this is a forward declaration.
The type for elements. Technically this is a DOM Node object. But we focus on DOM manipulation via elements, not the various kind of nodes that may exist.
v ?d ?at name cs is an element name with attribute at (defaults to []) and children cs. If at specifies an attribute more than once, the last one takes over with the exception of At.class' and At.style whose occurences accumulate to define the final value. d is the document on which the element is defined it defaults Brr.G.document.
txt s is the text s. d is the document on which the element is defined it defaults Brr.G.document. WARNING This is not strictly speaking an element most function of this module will error with this value.
is_txt e is true iff e is a text node. Note that in this cases many of the function below fail.
name e is the tag name of element e lowercased. For is_txt nodes this returns "#text".
txt_text e is the text of e if e is a text node and the empty string otherwise.
See also document element lookups.
els_by_class ~root c are the elements with class c that are descendents of root (defaults to Document.root).
find_by_tag_name ~root n are the elements with tag name t that are descendents of root (defaults to Document.root).
find_first_by_selector ~root sel is the first element selected by the CSS selector sel that is descendent of root (defaults to Document.root).
fold_find_by_selector ~root f sel acc folds f over the elements selected by the CSS selector sel that are descendent of root (defaults to Document.root).
children e are e's children. Warning, unless only_els is true (defaults to false) not all returned elements will satisfy is_el here.
previous_sibling e is e's previous sibling element (if any).
insert_siblings loc e l inserts l before, after or instead of element e according to loc.
set_at a v e sets the attribute a of e to v. If v is None the attribute is removed. If a is empty, this has not effect.
Some attributes are reflected as JavaScript properties in elements see here for details. The following gives a quick way of accessing these properties for elements whose interface which, unlike Brr_canvas.Canvas and Brr_io.Media.El, are not necessarily bound by Brr for the time being (or will never be).
prop p e is the property p of e if defined and false, 0, 0. or Jstr.empty as applicable if undefined.
set_class c b e sets the membership of e to class c to b.
computed_style ?w p e is the computed style property p of e in window w (defaults to G.window).
inline_style p e is the inline style property p of e.
set_inline_style ~important p v e sets the inline style property p of e to v with priority important (defaults to false).
remove_inline_style p e removes the inlie style property p of e.
The inner bound of an element includes its content and padding but not its border. We use the client* properties to get it. These only have integral CSS pixel precision.
inner_x e is the horizontal coordinate in the viewport of e's inner bound. Add Window.scroll_x to get the position relative to the document.
inner_y e is the vertical coordinate in the viewport of e's inner bound. Add Window.scroll_y to get the position relative to the document.
The bound of an element includes its content, padding and border. We use getBoundingClientRect to get it. These have CSS subpixel precision.
bound_x e is the horizontal coordinate in the viewport of e's bound. Add Window.scroll_x to get the position relative to the document.
bound_y e is the vertical coordinate in the viewport of e's bound. Add Window.scroll_y to get the position relative to the document.
scroll_w e is the minimum width the element would require to display without a vertical scrollbar.
scroll_h e is the minimum height the element would require to display without a vertical scrollbar.
scroll_into_view ~align e scrolls e into view. If align_v is `Start (default) the top of the element is align with to to the top of the scrollable area. If align_v is `End the bottom of the element is aligned with the bottom of the scrollable area.
set_has_focus b e sets the focus of e to b in the document it belongs do.
is_locking_pointer e is true if e is the element which locked the pointer.
request_pointer_lock e requests the pointer to be locked to e in the document it belongs to. This listens on the document for the next Ev.pointerlockchange and Ev.pointerlockerror to resolve the future appropriately.
Fullscreen navigation enum.
The type for FullscreenOptions objects.
fullscreen_opts () are options for fullscreen with given parameters.
request_fullscreen e requests to make the element to be displayed in fullscreen mode.
select_text e selects the textual contents of e. If the DOM element e has no select method this does nothing.
Some interfaces are in other modules. See for example Brr_io.Media.El for the media element interface, Brr_canvas.Canvas for the canvas element interface and Brr_io.Form for the form element interface.
The HTML input element interface .
See the MDN HTML element reference.
Convention. Whenever an element name conflicts with an OCaml keyword we prime it, see for example object'.
The type for element constructors. This is simply v with a pre-applied element name.
The type for void element constructors. This is simply v with a pre-applied element name and without children.