I have been trying various methods to put javascript into my theme. I just want to have some rotating images on the front page. I tried putting the internal js into page-front.tpl.php and I tried putting it all into a block and having it only show up on the front page. I declared the file on my .info file Really nothing works.

THe js I want to use has internal and external js.
So I read reading here: http://drupal.org/node/171213. It says that the theme folder needs a script.js file that is automatically included. Where do I look to find this file. I can't find it anywhere in any of my directories. I was thinking that maybe the js isn't working becuase of this issue.

Honestly, I've been reading so many posts on js in drupal I'm really confused now, as to what to do.

Any help is totally appreciated.
Becky

Comments

ananto’s picture

do you try drupal_add_js() ?

beckyjohnson’s picture

Yes I did. I found a post where it said to put the drupal_add_js into a block or on a page.tpl I want it in, but it did not work. I am beginning to wonder if there is something faulty with my installation....Is that possible?

Becky

baronmunchowsen’s picture

If you have a custom theme, you should be able to create a script.js file and upload it to your theme directory (/sites/all/themes/mytheme/script.js). Can you let us know what theme you're using?

beckyjohnson’s picture

Sure. I made a subtheme of the zen template. So, my next question is, does it have to be called script.js? It's not a big deal to change the file name by any means but is that a drupal standard?

baronmunchowsen’s picture

Hi,

