Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    UNSOLVED custom JS file (JQUERY)

    Troubleshooting
    4
    8
    331
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      panos last edited by

      Hello.
      Is there a way to run my own javascript on magicmirror?
      I want to run some functions using jquery.
      I was thinking to include my code on config.js (but I’m sure that will break the config file)
      Any suggestions?

      1 Reply Last reply Reply Quote 0
      • cowboysdude
        cowboysdude Project Sponsor Module Developer last edited by

        Running how? In a module? If in a module the you can just include it in your getScripts function…

        P 1 Reply Last reply Reply Quote 0
        • P
          panos @cowboysdude last edited by

          @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

          S 1 Reply Last reply Reply Quote 0
          • S
            sdetweil @panos last edited by

            @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 names

            then u can use the functions in those files from the modulename.js file functions.

            cowboysdude 1 Reply Last reply Reply Quote 0
            • cowboysdude
              cowboysdude Project Sponsor Module Developer @sdetweil last edited by cowboysdude

              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.

              1 Reply Last reply Reply Quote 0
              • P
                panos last edited by

                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!

                cowboysdude 1 Reply Last reply Reply Quote 0
                • cowboysdude
                  cowboysdude Project Sponsor Module Developer @panos last edited by

                  @panos Hopefully you find another way to do it because that would be frustrating after a while LOL

                  1 Reply Last reply Reply Quote 0
                  • D
                    doubleT Module Developer last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Enjoying MagicMirror? Please consider a donation!
                    MagicMirror created by Michael Teeuw.
                    Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                    This forum is using NodeBB as its core | Contributors
                    Contact | Privacy Policy