|
|
|
Olli, for HTML that is not normally needed, but is needed by my JavaScript, my preferred approach is to generate the the HTML in my JavaScript code, and have any necessary CSS already in a stylesheet attached to the page.
For HTML that should be visible normally, but which is irrelevant with JavaScript on, I prefer to use JavaScript to add a class to an element, that triggers a display: none in one of the stylesheets. Therefore, I don't really see the need for what you propose. For now I am just going to do a basic implementation. Ah, yes. I have actually done that in an earlier development, but forgotten about it.
The thing is though, the JS I am talking about still needs to load in the header whether it just toggles a class or loads extra CSS: otherwise, an element, which should only show if the user doesn't have javascript, will flicker at every load of the page.
Just to note it here, too: require_js indeed has a parameter to load js in the header (in order to do what Tim suggests above) even in moodle 2.0, though the default is to load it at the end of the content.
http://docs.moodle.org/en/Development:JavaScript_guidelines#Getting_Moodle_to_load_your_JavaScript_files |
||||||||||||||||||||||||||||||||||||||||||
In moodle quiz UI redesign, I currently have this hack in weblib.php print_header(), and I am not sure, this should probably be done via YUI as the newer versions provide the facilities for dynamically loading things, and they are probably more reliable than some piece of code I cut-and-pasted from http://some.randomurldotcom.
$meta .= <<<EOF
<script>
var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'edit-js.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);
</script>
EOF;