@tve/node-red-fd-html
v0.1.12
Published
Node-RED nodes to produce HTML and SVG widgets for Flexdash
Downloads
25
Readme
Node-RED FlexDash SVG
FlexDash HTML widget
This node & widget displays raw HTML in FlexDash and allows a Node-RED flow to alter the HTML via messages.
Messages may have the following fields:
payload
- a string containing HTML to replace the entire contents of the widgetselector
- a CSS selector to select elements to operate oncommand
- a string containing a command to execute on the selected elements, see belowargs
- an array of arguments to pass to the commandcommands
- an array of commands to execute, each element must contain acommand
anargs
field and optionally aselector
field (the latter defaults to the HTML root!)
The fields are processed in the following order: first html
, then selector
, command
and args
, then commands
.
Selectors
Standard selectors for ID (#id
), class (.class
) and attribute ([attr]
or [attr=value]
)
are supported. The
(space) combinator is supported, other combinators are not.
When an array of commands is specified, the selector
field may have the value .
to refer to
the same elements as the previous command in the same message.
HTML elements in arguments
Some commands, such as append
and prepend
, take HTML elements as arguments.
These must be Javascript objects with fields tag
(the tag name), attrs
(the
attributes including id
and class
if desired) and optionally children
(an array of child
elements) or text
(the text content of the element).
Elements with text
must have a tag of span
and no children.
Command list
The commands are loosely patterned after JQuery.
Commands that return something should output a message but currently don't
id
- set the ID of the element toargs[0]
addClass
- addargs[...]
to the classes of the elementhasClass
- check whether any of the elements has classargs[0]
, returns a booleanremoveClass
- removeargs[...]
from the classes of the elementattr
- ifargs.length==1
return an array with the values of the attributeargs[0]
for each selected element, ifargs.length==2
set the attributeargs[0]
to the valueargs[1]
for each elementhasAttr
- check whether any of the elements has attributeargs[0]
, returns a boolean (doesn't exist in JQuery)text
- ifargs.length==0
get the "inner text" of the selected elements (concatenated), else set the "inner text" of the selected elements toargs[0]
creating span elements, which is equivalent to bare text in HTML (currently there is no escaping done of<
, but that will be added...)html
- set the "inner HTML" of the selected elements toargs[0]
, i.e., parse the HTML and set the resulting elements as children of the selected elementsappend
- append elementsargs[0...]
to each of the selected elementsprepend
- prepend elementsargs[0...]
to each of the selected elementsempty
- remove all children of the selected elementsremove
- remove the selected elementsreplaceWith
- replace the selected elements with elementsargs[0...]