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.
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');
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>
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.
Could it be that regClientScript works only on the front end, not in the manager?
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.
OK, that explains it. I'm using regClientStartupHTMLBlock to insert the javascript link, which DOES work in the manager. Thanks for trying.
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.