Documentations › mmo.client › js › core dom MMO.core.dom · 73 symboles · générée le 27 Oct 2026
MMO.core.dom.BOOL_ATTRIBUTES = ['disabled', 'readonly', 'required', 'checked']; Espace de noms MMO.core.domMMO.core.dom.MERGEABLE_NODES = ['A', 'ABBR', 'AREA', 'AUDIO', 'B', 'BDI', 'BDO', 'BR', 'BUTTON', 'CANVAS', 'CITE', 'CODE', 'DATA', 'DATALIST', 'DEL', 'DFN', 'EM', 'EMBED', 'I', 'IFRAME', 'IMG', 'INPUT', 'INS', 'KBD', 'LABEL', 'MARK', 'MATH', 'METER', 'LINK', 'MAP', 'META', 'NOSCRIPT', 'OBJECT', 'OUTPUT', 'PICTURE', 'PROGRESS', 'Q', 'RUBY', 'S', 'SAMP', 'SCRIPT', 'SELECT', 'SLOT', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'SVG', 'TEMPLATE', 'TEXTAREA', 'TIME', 'U', 'VAR', 'VIDEO', 'WBR']; Espace de noms MMO.core.domCall query selector.
function MMO.core.dom.$(node, root = null, searchParent = true) Espace de noms MMO.core.domRoot is used to select elements into a shadowdom node Element | stringroot = null Elementa node use as reference to get root document or shadowroot from. searchParent = true Booleanif root is defined but no element are found, search in the document retourne Element | null
Call query selectorAll
function MMO.core.dom.$$(selector, root = null, searchSlot = true) Espace de noms MMO.core.domselector root = null Elementa node use as reference to get root document or shadowroot from. searchSlot = true Booleanif root is a shadow root, search in the slot retourne Array
Make every form control inside a node read-only, or writable again.
function MMO.core.dom.readonly(node, value) Espace de noms MMO.core.domCheckboxes and radios have no `readonly` state of their own, so they are disabled instead. node Nodevalue booleantrue to lock, false to unlock
Create a dom element from a configuration
function MMO.core.dom.createElement(node, attrs = null, ...children) Espace de noms MMO.core.domnode attrs = null Array | Function | object: - an object of attributes to set ({key: value}) - a Function(element) that returns an object - an Array of the above ...children ...*MMO.core.dom.appendChildren. A string is TEXT, never markup: a file's name shows as it was typed. Markup you wrote goes through MMO.core.dom.htmlretourne Node
MMO.core.dom.createElement('li', {class: 'file'}, MMO.core.dom.createElement('mmo-icon', {name: 'file'}), file.name)
function MMO.core.dom.createElementNS(namespace, tag, attrs = null, ...children) Espace de noms MMO.core.domVoir MMO.core.dom.createElement in an explicit xml namespace (svg, MathML, ...).namespace stringMMO.core.dom.NAMESPACE_URIStag stringattrs = null ?(Object | Function | Array)...children ...*MMO.core.dom.appendChildren: a string is textretourne Element
Create a custom event and dispatch it
function MMO.core.dom.dispatchEvent(node, name, detail = undefined, cancelable = true, bubbles = true) Espace de noms MMO.core.domnode Elementname stringEvent's name detail = undefined objectuser defined detail to pass to the handlers cancelable = true bubbles = true retourne boolfalse if at least one handler call preventDefault
Loop through all text nodes inside a node
function* MMO.core.dom.loopTextNodes(node) Espace de noms MMO.core.domnode Nodethe node to use retourne Generator<Text>
function MMO.core.dom.getTextNodes(node) Espace de noms MMO.core.domnode Noderetourne Array<Text>every text node inside, in document order
function MMO.core.dom.firstTextNode(node) Espace de noms MMO.core.domnode Noderetourne ?Textthe first text node inside, null when there is none
Tells if two nodes can be merged: they have the same type and the same attributes and they are part of the list MMO.core.dom.MERGEABLE_NODES or they are Text nodes
function MMO.core.dom.isMergeableNode(a, b) Espace de noms MMO.core.domMerge child nodes if they are mergeable
function MMO.core.dom.normalize(node) Espace de noms MMO.core.domCreate script
function MMO.core.dom.createScript(url, inline = false) Espace de noms MMO.core.domurl stringthe script url or the script text inline = false booleanif true, url should be the script text retourne Scriptthe added script
Include script in html <head> or in a node
async function MMO.core.dom.includeScript(url, inline = false, parentNode = null) Espace de noms MMO.core.domurl stringthe script url. if it starts with ':', it is resolved with MMO.url inline = false booleanif true, url should be the script text parentNode = null retourne ScriptElementthe added script
Create style
function MMO.core.dom.createStyle(url, inline = false) Espace de noms MMO.core.domurl stringthe style url inline = false booleanif true, url should be the style text retourne stylethe added style
Include style in html <head> or in a node
function MMO.core.dom.includeStyle(url, inline = false, parentNode = null) Espace de noms MMO.core.domurl stringthe style url. if it starts with ':', it is resolved with MMO.url inline = false booleanif true, url should be the style text parentNode = null retourne StyleElementthe added style
function MMO.core.dom.getFocusableElements(node = null) Espace de noms MMO.core.domThe focusable element sitting just before a node in the document's tab order.
function MMO.core.dom.getPreviousFocus(node) Espace de noms MMO.core.domnode Elementretourne ?Elementnull when the node is the first one, or is not focusable itself
The focusable element sitting just after a node in the document's tab order.
function MMO.core.dom.getNextFocus(node) Espace de noms MMO.core.domnode Elementretourne ?Elementthe LAST focusable element when the node is last, or is not focusable
Get the text position a pointer event landed on, across the three browser apis.
function MMO.core.dom.getMouseEventCaretRange(evt) Espace de noms MMO.core.domevt MouseEventretourne ?Rangea collapsed range, or undefined when no api is available
function MMO.core.dom.selectRange(range) Espace de noms MMO.core.domYield node selected in a range
function* MMO.core.dom.loopRangeNodes(range) Espace de noms MMO.core.domrange retourne Generator<[Node node, ?number startOffset, ?number endOffset)>
function MMO.core.dom.getRangeNodes(range) Espace de noms MMO.core.domrange Rangeretourne Array<[Node, ?number, ?number]>MMO.core.dom.loopRangeNodes
function MMO.core.dom.firstNodeInRange(range) Espace de noms MMO.core.domrange Rangeretourne ?Nodethe first node the range touches
Check if first text element in a node is wrapped in a tag
function MMO.core.dom.isWrapped(node, tagName, attrs = null) Espace de noms MMO.core.domnode NodetagName stringattrs = null object | nullif specified, check all attributes are set to the given values retourne boolean
Toggle wrapping text content in a selection.
function MMO.core.dom.toggleRangeTextWrapping(range, tagName, attrs = null) Espace de noms MMO.core.domExample toggle bold/italic/underline in a selection range tagName attrs = null object | nullif specified, apply attributes to the wrapper
Set element attributes
function MMO.core.dom.setAttributes(node, attrs) Espace de noms MMO.core.domnode attrs array | Function | Object- Function: function(node): value - Object: set the attributes with key,value - array: a list of the above retourne void
Test if element has the given attribute's values
function MMO.core.dom.hasAttributes(node, attrs, full = false) Espace de noms MMO.core.domnode Elementattrs objectfull = false booleanif true, check that the node has only and all the given attributes retourne boolean
Set element attribute
function MMO.core.dom.setAttribute(node, name, value) Espace de noms MMO.core.domnode name stringthe attribute's name value string | Function- Function: calls is with element as only argument retourne void
Get element attributes as an object
function MMO.core.dom.getAttributes(node) Espace de noms MMO.core.domnode Elementretourne Object
Get root HTML
function MMO.core.dom.root(node) Espace de noms MMO.core.domThe custom element owning the shadow root a node lives in.
function MMO.core.dom.host(node) Espace de noms MMO.core.domnode Noderetourne ?Elementnull when the node is not inside a shadow root
The parent element, crossing a shadow boundary to the host rather than stopping at it.
function MMO.core.dom.parentElement(node) Espace de noms MMO.core.domfunction MMO.core.dom.body(node) Espace de noms MMO.core.domnode Noderetourne HTMLElementthe body of the document the node belongs to
Test whether a node descends from another.
function MMO.core.dom.hasParent(node, parent, max = false) Espace de noms MMO.core.domnode Nodeparent Nodemax = false number | falsestop after this many levels retourne booleanfalse when node === parent: only ancestors count
Walk up until a node carries a given tag name. The node itself is a candidate.
function MMO.core.dom.closestParent(node, tagName) Espace de noms MMO.core.domNOTE: this does NOT cross shadow boundaries. node NodetagName stringcase insensitive retourne ?Element
Detach a node, or every node of a NodeList.
function MMO.core.dom.remove(node) Espace de noms MMO.core.domnode ?(Node | NodeList)retourne booleanfalse when there was nothing attached to remove
Mark markup to be parsed by the functions building nodes from children (MMO.core.dom.appendChildren,
function MMO.core.dom.html(html) Espace de noms MMO.core.domVoir MMO.core.dom.createElement, MMO.core.Template#add), which insert a plain string as text.Only for markup you wrote, or sanitized: it is parsed with `innerHTML`, so an `<img onerror>` in it runs. Never
wrap a name, a label or a message that came from a user or an api.
An array has each of its strings marked; anything else (a node, null...) is returned as it is, so a value
that may be a node or a string of markup can be handed over either way. html *retourne *a MMO.core.dom.Html for a string
MMO.core.dom.createElement('p', {}, MMO.core.dom.html('<b>Saved</b> in '), folder.name)
Add children to a node using a generator
function* MMO.core.dom.loopAppendChildren(node, ...children) Espace de noms MMO.core.domnode Elementthe node in which to add children ...children ...*MMO.core.dom.appendChildrenretourne Generator<Node>
Add children to a node.
function MMO.core.dom.appendChildren(node, ...children) Espace de noms MMO.core.domA string -- or a number, or anything that is not a node -- is inserted as TEXT, never parsed: a name or a
message shows as it was typed, `<b>` included, and runs nothing. Markup goes through `MMO.core.dom.html`,
and only markup you wrote or sanitized. node Elementthe node in which to add children ...children ...*each one can be: - a Node, a NodeList, a DocumentFragment, or a <template> (its content is cloned) - MMO.core.dom.html('...'): markup, parsed - an array, or a MMO.core.Map list, of any of these - null or undefined: skipped, and so is an empty string - anything else: its text retourne Array<Node>
MMO.core.dom.appendChildren(li, icon, file.name, MMO.core.dom.html(' <small>(new)</small>'))
Detach a list of nodes, flattening nested arrays and skipping null entries.
function MMO.core.dom.removeChildren(...children) Espace de noms MMO.core.dom...children ...(?Node | Array)
Parse html and add it to a node.
function MMO.core.dom.addHTML(node, html) Espace de noms MMO.core.domThe markup runs: only hand it what you wrote or sanitized. Text goes through `MMO.core.dom.appendChildren`. node Elementhtml stringretourne Array<Node>the nodes parsed, in order
Insert an Element inside a text element
function MMO.core.dom.insertNodeInText(text, node, offset, size = 0) Espace de noms MMO.core.domtext Textnode Element[description] offset Numberthe offset to insert the element at size = 0 Numberthe size to remove after offset (replaced by the element)
Insert a node just after another one.
function MMO.core.dom.insertAfter(node, ref) Espace de noms MMO.core.domnode Nodethe node to insert ref Nodethe node to insert after retourne Nodethe inserted node
Get the Element from which a fixed element has his position computed. If null, it is the viewport.
function MMO.core.dom.fixedNode(node) Espace de noms MMO.core.domOnly an ancestor with a 'transform', 'perspective', 'filter', 'backdrop-filter', a layout or paint
'contain', or a 'will-change' of one of them is such a containing block; 'position: fixed' or 'sticky'
is not (taking a sticky bar for one threw a dropdown opened in it to the top of the page). The walk
crosses shadow roots, since a fixed element in a shadow tree is still placed against its host's ancestors. The parent of a node in the flattened tree: its parent element, or the host of the shadow root it sits in.
function MMO.core.dom.composedParent(node) Espace de noms MMO.core.domfunction MMO.core.dom.getComputedStyle(node, property = null, pseudo = null) Espace de noms MMO.core.domnode property = null pseudo = null
Copy every COMPUTED style of a node onto another as inline styles, so the copy keeps its look once detached from the stylesheets that produced it.
function MMO.core.dom.copyStyles(nodeA, nodeB, pseudo = null) Espace de noms MMO.core.domnodeA Elementthe source nodeB Elementthe target pseudo = null ?stringread a pseudo element of the source instead (':before', ...)
Get the node's font-size in pixels (the value 1em resolves to).
function MMO.core.dom.getEmValue(node) Espace de noms MMO.core.domnode Elementretourne number
Get a computed style and convert it to a number (interpreting the unit)
function MMO.core.dom.getComputedStyleValue(node, property, pseudo = null) Espace de noms MMO.core.domnode [type][description] property [type][description] pseudo = null [type][description] retourne [type][description]
Convert any css string value into a float
function MMO.core.dom.decodeUnit(node, value, em = null, percent = 1) Espace de noms MMO.core.domnode value *any value if string will try to read the unit and convert into a float em = null numberif value is em, will use this value as reference percent = 1 numberif value is percent, will use this value as reference retourne number | stringif value is a percent value, returns a string version of the number
Make sure a value is a properly formed css value with the correct unit
function MMO.core.dom.encodeUnit(node, value = 0, unit = null, percent = 1) Espace de noms MMO.core.domnode value = 0 string | number[description] unit = null string | number | null('px','em','rem') unit to use by default, or another value. In that case, unit is percent percent = 1 retourne string
Set css styles
function MMO.core.dom.setStyles(node, styles) Espace de noms MMO.core.domQueue style update in animation frame
function MMO.core.dom.setStyle(node, key, value) Espace de noms MMO.core.domnode Elementkey stringstyle name value *style value
Update queue styles in given node
function MMO.core.dom.updateStyles(node) Espace de noms MMO.core.domSet css styles
function MMO.core.dom.getStyle(node, key) Espace de noms MMO.core.domGet the element's absolute coordinates (left, top) using offset and scroll
function MMO.core.dom.getCoord(node, root = null) Espace de noms MMO.core.domnode root = null retourne x: number, y: number}
Get bounding rect relative to a parent
function MMO.core.dom.getBoundingRect(node, parent = false) Espace de noms MMO.core.domnode parent = false Element | booleanif true, use direct parent. if false get absolute bounding rect retourne x,y,width,height}
Convert an absolute document point into one relative to a node's box.
function MMO.core.dom.makeRelative(node, pt, copyPt = true) Espace de noms MMO.core.domnode Elementpt copyPt = true booleancarry the point's other properties over to the result retourne x: number, y: number} a new object; pt is never modified
Tells if a point is inside a container
function MMO.core.dom.ptInside(node, x, y) Espace de noms MMO.core.domCheck if element is visible
function MMO.core.dom.isVisible(elem) Espace de noms MMO.core.domelem Elementretourne Boolean
Get a promise waiting for an element to become visible
function MMO.core.dom.waitUntilVisible(node, opts) Espace de noms MMO.core.domnode Elementto watch opts Objectthe options to pass to the IntersectionObserver retourne Promise<IntersectionObserverEntry>
function MMO.core.dom.setBoundingRect(node, rect) Espace de noms MMO.core.domSet the current offset of the element
function MMO.core.dom.setOffset(node, x, y = null) Espace de noms MMO.core.domnode x y = null null | number[description] retourne MMO.core.Elementthis
Move the element
function MMO.core.dom.addOffset(node, x, y) Espace de noms MMO.core.domSet a node's width and height, queued like every other style write.
function MMO.core.dom.setSize(node, w, h) Espace de noms MMO.core.domA negative value is clamped to 0, and a falsy one clears the style. node Elementw h number=the height, when w is a number
Get a unique css selector for a node It is usefull to have a visual path for a node, but it should not be used to retrieve the node. Use getPath instead.
function MMO.core.dom.getCSSPath(node, root = null) Espace de noms MMO.core.domnode Noderoot = null Nodethe root node to get path from. If null, use document body retourne string
Get a unique path for node as indexes in childnodes WARNING: the path is reversed, so iteration starts from length-1 and not 0
function MMO.core.dom.getPath(node, root = null) Espace de noms MMO.core.domnode Noderoot = null Nodethe root node to get path from. If null, use document body retourne stringfalse if the root node was not found
Get a node from its path
function MMO.core.dom.at(node, path) Espace de noms MMO.core.domnode Nodepath stringthe return value of (MMO.core.dom.getPath()) retourne Node
This function allow a checkbox to cycle through 3 states: checked, unchecked, indeterminate.
function MMO.core.dom.onIndeterminateClick(event) Espace de noms MMO.core.domIt is meant to be used in the onclick attribute: `<input type="checkbox" onclick="MMO.core.dom.onIndeterminateClick(event)" />`