Read the statement by Michael Teeuw here.
custom JS file (JQUERY)
-
@cowboysdude
Hi.
I’m using the MMM-MQTT module and I want to change the color of the represented text by MQTT in real-time using JQuery.I wrote the code, but I can’t make it run on MagicMirror web UI
-
@panos in a module, u need to tell M to make those functions available
in a normal js file you would use require(‘js+filename’)
in the module u have to return the names (and paths) of these routine files from the
getScripts() function, which returns an array of namesthen u can use the functions in those files from the modulename.js file functions.
-
For example:
In your main.js file we’ll call it MMM-Whatever.js
// Define required scripts. getScripts: function() { return ["jquery.min.js", "moment.js", "run.js"]; },
That’s one way to to do it.
-
Thanks guys. I did it by modifying MMM-MQTT original code.
The only issue is that everytime that the module will be updated, I must modify it again.
Thanks for your help! -
@panos Hopefully you find another way to do it because that would be frustrating after a while LOL
-
If you have a git hub account you can fork the module’s repo to your own github account and then install/clone it to your modules folder from your own git. Make the change, push it to your remote repo. When there’s an update, you can merge the update with your changed code on github and update the module afterwards. Or not even bother with updates anymore at all, if you want that.