I need to get an extra script on my site to work. I have followed the instructions for the theme.info method of adding scripts[] = js/scripts.js, cleared my site cache and browser cache. I still get no scripts. I have followed this thread - http://drupal.org/node/266585.

I am using the Omega theme, which calls for the js/omega.js file. It has no scripts.js file. I am trying to add a script that prompts IE6 and IE7 users to upgrade their browsers. The script is here - http://code.google.com/p/sevenup/ I know the script works, I tested it on a dev Joomla site and it fired the first time.

So how do I include multiple js files?

My current theme.info is like this-

scripts[] = js/omega.js
scripts[] = fix-ie/sevenup.0.3.js
scripts[] = fix-ie/sevenup_black.0.3.js

Any help is greatly appreciated!

Comments

bitradiator’s picture

Is your "fix-ie" directory located in sites/all/themes/omega?

samuel13’s picture

Yes it is.

iantresman’s picture

To get my scripts recognised, I had to Clear cached data (Admin|Performance) first.

I had also tried to place my scripts in my /modules directory (they weren't part of the original script), but the only path I could find that worked on my multi-site set-up was:

scripts[] = ../../modules/jquery.cycle.all.min.js

All other path variants did not work, even though the path relative to the base_url should work eg:

scripts[] = /sites/mydomain.com/themes/mytheme/jquery.cycle.all.min.js
scripts[] = sites/mydomain.com/themes/mytheme/jquery.cycle.all.min.js
scripts[] = /mydomain.com/themes/mytheme/jquery.cycle.all.min.js
scripts[] = mydomain.com/themes/mytheme/jquery.cycle.all.min.js
scripts[] = /themes/mytheme/jquery.cycle.all.min.js
scripts[] = themes/mytheme/jquery.cycle.all.min.js

I ended up creating a new /js directory in my theme, and added the following to my theme's .info file:

scripts[] = js/jquery.cycle.all.min.js
iantresman’s picture

The method I used above would only allow the script to reside in the theme's directory. Since I use a multisite set-up, I wanted my scripts to appear in a common directory, such as

modules/scripts</codes>. My solution, based on <a href="http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js/6#comment-120">this comment</a>, is to add the following lines of code template.php (just below the first &lt;?php>) in my theme's directory:

<code>drupal_add_js(drupal_get_path('module', 'my_module') . 'sites/all/modules/scripts/jquery.cycle.all.js');
drupal_add_js(drupal_get_path('module', 'my_module') . 'sites/all/modules/scripts/jquery.easing.1.3.js');
iaugur’s picture

In case you come across this looking for a solution to how to add Javascript files to Omega.

There are two main options:
If you want to add a javascript file to all of your pages (and you can optionalise this if you use delta - e.g. turn it off for certain deltas)
Then in your starter kit theme (your custom subtheme)
mytheme.info

add the following:

libraries[mytheme][name] = Global Javascript
libraries[mytheme][description] = Provides a global location for common JS
libraries[mytheme][js][0][file] = global.js
libraries[mytheme][js][0][options][weight] = 10

This is then available to toggle on and off in your settings configuration at "admin/appearance/settings/mytheme"
Your file then gets added alongside the other libraries such as media queries, formalize etc

If you would like to only add the file to certain pages then in your template.php

function mytheme_preprocess_html(&$variables) {
 // e.g. test for a specific node - or node type or some other condition such as is_front etc
  $node = menu_get_object();
  if ( !empty($node) && $node->nid == 27 ) {
    $path_prefix = $variables['directory'] ;
    drupal_add_js($path_prefix . '/js/global.js', array('type' => 'file', 'scope' => 'footer', 'weight' => 2)) ;
  }
}

George Boobyer
www.blue-bag.com