We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24374
    • 322 Posts
    I'm trying to write a simple plugin that will run a javascript at the end of manager pages, right before the </body> tag. I'm doing this in order to control the height of various textarea fields (TVs), since there is currently no way to specify this in the TV settings. I have a script that searches for the ID of the field (example: 'tv46') and changes the inline style to the height I want (currently these fields show up with "height=128px"). But I can't get the javascript to show up in the manager pages. I've tried checking off different system events. I've currently got onDocFormPrerender, onDocFormRender, onDocFormSave, and onManagerPageInit checked off.

    I'm using $modx->regClientScript('/js/manager.js'); in the plugin. $modx->regClientStartupHTMLBlock works for me, but that puts the code in the head. I can use a window.onload statement there, but I'm still curious why regClientScript isn't working, since it's supposed to put the code just before the closing </body> tag.
      • 3749
      • 24,544 Posts
      That should work, but you might want to try using a more complete path using one of the MODX constants like MODX_MANAGER_URL or MODX_BASE_URL:

      $regClientScript(MODX_BASE_URL . 'js.manager.js');




        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 24374
        • 322 Posts
        Quote from: BobRay at Dec 01, 2014, 03:28 PM
        That should work, but you might want to try using a more complete path using one of the MODX constants like MODX_MANAGER_URL or MODX_BASE_URL:

        $regClientScript(MODX_BASE_URL . 'js.manager.js');


        Thanks, but still not working after adding MODX_BASE_URL. If I do this:

        $modx->regClientStartupHTMLBlock('<script type="text/javascript" src="'.MODX_BASE_URL.'js/manager.js"></script>');


        it works, but in the head of the web page. [ed. note: rainbowtiger last edited this post 11 years, 9 months ago.]
          • 3749
          • 24,544 Posts
          This seems to work for me:

          $modx->regClientScript(MODX_BASE_URL . 'assets/js/hello.js');



          It produces this just above the final body tag:

          <script type="text/javascript" src="/addons/assets/js/hello.js"></script>
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 24374
            • 322 Posts
            Quote from: BobRay at Dec 02, 2014, 12:31 PM
            This seems to work for me:

            $modx->regClientScript(MODX_BASE_URL . 'assets/js/hello.js');



            It produces this just above the final body tag:

            <script type="text/javascript" src="/addons/assets/js/hello.js"></script>

            What system event(s) do you have checked off? Is this on MODX 2.3.2?
              • 3749
              • 24,544 Posts
              It works for me in 2.3.2 with either OnWebPageInit or OnLoadWebDocument.

              [update] Oops. You wanted it for the Manager, let me try again.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 24374
                • 322 Posts
                Could it be that regClientScript works only on the front end, not in the manager?
                  • 3749
                  • 24,544 Posts
                  Yes, that's what I'm finding. No event works in the Manager that I can find. All the various regClient* calls do is add to $modx->loadedjscripts. I can't find the code where they're actually applied.

                  It might work as a snippet if you put it in a Manager template.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 24374
                    • 322 Posts
                    OK, that explains it. I'm using regClientStartupHTMLBlock to insert the javascript link, which DOES work in the manager. Thanks for trying.
                      • 3749
                      • 24,544 Posts
                      It's very mysterious that that one works and regClientScript() doesn't. They all go in the loadedjscripts array and should all be applied at the same time. Go figure.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting