Statics_Maps certain characters to their entity or special html tag or empty string if it has no use in html
StaticaddCombines UFHtml.addClasses and UFHtml.removeClasses.
Element to add and remove the classes to and from; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case no classes are added.
Css classes separated by a space character; can be null, in that case no classes are removed.
StaticaddAdds a listener to the body element for one or more events. If the target or any of the parents of the target matches the selector, the listener is called. The function returns a callback, which can be called to remove the listener. This method can be used to handle events fired by elements that are dynamically added at a later time.
Selector the target must match.
One or more events to add listener for (separated by space)
A factory function that creates a handler callback for the element. Note that this function is called everytime an event is fired. The function should take as little time as possible.
a function that can be called to remove the listener from the body.
StaticaddAdds css classes in a single string to an element.
Element to add the classes to; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
StaticaddAdds a listener for one or more events. The function returns a callback, which can be called to remove the listener.
Element to add listener to or selector for the element
One or more events to add listener for (separated by space)
Listener callback
a function that can be called to remove the listener from the element for the events.
StaticaddAdds a listener for one or more events to an element or a list of elements. The function returns a callback, which can be called to remove all the listener.
a function that can be called to remove all the added listener from the elements for the events.
StaticassignAssigns a value to a form field element and triggers the "input" and "change" events.
With checkbox/radio elements the following values will set the checked state to true: 'true', '1', 'checked'. Any other value will set the checked state to false.
If the element is not a form field element, nothing happens.
Element to assign to
Value to assign
true if the value could be assigned, false if the element is not a form field.
StaticbuildBuilds a map of data attributes from the element. The method will skip data attributes that start with 'data-uf-'.
The result can be used with UFHtml.copyAttributes.
Element to get data attributes from.
an object where the keys are the attribute names and the values are the attribute enclosed by square brackets.
StaticconvertConverts a html formatted text to a plain text.
Based on code from: https://javascript.plainenglish.io/3-ways-to-convert-html-text-to-plain-text-strip-off-the-tags-from-the-string-4c947feb8a8c
Html text to format
plain version of the text
StaticcopyCopies one or more attribute values to elements. Depending on the type of the element the value gets handled as follows:
input: the checked or value property is set (depending on the type).textarea: the value property is set.select: the value property is set.img: the src property is set.Element to get the attributes from
The field names are used as attribute names and the values are used as selectors for the target elements. If the selector points to multiple elements, each element will get the attribute value.
Optionalcontainer: DocumentFragment | ElementContainer to search the target elements in; if not set, the document is used.
StaticcreateCreates an element by parsing a piece of html.
Html to parse
created element; the element is removed from the document before it is returned.
StaticemptyRemoves all child elements from an element.
Element to remove all children of.
StaticescapeConverts plain text to html by replacing certain characters with their entity equivalent and
replacing \n with
tags.
Based on code from answer: https://stackoverflow.com/a/4835406/968451
Text to convert
Html formatted plain text
StaticfadeFades in an element by setting the styles opacity and transition.
Element to fade in
Duration in millisecond for the fade in transition (default = 400)
StaticfadeFades out an element by setting the styles opacity and transition.
Element to fade out
Duration in millisecond for the fade in transition (default = 400)
StaticfindGets all elements for an attribute.
Attribute name
Attribute value or use null to ignore value
Optionalcontainer: ElementContainer to search the element in; if not set, the document is used.
found elements
StaticfindTries to find an element for an attribute.
Attribute name
Attribute value or use null to ignore value
Optionalcontainer: ElementContainer to search the element in; if not set, the document is used.
found element or null if no element could be found
StaticgetGets an element for a selector. If the selector is an element, it just returns the element.
If the selector is a string, it will try to find the element in the document or container.
If no element can be found or the selector is a null value, the method will throw an error.
Element, selector text or null
Optionalcontainer: ElementContainer to search the element in; if not set, the document is used.
found element
StaticgetGets the value of an attribute.
Element to get attribute from
Name of attribute
Default value to return if no value could be determined (default = '')
the value of the attribute or aDefault if there is no value.
StaticgetGets all attribute names of an element.
Element to get the attribute names from
all the names of attributes defined at the element
StaticgetGets the first parent element of the element that matches the selector.
Element to get the parent (or grandparent or great-grandparent) of
Selector to filter the parent with
the parent element that matches the selector or null if no parent could be found
StaticgetGets an element for an attribute.
If no element can be found the method will throw an error.
Attribute name
Attribute value or use null to ignore value
Optionalcontainer: ElementContainer to search the element in; if not set, the document is used.
found element
StaticgetGets an element for a dom ID and typecast it to a certain type.
If no element can be found, the method will throw an error.
The dom id of element
found element
StaticgetGets all parents of an element.
Element to get all parents for
Optionalselector: stringOptional selector to filter the parents with
all parent elements of the element (parent, grandparent, great-grandparent, etc.)
StatichasChecks if an element has an attribute.
Element to check attribute for
Name of attribute
true if the element has the attribute, false if not.
StatichideHides an element by updating the display style property. The current value is stored in the
element and is used by show. Then the value 'none' is assigned to display style.
Element to hide
StaticinsertInserts an element after another element.
Parent to insert the element in
Element to insert
Element to insert the new element after
StaticisChecks if an element is visible, that it is not hidden by some styling and the element has some size.
Element to check
True to check the parents of the element as well, false to only check the element itself.
true if the element is visible, false if not. Note that if only element itself
is checked, it does not take into account of any parent is not visible.
StaticreloadReloads the current page. It removes the current page from the history and then reloads the page. Any post data is no longer used and the page with the post data is no longer in the history.
StaticremoveRemoves css classes in a single string from an element.
Element to remove the classes from; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
StaticshowShows a element by updating the display style property.
Element to show
Optionaldisplay: stringWhen set use this value, else use the initial value which was copied with hide. If there is no initial value, use 'block'.
StatictoggleToggle css classes in a single string in an element.
Element to add to or remove from the classes; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
Optionalforce: booleanIf true the classes are added, if false the classes are removed, if not set the classes are toggled.
UFHtml implements methods for supporting html and the dom.