Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.551
diff -u -F^function -r1.551 common.inc
--- includes/common.inc 3 Aug 2006 07:06:36 -0000 1.551
+++ includes/common.inc 3 Aug 2006 07:35:30 -0000
@@ -116,6 +116,7 @@ function drupal_set_html_head($data = NU
function drupal_get_html_head() {
$output = "\n";
drupal_add_css('misc/drupal.css', 'core');
+ $output .= drupal_get_js();
return $output . drupal_set_html_head();
}
@@ -1253,22 +1254,76 @@ function drupal_get_css($css = NULL) {
/**
* Add a JavaScript file to the output.
*
- * The first time this function is invoked per page request,
- * it adds "misc/drupal.js" to the output. Other scripts
- * depends on the 'killswitch' inside it.
- */
-function drupal_add_js($file, $nocache = FALSE) {
- static $sent = array();
-
- $postfix = $nocache ? '?'. time() : '';
- if (!isset($sent['misc/drupal.js'])) {
- drupal_set_html_head('');
- $sent['misc/drupal.js'] = TRUE;
- }
- if (!isset($sent[$file])) {
- drupal_set_html_head('');
- $sent[$file] = TRUE;
+ * When the function is called, it adds an element to the array of JavaScript files
+ * that should be in the page header.
+ *
+ * @param $file
+ * (optional) The path to the JavaScript file to include.
+ * @param $nocache
+ * (optional) If set to TRUE, the referenced JavaScript file is loaded every time a new
+ * page is loaded. This prevents caching.
+ * @return
+ * An array with all JavaScript files that are queued for addition to the header.
+ */
+function drupal_add_js($file = FALSE, $nocache = FALSE) {
+ static $javascript = array();
+
+ if ($file) {
+ $javascript[$file] = array(
+ 'path' => base_path() . $file,
+ 'cache' => !$nocache,
+ );
+ }
+
+ return $javascript;
+}
+
+/**
+ * Add JavaScript configuration settings to a page.
+ *
+ * Often, JavaScript enabled modules need settings to function properly. To prevent modules from
+ * interfering with each other, Drupal offers a centralized place to store this information. The settings
+ * will be accessible at Drupal.settings[$module].
+ *
+ * @param $module
+ * (optional) The module the JavaScript settings are for.
+ * @param $configuration
+ * (optional) The array with configuration options as associative array.
+ * @return
+ * An array with all JavaScript configuration settings that have been added so far.
+ */
+function drupal_add_js_settings($module = FALSE, $configuration = FALSE) {
+ static $javascript;
+
+ if ($module && $configuration) {
+ $javascript[$module] = array_merge((array)$javascript[$module], $configuration);
+ }
+
+ return $javascript;
+}
+
+/**
+ * This function returns all JavaScript files that are queued for addition to the header
+ * as HTML code. It adds drupal.js first as some other JavaScript files depend on
+ * the killswitch inside it
+ */
+function drupal_get_js() {
+ $javascript = drupal_add_js();
+ $settings = drupal_add_js_settings();
+
+ if ($javascript) {
+ array_unshift($javascript, array('path' => base_path() .'misc/drupal.js', 'cache' => TRUE));
+ }
+
+ foreach ($javascript as $file) {
+ $output .= '\n";
}
+
+ if ($settings) {
+ $output .= '\n";
+ }
+
+ return $output;
}
/**