• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

custom JS file (JQUERY)

Scheduled Pinned Locked Moved Unsolved Troubleshooting
8 Posts 4 Posters 1.4k Views 3 Watching
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 Offline
    panos
    last edited by Jan 16, 2020, 11:06 AM

    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
    • C Offline
      cowboysdude Module Developer
      last edited by Jan 16, 2020, 12:42 PM

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

      P 1 Reply Last reply Jan 16, 2020, 2:17 PM Reply Quote 0
      • P Offline
        panos @cowboysdude
        last edited by Jan 16, 2020, 2:17 PM

        @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 Jan 16, 2020, 5:53 PM Reply Quote 0
        • S Away
          sdetweil @panos
          last edited by Jan 16, 2020, 5:53 PM

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

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          C 1 Reply Last reply Jan 17, 2020, 1:36 PM Reply Quote 0
          • C Offline
            cowboysdude Module Developer @sdetweil
            last edited by cowboysdude Jan 17, 2020, 1:36 PM Jan 17, 2020, 1:36 PM

            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 Offline
              panos
              last edited by Jan 17, 2020, 5:48 PM

              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!

              C 1 Reply Last reply Jan 17, 2020, 11:04 PM Reply Quote 0
              • C Offline
                cowboysdude Module Developer @panos
                last edited by Jan 17, 2020, 11:04 PM

                @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 Offline
                  doubleT Module Developer
                  last edited by Jan 17, 2020, 11:15 PM

                  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
                  1 / 1
                  • First post
                    8/8
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy