Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.925
diff -u -r1.925 common.inc
--- includes/common.inc	18 Jun 2009 21:19:01 -0000	1.925
+++ includes/common.inc	29 Jun 2009 20:55:32 -0000
@@ -3664,23 +3664,32 @@
   }
 
   // Add additional CSS and JavaScript files associated with this element.
-  foreach (array('css', 'js') as $kind) {
+  foreach (array('library', 'css', 'js') as $kind) {
     if (!empty($elements['#attached_' . $kind]) && is_array($elements['#attached_' . $kind])) {
       foreach ($elements['#attached_' . $kind] as $data => $options) {
-        // If the value is not an array, it's a filename and passed as first
-        // (and only) argument.
-        if (!is_array($options)) {
-          $data = $options;
-          $options = NULL;
+        // Adding libraries is different then adding Javascript or CSS. Due to
+        // this, we will use call_user_func_array() rather then call_user_func.
+        if ($kind == 'library') {
+          // The options array becomes the arguments that are passed through to
+          // the call to drupal_add_library().
+          call_user_func_array('drupal_add_library', $options);
         }
-        // When drupal_add_js with 'type' => 'setting' is called, the first
-        // parameter ($data) is an array. Arrays can't be keys in PHP, so we
-        // have to get $data from the value array.
-        if (is_numeric($data)) {
-          $data = $options['data'];
-          unset($options['data']);
+        else {
+          // If the value is not an array, it's a filename and passed as first
+          // (and only) argument.
+          if (!is_array($options)) {
+            $data = $options;
+            $options = NULL;
+          }
+          // When drupal_add_js with 'type' => 'setting' is called, the first
+          // parameter ($data) is an array. Arrays can't be keys in PHP, so we
+          // have to get $data from the value array.
+          if (is_numeric($data)) {
+            $data = $options['data'];
+            unset($options['data']);
+          }
+          call_user_func('drupal_add_' . $kind, $data, $options);
         }
-        call_user_func('drupal_add_' . $kind, $data, $options);
       }
     }
   }
