By nadongtae on
This is my problem.
I used Garland theme and I added a block like this $('.mymenu > li ').each(function(index) {alert(1)});
There was no problem when I stayed in admin/build/block.
However the problem happened when I entered the other pages. The firebug alert that it does not understand $('.mymenu > li ').
When I opened the source code and what I saw was
----- some lines for sheetstyle -----
I don't know where they are from because in garland theme there is only print $scripts; .
This is so weird.
After that, I did
In garland.info I added scripts[]=jquery.js
And I got this
----- some lines for sheetstyle -----
Anybody know how to fix this ?
Comments
Post again because missing information
This is my problem.
I used Garland theme and I added a block like this $('.mymenu > li ').each(function(index) {alert(1)});
There was no problem when I stayed in admin/build/block.
However the problem happened when I entered the other pages. The firebug alert that it does not understand $('.mymenu > li ').
When I opened the source code and what I saw was
----- some lines for sheetstyle -----
I don't know where they are from because in garland theme there is only
.
This is so weird.
After that, I did
In garland.info I added scripts[]=jquery.js
And I got this
----- some lines for sheetstyle -----
Anybody know how to fix this ?
The recommended way to add
The recommended way to add js is drupal_add_js()
Interestingly, that does a little magic. If ANY scripts are loaded at all, jquery.js gets loaded first, as well.
If NO scripts are being loaded - jquery doesn't get sent.
This is what happened to you on 'normal' pages. Drupal didn't know that you wanted/expected jquery available.
And yea, adding it to the theme info would be expected to work. I'm not sure if it does however, or if caching may be an issue.
I sometimes set it with drupal_add_js in my template phptemplate_variables()
Or the quick way is to type it into your page.tpl.php HEAD yourself.
In the middle, a safe way will be to call
in your BLOCK code (PHP code) next to where you want to run your scripting.
This means
- it'll always have loaded when you want it
- It won't when you dont'
- it won't double up as drupal_add_js filters dupes.
- your block functionality is still totally independant from any theme hacks.
But about now I'd say make a copy of Garland and work from that before you make any more changes.
And of course TMTOWTDI
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks
Thanks you a lot.
I have another idea that is I will create an empty javascript file such as scripts.js and add it into .info file like this scripts[]=scripts.js. Anh now every page I see jquery.js adding automatically. A cheat but it's ok. Don't worry about missing anymore.
I'm having a similar
I'm having a similar problem. I have some javascript that rotates linked images that I want to add to the front page. The code has internal javascript and and external file but I can't seem to get it to load or work. would I add the internal js into a block with the drupal_add_js code?