I've created a function which I call inside the "oneditprepare", it works fine but since is rather large and I plan on using it in other nodes, I want to have it in a separate file, so far I've been unable to do this, I've tried adding the file with a script tag just above the one that contains the node definition but it seems node-red does not send the file (the one with my function) to the frontend, I've also tried requiring it in the "functionGlobalContext" but that only makes it available on the server side (js file) and I need it on the front since I'm manipulating the DOM in this function, the last thing I tried was to put the function inside a script tag on a html file, but once again, it seems node-red does not send that either to the front.
Here what I had before (this worked):
my-node.html
<script type="text/javascript">
RED.nodes.registerType('create-issue', {
.
.
.
oneditprepare: function() {
function myVeryLargeFunction() {
// Do stuff here
}
myVeryLargeFunction();
}
.
.
.
});
</script>
Here an example of what I'm trying to accomplish:
my-node.html
<script type="text/javascript">
RED.nodes.registerType('create-issue', {
.
.
.
oneditprepare: function() {
// some kind of require here
myVeryLargeFunction();
}
.
.
.
});
</script>
my-very-large-function.js
function myVeryLargeFunction() {
// Do stuff here
}
Have a look at the geofence node this loads the leaflet script file dynamically to support adding a map to the config dialog.
You have to use jquery's loader to get it to work the example code starts at about line 190.
$.getScript('geofence/js/leaflet/leaflet-src.js')
.done(function(data, textStatus, jqxhr) {
...
})