What modules do I need to add javascript?
mxer269 - May 19, 2009 - 14:16
Hi guys,
What modules do I need to add javascript? I downloaded jquery_ui and jquery update but can't get the UI to install properly and I'm not even sure if that's what I need. For now the reason I want to add javascript is for an expandable menu and slideshow gallery. I also want to be able just to insert random scripts into blocks and have them work properly.
Where do I go from here? I've searched some topics but can't find the right information.
Thank you for the help. :)
Edited by: VeryMisunderstood; Moved to appropriate forum

=-=
drupal uses the jquery javascript library. as such you don't need to "add" javascript to get javascript to work.
if it isn't jquery javascript that you are looking to use you may want to read api.drupal.org and learn about drupal_add_js or drupal_get_js one/or both of those help pull javascript into drupal.
if you are having trouble withe the jquery_ui, discuss the details of that trouble in another thread of file an issue against the project in the projects issue queue.
thanks! Ill take a look at
thanks! Ill take a look at the api right now
mxer269
C.P.C. developments
I read over the api like you
I read over the api like you mentioned. What are the steps I need to take to add javascript to say a block? To be specific, I want to add an expandable menu in a block.
From what I understand I need to upload the .js script into my directory somewhere.
Do I just need to add this code?:
<?php
function drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE) {
static $javascript = array();
if (isset($data)) {
// Add jquery.js and drupal.js, as well as the basePath setting, the
// first time a Javascript file is added.
if (empty($javascript)) {
$javascript['header'] = array(
'core' => array(
'misc/jquery.js' => array('cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE),
'misc/drupal.js' => array('cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE),
),
'module' => array(),
'theme' => array(),
'setting' => array(
array('basePath' => base_path()),
),
'inline' => array(),
);
}
if (isset($scope) && !isset($javascript[$scope])) {
$javascript[$scope] = array('core' => array(), 'module' => array(), 'theme' => array(), 'setting' => array(), 'inline' => array());
}
if (isset($type) && isset($scope) && !isset($javascript[$scope][$type])) {
$javascript[$scope][$type] = array();
}
switch ($type) {
case 'setting':
$javascript[$scope][$type][] = $data;
break;
case 'inline':
$javascript[$scope][$type][] = array('code' => $data, 'defer' => $defer);
break;
default:
// If cache is FALSE, don't preprocess the JS file.
$javascript[$scope][$type][$data] = array('cache' => $cache, 'defer' => $defer, 'preprocess' => (!$cache ? FALSE : $preprocess));
}
}
if (isset($scope)) {
if (isset($javascript[$scope])) {
return $javascript[$scope];
}
else {
return array();
}
}
else {
return $javascript;
}
}
?>
And then change it to point to the javascript file I uploaded.
Or am I completely off?
Are there any guides out there that detail the process step-by-step?
mxer269
C.P.C. developments