The JavaScript for drupal is generated by drupal_get_js. Not one does it do the preprocessing magic it renders the xhtml output. Since this output is not sent through a theme function it cannot be overriden. The current output is valid xhtml. But, as html5 becomes more popular some will want to change the JavaScript output to be valid html5.
A simple example of the problem....
Currently we have something like:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, { "basePath": "/" });
//--><!]]>
</script>
This is valid xhtml. We actually need the CDATA for the xhtml to validate. This is not the case with html5. Valid html5 markup would look like:
<script>
jQuery.extend(Drupal.settings, { "basePath": "/" });
</script>
The default type for script is text/javascript so we don't even need to specify that (though we could).
The inability to change the markup is a bug we need to fix. Patch to come soon.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | drupal-js-themable-1.patch | 7.52 KB | mfer |
| #2 | drupal-js-themable.patch | 7.51 KB | mfer |
Comments
Comment #1
robloachOh dear god yes.
Comment #2
mfer commentedThis is a companion issue to #576940: links tags which reference css are not themable. There is, also, #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag which I am not opposed to. But, with so little time until D7 is actually frozen for API changes I don't see that one going in.
Comment #3
robloachVery nicely done! So close, a couple small changes and it's good.
I like this change a lot!
Having a NULL argument first looks kind of weird, but it makes sense, since its the contents of the script, and this script tag isn't meant to have anything in it.
"// Set a default value for the type." ;-)
These whitespace changes probably shouldn't be in this patch.
I'm on crack. Are you, too?
Comment #4
mfer commentedHere is an update based on the feedback from Rob Loach.
Comment #5
robloachThe whitespace changes are minor, and they have to happen anyway. RTBCing!
Comment #6
sunwow, erm, now you're trying to sneak in that theme function for links in here?
Comment #7
sunSure, that's a great API design. theme_css(), theme_script(), theme_link(), theme_........
So much time wasted instead of working on the proper solution.
Comment #8
sunFYI: I'm referring to #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag (again).
Comment #9
mfer commented@sun If I thought that issue would get into D7 I would pursue it. But, I find this one to be much more likely. I would rather have this and the css counterpart in core rather than putting all my eggs in the basket of #552478 and have it not go in. This is a simple bug fix which creates a minor change. That is proposing an API change that isn't ready to go yet.
Comment #10
mfer commentedShould the interface to the theme function be a $element array? Like those used in to many other parts of drupal?
The function definition would looke like:
And the input array would look like:
This change would mean the script tag can be used by drupal_render as well.
Comment #11
catchI prefer #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag if we can get it ready.
This should be blowing up massively because all theme functions take a single array now.
Comment #12
mfer commentedPostponing in light of #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag. If that goes in we don't need this one.
Comment #15
aptereket commentedThanks for the patch!
Comment #16
robloach#552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag was committed and added theme_html_tag(), which is now used for both the JavaScript and CSS script tags. This is now considered fixed :-) .