I think you have 2 options available to you.

  1. In drupal 6 you can create a script.js file and put it in the root directory of your theme and Drupal will pick it up automatically (http://drupal.org/node/171213)
  2. You can add a line to your mytheme.info file rather than use drupal_get_js() which looks like:
    scripts[] = myscriptfile.js
    

    This is documented here - http://drupal.org/node/171205#scripts - but the example on this book page is bad because the javascript file in the example is 'script.js' which would actually be included automatically (as per 1. above)

One thing you will have to do is empty your theme registry (see 'The theme registry' at the bottom of http://drupal.org/node/173880) every time you make one of these changes, and I recommend the devel module to help you with this http://drupal.org/node/270064.

Hope this helps.

beckyjohnson’s picture

Baronmunchowsen, when I made the file called script.js and added scripts [] =script.js to my .info file, i go the following error message in my admin panel:

warning: file_get_contents(sites/all/themes/custom/wimax_forum/script.js) [function.file-get-contents]: failed to open stream: Permission denied in /Applications/xampp/xamppfiles/htdocs/drupal6/includes/locale.inc on line 1622.
One or more problems were detected with your Drupal installation. Check the status report for more information.

Becky

baronmunchowsen’s picture

One or more problems were detected with your Drupal installation. Check the status report for more information.

Does this display when you've not got the scripts[] line in your info file? What are the errors/issues on your status report? This still seems to me to be a path issue as the php function 'file_get_contents' is being passed a path that can't be found (sites/all/themes/custom/wimax_forum/script.js). How is your server configured?

newtoid’s picture

this is sounds advice,

i wanted to include a 3rd party javascript and css combo, i just added them as directed and it works a treat

i tried before by putting the code into page.tpl.php and the lines i had put in were being automatically deleted, as were the files so i was depending on chmod to protect the files from deletion like a crazy fool

cheers baronmunchowsen

fumbling’s picture

I couldn't put the AdSense javascript snippet in a block on D6 until I went to Site configuration >> Input formats >> Add input format, and then have no filters on the new format. Then choose that completely open format when adding your js into the block you create for your js. Just a thought.

Drupalot.com - ask & answer Drupal questions

beckyjohnson’s picture

what is the name of the input format to add?

Also, thanks for all these suggestions guys, I really appreciate it. I will try them asap.

Becky

fumbling’s picture

Site Configuation >> Input Formats >> Add Input Format >> ... once you're here, give your input format a name, such as "Javascript," choose "administrator" under "Roles" and don't choose any filters. Then click "Save configuration." You now have a js-friendly option when you're posting/creating any content, block, etc, as an admin. Just remember that when you do need to use javascript, that you click "input format" below the new post or content and choose "Javascript" from the options.

Let me know if I glossed over anything. Hope that helps.

Drupalot.com - ask & answer Drupal questions

beckyjohnson’s picture

I did what you guys suggested and made an input format for the js and then i declared the external code in my info file. I think the internal javascript is having a problem grabbing the images from my directory. I am posting my code below to see if you guys have any further suggestions.

<script src="script.js" language="Javascript"></script> 
<script type="text/javascript">
<!-- //
/*================================

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com
http://slayeroffice.com

==================================

- Modifications By www.dhcreationstation.com
04.30.2008 version: 2.5.3
[Desc]   Transition time delay and individual linking abiltities.

[Added]  Variables: pause        = 5000; // delay before next transition begins
                    fadeInterval = 100;  // speed of transition

05.10.2008 version: 2.5.7
[Added]  MultiLinking Abilities to function call.

         Default: Pull gallery Images No Linking.
                  var gallery=new XFadeGallery('MyGallery')

       Setting 1: Pull gallery Images, Link Individual Images. Links are defined in
                  image array. If link not available returns void.
                  var gallery=new XFadeGallery('MyGallery',1)

       Setting 2: Pull gallery Images, Link Image Group. Link is defined by Arg[2].
                  By default, if group link is not defined it defaults to
                              www.dhcreationstation.com
                  var gallery=new XFadeGallery('MyGallery',2,'newImagepage.html')

================================*/



//===== Adjustable Globals =====//
var pause        = 5000;
var fadeInterval = 100;

var imgDir       = "<?php print base_path() .
path_to_theme() . '/' ?>";

//===== Gallery Arrays Begin =====//

var MyGallery1 = new Array();
MyGallery1[1] = '/images/promos/canada_conference.jpg| http://www.wimaxforum.org';
MyGallery1[2] = '/images/promos/news1.jpg|http://www.wimaxforum.org';
MyGallery1[3] = '/images/promos/press1.jpg|http://www.wimaxforum.org';
MyGallery1[4] = '/images/promos/sanjose_summit.jpg|http://www.wimaxforum.org';

var MyGallery2 = new Array();
MyGallery2[1] = '/images/promos/congress_america.jpg.jpg| http://www.wimaxforum.org';
MyGallery2[2] = '/images/promos/news2.jpg|http://www.wimaxforum.org';
MyGallery2[3] = '/images/promos/press2.jpg|http://www.wimaxforum.org';
MyGallery2[4] = '/images/promos/plugfest_malaga.jpg|http://www.wimaxforum.org';

var MyGallery3 = new Array();
MyGallery3[1] = '/images/promos/congress_asia.jpg| http://www.wimaxforum.org';
MyGallery3[2] = '/images/promos/news3.jpg|http://www.wimaxforum.org';
MyGallery3[3] = '/images/promos/press3.jpg|http://www.wimaxforum.org';
MyGallery3[4] = '/images/promos/taipei_summit.jpg|http://www.wimaxforum.org';

var MyGallery4 = new Array();
MyGallery4[1] = '/images/promos/congress_global.jpg| http://www.wimaxforum.org';
MyGallery4[2] = '/images/promos/news4.jpg|http://www.wimaxforum.org';
MyGallery4[3] = '/images/promos/press4.jpg|http://www.wimaxforum.org';



//===== Gallery Arrays End =====//

// -->
</script>
<div id="promotions">
    		<div id="promotion_one">
 				 <script>var gallery=new XFadeGallery('MyGallery',1)</script>
  			</div>
  			<div id="promotion_two">
 				 <script>var gallery=new XFadeGallery('MyGallery',2)</script>
  			</div>
  			<div id="promotion_three">
 				 <script>var gallery=new XFadeGallery('MyGallery',3)</script>
  			</div>
  			<div id="promotion_four">
 				 <script>var gallery=new XFadeGallery('MyGallery',4)</script>
  			</div>
  				</div>

To be clear, this is what I put in my block