Hi,
At first, I have follow bellow topic for add external client javascript in created node html file.
Include JS in a html custom module - General - Node-RED Forum (nodered.org)
Include JS in a html custom module - General - Node-RED Forum (nodered.org)
I use RED.httpAdmin.get(...) in created node js file.
RED.httpAdmin.get('/node-line-notify/js/*', function(req, res){
const parentPath = path.resolve(__dirname, '..');
const options = {
root: parentPath + '/static/',
dotfiles: 'deny'
};
res.sendFile(req.params[0], options);
// var filename = path.join(__dirname , 'static', req.params[0]);
// res.sendfile(filename);
});
And I use $.getScript(..) in created node html file at event 'oneditprepare' event, see below
oneditprepare: function () {
.......
$.getScript('node-line-notify/js/emoji-picker-new.js')
.done(function (data, textStatus, jqxhr) {
console.log("load emoji script done");
initEmojiPicker({
trigger: [
{
selector: '.btnEmoji',
insertInto: '.node-input-message'
}
],
closeButton: false,
}, setButtonState);
})
.fail(function (jqxhr, settings, exception) {
console.log("fail load emoji script");
console.log(exception);
console.log(exception.stack);
});
.........
}
The process for load external client javascript is able to work properly.
But I have some problem after that.
My script has load and create new instantiate javasript class object every time when 'oneditprepare', Then my class object has increase everytime.
Is there another solution instead using $.getScript(..) for once add external client javascript in created node html file?
Thank you in advance.