bartbutenaers / node-red-contrib-ui-svg

A Node-RED widget node to show interactive SVG (vector graphics) in the dashboard
Apache License 2.0
94 stars 27 forks source link

Support mutation observers #84

Open bartbutenaers opened 3 years ago

bartbutenaers commented 3 years ago

It might be useful to do something when an attribute value changes. However seems this is only possible by watching the entire DOM tree for changes, using a mutation observer. And since we would have to watch for DOM changes anyway, we could also use this to detect whether elements are added or removed.

Perhaps this could be implemented like this:

  1. A user can specify (in the "Events" and "JS" tabsheets) for which CSS selector the mutation event needs to be detected:

    image

  2. As soon as minimum 1 of such events is used, the client side will add a mutation observer.

  3. When the mutation observer callback is triggered, when can determine whether the target element matches the CSS selector (e.v. via this mechanism on Stackoverflow)

  4. When a match has been found, the specified event handler will be executed.