I've got a cool javascript-driven animation that I'd like to use as the background for all of my theme's h1 tags. How would I go about automatically inserting the js into the tags?
Kimber
I've got a cool javascript-driven animation that I'd like to use as the background for all of my theme's h1 tags. How would I go about automatically inserting the js into the tags?
Kimber
I am not sure your users will thank me for helping you add a "cool animation" everywhere, but ...
The general technique in http://docs.moodle.org/dev/Themes_2.0_overriding_a_renderer can be used to change how Moodle outputs h1s (modify the $OUTPUT->heading method).
Alternatively, you could write some JavaScript that runs in the browser and attaches the admination to every h1. (Y.all('h1').each(...)). Then you would just need to get that JavaScript run on every page ($PAGE->requires->js_init_call somewhere in your layout template.)
What Tim says is the best way, however, I would like to know why Javascript? What exactly does this animation do and how much script is involved?
Cheers
Mary
It's an animation of balls that move away from the user's mouse. The user will have to deliberately interact with them to create any movement, and I promise it's appropriate for the context. The script is approximately 30 lines.
My question was probably oversimplified. I really only want to target h1s in the #region-main section, and probably only on the course main page. Can I be that specific when overriding a renderer?
I can call the Javascript from within the label containing the h1 when I create the course, but I can't expect the teacher to be able to do the same thing if she adds another h1. That's why I'd like to build it in if it's practical. Thanks for your help!
Hi Kimber,
Try this...
In the theme you are using or want to use, add a directory and name it javascript and then add the javascript to it providing the javascript is just that and NOT the <script></script> tags as those are not needed. You just need the raw code itself. If your Javascript code does not have a name well make one up, call the file animate.js
That done you need to tell Moodle that you want to use a Javascript file called 'animate' and call it from the footer of the page. To do this you need to add this line to your theme's config.php
like so...
$THEME->javascripts_footer = array('animate');
That done, next you need to tell Moodle where you want the animate script to be triggered. It's this part that could be easy or difficult depending on the way the script works.
I need to know more about the script to explain more.
Mary