Hey,

I tried to add a script (http://www.ajaxblender.com/bgstretcher-jquery-stretch-background-plugin....) to my zen subtheme.

- I copied the file bgstretcher.js in the js file in my subtheme's directory
- I added : scripts[] = js/bgstretcher.js in my subtheme's .info file
- I added the script in the head in my page.tpl.php (copied in /template in my subtheme directory):

$(document).ready(function(){ // Initialize Backgound Stretcher $(document).bgStretcher({ images: ['sites/all/themes/mythemename/images/myimage.jpg'], imageWidth: 1200, imageHeight: 937 }); });

Everything seems to be ok in my code : the script apperas in the list of the scripts called when the page is loaded.
But I d'ont have any

created.

I tried to read other issues about adding script in page.tpl.php, talking about drupal_add_js, but I don't think it is related to my issue because with the .info I can call the scripts. Am I wrong ? I think I forgot or misunderstand something.

Can somebody help me.

Thank you.

Comments

akalata’s picture

Status: Active » Postponed (maintainer needs more info)

Have you had any luck? Everything you've posted should work. I haven't used that script, but I've called others (superfish, cufon) in the same manner. One suggestion would be to use an absolute path to your image: images: ['/sites/all/themes/mythemename/images/myimage.jpg'] (note the first "/").

cato’s picture

I have to agree on this issue, my zen subtheme isn't loading added scripts[] either.
I've added a line that reads scripts[] = js/external.js and it simply does not load. There is no errror in the file location, watching the apache log there is no mention of external.js anywhere.

I'm running jquery-ui, jquery-update, admin_menu and a few other modules that could be suspected of tampering with the $scripts variable so the question is if this is a zen issue or if it's actually one of the other modules resetting and overwriting $scripts. I'm not sure.

Scripts from other modules _are_ being loaded though. I guess I'll revert back to including the script in page.tpl.php manually until we have a fix or some more info on this issue.

Thanks,

Christopher Cato
www.christophercato.se

akalata’s picture

@cato - have you rebuilt your theme registry?

cato’s picture

Yes, I've rebuilt theme registry and cleared all caches about a million times. To no effect :/
If there is a test I could run, I'll run it - just give me something to work with.

//Christopher

n8tron’s picture

So scripts are in the js folder, right?

And .info reflects the correct filename of scripts?

scripts[] = js/bgstretcher.js
scripts[] = js/scripts.js

bgStretcher path to image is correct and works in location bar?

Put js/scripts.js

(function ($) {
  $(document).ready( function () {
    $(document).bgStretcher({
      images: ['sites/all/themes/mythemename/images/myimage.jpg'], imageWidth: 1200, imageHeight: 937
    });
  });
})(jQuery);

Maybe try console.log() to test?

shruti.sheth’s picture

r8r8r’s picture

I am actually on zen 7.x-3.0, but this seems to be the same issue.
I agree, there is a problem with js in Zen subthemes, more specific, with jQuery.

I have included
scripts[] = js/ws-script.js
in the .info file.

Its content:

alert('js/ws-script.js loaded');
$(document).ready(function(){
  alert('jQuery loaded');
});

Sure enough, I get a js-alertbox telling me

js/ws-script.js loaded

but not more.

The console throws the following error:

$ is not a function
http://www.MYSITE.dev/sites/all/themes/MYSITE/js/ws-script.js?lk0uul
Line 2

Replacing the code block above with the full jQuery syntax

alert('js/ws-script.js loaded');
jQuery(document).ready(function(){
  alert('jQuery loaded');
});

results in both desired js-alertboxes:

js/ws-script.js loaded

jQuery loaded

Conclusion:
The jQuery shortcut $ is not handled correctly (or "as expected") in subtheme js files. I have not tracked down the reason for this, but maybe someone could do that or post a resolution. In the meantime, avoid using the $-shortcut and read http://wbsl.at/Su for some more information on alternatives and the underlying jQuery behavior.

akalata’s picture

@r8r8r: The jQuery namespace change was actually made in core and has nothing to do with Zen. See http://drupal.org/update/modules/6/7#javascript_compatibility

barraponto’s picture

Version: 6.x-2.0 » 7.x-3.x-dev
Status: Postponed (maintainer needs more info) » Closed (works as designed)

i guess we're done here.

Gik000’s picture

Than?
Do we have to use always "JQuery" instead of "$" in declaration and so on...?

barraponto’s picture