Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.841
diff -u -p -r1.841 common.inc
--- includes/common.inc 30 Dec 2008 16:43:14 -0000 1.841
+++ includes/common.inc 31 Dec 2008 16:36:30 -0000
@@ -2301,7 +2301,9 @@ function drupal_clear_css_cache() {
* performed using this function:
*
* - Add a file ('file'):
- * Adds a reference to a JavaScript file to the page.
+ * Adds a reference to a JavaScript file to the page. This may either be a file
+ * relative to base_path(), or the absolute path to a JavaScript file hosted
+ * externally.
*
* - Add inline JavaScript code ('inline'):
* Executes a piece of JavaScript code on the current page by placing the code
@@ -2322,11 +2324,13 @@ function drupal_clear_css_cache() {
* drupal_add_js('$(document).ready(function(){alert("Hello!");});',
* array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
* );
+ * drupal_add_js('http://yui.yahooapis.com/2.6.0/build/utilities/utilities.js');
* @endcode
*
* @param $data
* (optional) If given, the value depends on the $options parameter:
- * - 'file': Path to the file relative to base_path().
+ * - 'file': Path to the file relative to base_path(), or the absolute path
+ * to a JavaScript file hosted externally.
* - 'inline': The JavaScript code that should be placed in the given scope.
* - 'setting': An array with configuration options as associative array. The
* array is directly placed in Drupal.settings. All modules should wrap
@@ -2559,7 +2563,8 @@ function drupal_get_js($scope = 'header'
case 'file':
if (!$item['preprocess'] || !$is_writable || !$preprocess_js) {
- $no_preprocess .= '\n";
+ $prefix = filter_var($item['data'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) ? '' : base_path();
+ $no_preprocess .= '\n";
}
else {
$files[$item['data']] = $item;
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.19
diff -u -p -r1.19 common.test
--- modules/simpletest/tests/common.test 26 Dec 2008 21:01:57 -0000 1.19
+++ modules/simpletest/tests/common.test 31 Dec 2008 16:36:30 -0000
@@ -470,6 +470,17 @@ class JavaScriptTestCase extends DrupalW
$javascript = drupal_get_js();
$this->assertTrue(strpos($javascript, 'simpletest.js') < strpos($javascript, 'misc/tableselect.js'), t('Altering JavaScript weight through the alter hook.'));
}
+
+ /**
+ * Test rendering an external JavaScript file.
+ */
+ function testRenderExternal() {
+ $external = 'http://yui.yahooapis.com/2.6.0/build/utilities/utilities.js';
+ drupal_add_js($external);
+ $javascript = drupal_get_js();
+ // Local files have a base_path() prefix, external files should not.
+ $this->assertTrue(strpos($javascript, 'src="' . $external) > 0, t('Rendering an external JavaScript file.'));
+ }
}
/**