'Library One', 'website' => 'http://example.com/library-1', // Note that this is a string. Use version_compare() to compare. 'version' => '1.2', 'js' => array( // Items that are just strings are interpreted as stright files. drupal_get_path('module', 'my_module') . '/library-1.js', ), 'css' => array( // By providing an array, it becomes the $options parameter during the // drupal_add_js/drupal_add_css call. drupal_get_path('module', 'my_module') . '/library-2.css' => array( 'type' => 'file', 'media' => 'screen', ), ), ); // Library Two. $libraries['library-2'] = array( 'title' => 'Library Two', 'website' => 'http://example.com/library-2', 'version' => '1.2', 'js' => array( // JavaScript settings can be added by sending in an array. array( 'type' => 'setting', 'data' => array('library-2' => TRUE), ), ), // Any depending libraries can be added by using the "dependencies" key. 'dependencies' => array( // Sending in a string will just add the depending library to the page. 'library-1', // Sending in the library name along with an array of parameters will be // sent in as additional arguments to drupal_add_js_library(). 'library-3' => array( 'additional arguments', ), ), // During inclusion of this library, all functions defined in the // "add callbacks" array will be called. 'add callbacks' => array( // The function named "library_2_added" will be called when library-2 is // added to the page. The arguments passed to this function are this // library's name, as well as any additional arguments that were passed // during the call to drupal_add_js_library(). 'library_2_added', ), ); return $libraries; } function cutting_edge_module_js_libraries() { $libraries['library-1'] = array( 'title' => 'Library One', 'website' => 'http://example.com/library-1', 'version' => '2.1', 'js' => array( drupal_get_path('module', 'cutting_edge_module') . '/library-1.js', ), 'css' => array( drupal_get_path('module', 'cutting_edge_module') . '/library-2.css' => array( 'type' => 'file', 'media' => 'screen', ), ), ); $libraries['library-2'] = array( 'title' => 'Library Two', 'website' => 'http://example.com/library-2', 'version' => '1.2', 'js' => array( array( 'type' => 'setting', 'data' => array('library-2' => TRUE), ), ), 'dependencies' => array( 'library-1', 'library-3' => array( 'additional arguments', ), ), 'add callbacks' => array( 'library_2_added', ), ); return $libraries; } function crappy_module_js_libraries() { $libraries['library-1'] = array( 'title' => 'Library One', 'website' => 'http://example.com/library-1', 'version' => '0.7-beta1', 'js' => array( drupal_get_path('module', 'crappy_module') . '/library-0.7.1.js' => array( 'type' => 'file', 'scope' => 'footer', 'weight' => 20, ), 'http://googleapis.com/library-1/0.7.js', ), 'css' => array( drupal_get_path('module', 'crappy_module') . '/library-2.css', ), 'add callbacks' => array('crappy_module_add_crap'), ); return $libraries; } //$a1 = array( // 'js' => array('foo/bar.js'), // 'css' => array('foo/bar.css'), // 'libraries' => array( // // ), // 'add callbacks' => array('foo_bar'), //); // //$a2 = array( // 'js' => array( // array('file' => 'foo/bar.js', 'scope' => 'footer'), // ), // 'css' => array('foo/bar.css', 'foo/baz.css'), //); // @see http://api.drupal.org/api/function/module_invoke_all/7 $return = array(); $hooks = array( 'hook_js_libraries', 'cutting_edge_module_js_libraries', 'crappy_module_js_libraries', ); foreach ($hooks as $function) { $args = array(); $result = call_user_func_array($function, $args); if (isset($result) && is_array($result)) { $return = array_merge_recursive($return, $result); } elseif (isset($result)) { $return[] = $result; } } print_r($return); /** * @defgroup helpers * @{ */ function drupal_get_path($type, $name) { return "sites/all/{$type}s/$name"; } /** * @} End of "defgroup helpers". */