Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It would be good to have the conditional comments feature extend to scripts in the .info file.
For example the script for DD-belatedPNG to fix issues with the IE6 transparency and should only be called for IE6. http://www.dillerdesign.com/experiment/DD_belatedPNG/
Comment | File | Size | Author |
---|---|---|---|
#31 | conditional_styles-639288.patch | 1.09 KB | xurizaemon |
#30 | conditional_scripts7.tar_.gz | 755 bytes | Bedstvie |
#4 | conditional_scripts.patch | 3.56 KB | jdanthinne |
#3 | conditional_scripts.patch | 3.4 KB | nairb |
Comments
Comment #1
Standart CreditAttribution: Standart commentedExactly the same use case here.
Comment #2
JohnAlbinI'd consider this. Especially if someone else wrote the patch. :-D
Comment #3
nairb CreditAttribution: nairb commentedI modified 6.x-1.x-dev to include conditional script support. I am including a patch. See what you think.
Here is the formatting in my theme.info:
; Set the conditional scripts that are processed by IE.
conditional-scripts[if IE 6][] = js/DD_belatedPNG_0.0.8a-min.js
conditional-scripts[if IE 6][] = js/ie6.js
Brian
Comment #4
jdanthinne CreditAttribution: jdanthinne commentedPatch is working fine for me.
Modified it to be able to include extrernal scripts as well.
Comment #5
gmclelland CreditAttribution: gmclelland commentedTested both patches. Both patches applied, but had no effect.
Not sure why, but I couldn't get the js to load.
Here is the link in my .info file
conditional-scripts[if IE 6][] = "js/pngfix-1.1/jquery.pngFix.js"
Used the latest 6.x-1.x-dev version.
I am using the TAO theme as my base theme.
Comment #6
gmclelland CreditAttribution: gmclelland commentedI think my problem isn't the patches, it's that the conditional styles module simply doesn't work with TAO. Anyone have any suggestions on how to fix it?
I tried adding $var['styles'] .= $var['conditional_styles']; inside function tao_preprocess_page
Thanks
Comment #7
nairb CreditAttribution: nairb commentedThrew TAO on my dev site and got it working...
Use jdanthinne's patch. He also fixed a var that I missed. :)
For your preprocess, use 'vars' instead of 'var':
$vars['styles'] = drupal_get_css($css);
$vars['styles'] .= $vars['conditional_styles'];
Make sure the conditional css/js files exist too, the module checks.
Brian
Comment #8
nairb CreditAttribution: nairb commentedComment #9
gmclelland CreditAttribution: gmclelland commentedHi @nairb, thanks for the help. I tried adding
function tao_preprocess_page(&$vars) {
$vars['styles'] = drupal_get_css($css);
$vars['styles'] .= $vars['conditional_styles'];
to my template.php, but then my page renders really funky looking. It's almost as if the styles weren't processed by the Scaffold module. Maybe there is some kind of conflict? Even with the messed up page I checked the view source in IE 6 and it didn't include my conditional script.
I also double checked the paths to my js files as specified in the .info file.
When I remove the code from the template.php everything goes back to working fine.
Any suggestions, I would love to get this working.
Comment #10
gmclelland CreditAttribution: gmclelland commentedFYI.. I'm using the 1.x branch of Scaffold. It looks like this issue might be what is causing the problem:
http://drupal.org/node/885056
Possible fix, but I couldn't get it to work when I combine your code with what is provided.
http://drupal.org/node/885056#comment-3390290
Comment #11
gmclelland CreditAttribution: gmclelland commented@nairb - Does it matter that TAO outputs the scripts at the bottom of the page?
Should it be $vars['scripts'] since it is a script that needs to be outputted with the $scripts variable not the $styles variable?
or maybe it should be $vars['conditional_scripts'] ?
Also, I read that function _scaffold_get_css($css = NULL) is the replacement of drupal_get_css()
So technically I should be able to this:
function tao_preprocess_page(&$vars) {
$vars['styles'] = _scaffold_get_css($css);
$vars['styles'] .= $vars['conditional_styles'];
Seems like the code above would just make TAO + conditional_styles module play nicely together, but not javascripts. Am I wrong?
Comment #12
gmclelland CreditAttribution: gmclelland commentedTried this, but it didn't seem to work. FYI.. I am clearing all caches before I check the results
function cmftao_preprocess_page(&$vars) {
$vars['styles'] = _scaffold_get_css($css);
$vars['styles'] .= $vars['conditional_styles'];
$vars['scripts'] = drupal_get_js();
$vars['scripts'] .= $vars['conditional_scripts'];
Comment #13
nairb CreditAttribution: nairb commentedYou only need to add the additional line to the preprocess_page function for the css styles because the Tao theme modifies their media attribute, otherwise the module handles everything automatically. That line will appended the conditional styles once Tao is done making changes. Tao does nothing with the js, so there is no reason to add those lines to the preprocess_page.
#11 sounds plausible but without testing I do not have knowledge of how the module works.
I would begin testing by eliminating as many possible variables as you can. Start with Tao and Conditional Comments only, remove anything else that may modify css/js file. If you can get that working, then try adding Scaffolding.
Comment #14
gmclelland CreditAttribution: gmclelland commentedI disabled the Scaffold module.
I only placed:
$vars['styles'] = drupal_get_css($css);
$vars['styles'] .= $vars['conditional_styles'];
into my preprocess_page
The conditional stylesheets show up in my webpage correctly, but I can't get the conditional scripts to output. All my other non-conidtional js files output correctly.
I used devel to check the conditional scripts variable and it did have the correct conditional javascript file specified with the correct paths, but for some reason it simply won't output into the page.
Any other suggestions? Thanks for your help. I will continue to test.
Comment #15
puya CreditAttribution: puya commentedThis is really useful. Could you please commit this to head?
Comment #16
puya CreditAttribution: puya commentedOh and is the patch in the dev version or do I still need to patch the dev?
Comment #17
puya CreditAttribution: puya commentedoops .. looks like the #4 patch broke my site :
Notice: Undefined index: arguments in /.../includes/theme.inc on line 318
Comment #18
nairb CreditAttribution: nairb commentedIf anyone has been having problems with this patch or the module in general, I have come to a couple conclusions... it will break when you use a module that modifies $scripts, such as jQuery Update. The $scripts and $styles variables should be modified through the api or .info file, not added as a string on the end as this is doing.
Looking at this issue, the conditional scripts could be thrown in $head but I don't really like that idea, as I prefer the conditional css and js to be added below their respective sections.
The option I am currently testing, is to use the patch above, remove the portion that updates the $styles/$scripts, and insert the $conditional_styles/$conditional_scripts variables into my template where I want them. It would be nice to automate this process, so you could just activate the module and be done but I do not see how that could be achieved.
Comment #19
JohnAlbinI've been playing around with some code in the D7 version to get conditional comment-wrapped scripts to work. This suddenly became important to me since the HTML5 shim requires it.
Comment #20
klonosReally interesting feature! I have no use for it right now, but I'm sure it will come handy someday ;)
Comment #21
muschpusch CreditAttribution: muschpusch commentedsubscribe!
Comment #22
fonant CreditAttribution: fonant commentedThis would be nice!
Comment #23
betovargSubscribing. Any intentions in getting this one into the actual module, without a patch? thnx!
Comment #24
loopy1492 CreditAttribution: loopy1492 commentedI'd like this for Drupal 7.
Comment #25
nairb CreditAttribution: nairb commentedThat's great but this is a 6.x issue.
Comment #26
klonosI don't like to impose here, but it is accustomed for features to go against latest version first and then backported. So, changing it to 7.x is more of a "procedural" thing - it doesn't mean it won't happen for 6.x too. Besides, this issue hasn't seen any action recently and it's more likely that by the time this gets implemented, most of us will already be using D7. Also, if you take a look back at #19, John (the maintainer of this module) seems to be playing around with a 7.x version.
I won't join the change-issue-version game though :P
Comment #27
loopy1492 CreditAttribution: loopy1492 commentedOkaaaaaay. I guess I'll just copy this issue.
Comment #28
klonos...that's not the way either. I'm sure that the issue you'll file will eventually be closed as duplicate of this one. The process of getting things done is as I described: first in latest branch, then backported. Switching an issue to a version/branch or another won' get anybody any attention. Specifically for this issue, it is pointless since the module maintainer already clearly stated that he's working on it in the 7.x branch.
Comment #29
JohnAlbinWe can work on both D6 and D7 in the same issue. :-)
The patch for D6 needs work. There is no patch for D7. When you post a patch just mention which version its for.
Thanks!
Comment #30
Bedstvie CreditAttribution: Bedstvie commentedComment #31
xurizaemonAdds support for
scripts-conditional[]
-style entries in theme .info, as per existing config.Probably don't need to be able to add JS for print mode (do we?) but there you go.
EDIT: This patch (and the tarball above it) aren't complete, because drupal_add_js() doesn't handle the
$options['browsers']
parameter that drupal_add_css() does. So your conditional scripts will be applied to all browsers anyway.On reflection, conditional scripts aren't such a good idea IMO, and I'd encourage using conditionals in the JS instead of this approach.