Blockly.utils. dom
Enumeration
NodeType
number
Node type constants. https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
Value |
|
---|---|
ELEMENT_NODE |
|
TEXT_NODE |
|
COMMENT_NODE |
|
DOCUMENT_POSITION_CONTAINED_BY |
Properties
HTML_NS
Required name space for HTML elements.
NodeType
number
Node type constants. https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
Value |
|
---|---|
ELEMENT_NODE |
|
TEXT_NODE |
|
COMMENT_NODE |
|
DOCUMENT_POSITION_CONTAINED_BY |
SVG_NS
Required name space for SVG elements.
XLINK_NS
Required name space for XLINK elements.
Methods
addClass
addClass(element, className) returns boolean
Add a CSS class to a element. Similar to Closure's goog.dom.classes.add, except it handles SVG elements.
Parameter |
|
---|---|
element |
Element DOM element to add class to. Value must not be null. |
className |
string Name of class to add. |
- Returns
-
boolean
True if class was added, false if already present.
containsNode
containsNode(parent, descendant) returns boolean
Whether a node contains another node.
Parameter |
|
---|---|
parent |
Node The node that should contain the other node. Value must not be null. |
descendant |
Node The node to test presence of. Value must not be null. |
- Returns
-
boolean
Whether the parent node contains the descendant node.
createSvgElement
createSvgElement(name, attrs, opt_parent) returns T
Helper method for creating SVG elements.
Parameter |
|
---|---|
name |
(string or Blockly.utils.Svg containing T) Element's tag name. |
attrs |
Object Dictionary of attribute names and values. Value must not be null. |
opt_parent |
Optional Element Optional parent on which to append the element. |
- Returns
-
T
Newly created SVG element. The return type is {!SVGElement} if name is a string or a more specific type if it a member of Blockly.utils.Svg
getFastTextWidth
getFastTextWidth(textElement, fontSize, fontWeight, fontFamily) returns number
Gets the width of a text element using a faster method than getTextWidth
.
This method requires that we know the text element's font family and size in
advance. Similar to getTextWidth
, we cache the width we compute.
Parameter |
|
---|---|
textElement |
Element An SVG 'text' element. Value must not be null. |
fontSize |
number The font size to use. |
fontWeight |
string The font weight to use. |
fontFamily |
string The font family to use. |
- Returns
-
number
Width of element.
getFastTextWidthWithSizeString
getFastTextWidthWithSizeString(textElement, fontSize, fontWeight, fontFamily) returns number
Gets the width of a text element using a faster method than getTextWidth
.
This method requires that we know the text element's font family and size in
advance. Similar to getTextWidth
, we cache the width we compute.
This method is similar to getFastTextWidth
but expects the font size
parameter to be a string.
Parameter |
|
---|---|
textElement |
Element An SVG 'text' element. Value must not be null. |
fontSize |
string The font size to use. |
fontWeight |
string The font weight to use. |
fontFamily |
string The font family to use. |
- Returns
-
number
Width of element.
getTextWidth
getTextWidth(textElement) returns number
Gets the width of a text element, caching it in the process.
Parameter |
|
---|---|
textElement |
Element An SVG 'text' element. Value must not be null. |
- Returns
-
number
Width of element.
hasClass
hasClass(element, className) returns boolean
Checks if an element has the specified CSS class. Similar to Closure's goog.dom.classes.has, except it handles SVG elements.
Parameter |
|
---|---|
element |
Element DOM element to check. Value must not be null. |
className |
string Name of class to check. |
- Returns
-
boolean
True if class exists, false otherwise.
insertAfter
insertAfter(newNode, refNode)
Insert a node after a reference node. Contrast with node.insertBefore function.
Parameter |
|
---|---|
newNode |
Element New element to insert. Value must not be null. |
refNode |
Element Existing element to precede new node. Value must not be null. |
measureFontMetrics
measureFontMetrics(text, fontSize, fontWeight, fontFamily) returns Object
Measure a font's metrics. The height and baseline values.
Parameter |
|
---|---|
text |
string Text to measure the font dimensions of. |
fontSize |
string The font size to use. |
fontWeight |
string The font weight to use. |
fontFamily |
string The font family to use. |
- Returns
-
{height: number, baseline: number}
Font measurements.
removeClass
removeClass(element, className) returns boolean
Remove a CSS class from a element. Similar to Closure's goog.dom.classes.remove, except it handles SVG elements.
Parameter |
|
---|---|
element |
Element DOM element to remove class from. Value must not be null. |
className |
string Name of class to remove. |
- Returns
-
boolean
True if class was removed, false if never present.
removeClasses
removeClasses(element, classNames)
Removes multiple calsses from an element.
Parameter |
|
---|---|
element |
Element DOM element to remove classes from. Value must not be null. |
classNames |
string A string of one or multiple class names for an element. |
removeNode
removeNode(node) returns Node
Removes a node from its parent. No-op if not attached to a parent.
Parameter |
|
---|---|
node |
Node The node to remove. |
- Returns
-
Node
The node removed if removed; else, null.
setCssTransform
setCssTransform(element, transform)
Sets the CSS transform property on an element. This function sets the non-vendor-prefixed and vendor-prefixed versions for backwards compatibility with older browsers. See https://caniuse.com/#feat=transforms2d
Parameter |
|
---|---|
element |
Element Element to which the CSS transform will be applied. Value must not be null. |
transform |
string The value of the CSS |
startTextWidthCache
startTextWidthCache()
Start caching text widths. Every call to this function MUST also call stopTextWidthCache. Caches must not survive between execution threads.
stopTextWidthCache
stopTextWidthCache()
Stop caching field widths. Unless caching was already on when the corresponding call to startTextWidthCache was made.