Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.799 diff -u -r1.799 common.inc --- includes/common.inc 20 Sep 2008 20:22:23 -0000 1.799 +++ includes/common.inc 1 Oct 2008 00:12:33 -0000 @@ -2289,6 +2289,90 @@ } /** + * Adds a jQuery Plugin, its dependant plugins, and CSS to the page. + * @param $plugin + * The plugin to add. + * @return + * Details regarding the plugin that was added, or NULL when the plugin + * was not found. + * @see drupal_add_js() + * @see hook_jquery_plugins() + */ +function drupal_add_jq($plugin, $display_errors = FALSE, $log_errors = TRUE) { + static $invoked_plugins = array(); + if (!isset($invoked_plugins[$plugin])) { + $jq = drupal_get_jq($plugin); + if (isset($jq)) { + if (isset($jq['dependancies']) && is_array($jq['dependancies'])) { + foreach ($jq['dependancies'] as $dependancy) { + drupal_add_jq($dependancy); + } + } + if (isset($jq['js']) && is_array($jq['js'])) { + foreach ($jq['js'] as $js) { + drupal_add_js($js, 'module', 'footer'); + } + } + if (isset($jq['css']) && is_array($jq['css'])) { + foreach ($jq['css'] as $css) { + drupal_add_css($css); + } + } + } + else { + // Log and display stating that the jQuery plugin was not found. + $error = t('The %plugin jQuery plugin is not defined.', array('%plugin' => $plugin)); + if ($log_errors) { + watchdog('jquery', $error, WATCHDOG_ERROR); + } + if ($display_errors) { + drupal_set_message($error, 'error'); + } + } + } + return $plugin; +} + +/** + * Retrieve information about any available jQuery plugins. + * @param $plugin + * The name of the plugin to obtain information on. If NULL, retrieves + * information about all plugins. + * @param $cached + * Whether or not to use the cache when looking in the registry. + * @return + * An array of all information about the desired plugin. + */ +function drupal_get_jq($plugin = NULL, $cached = TRUE) { + static $plugins; + if (!isset($plugins) || !$cached) { + if ($cached && $cache = cache_get('jquery_plugins')) { + $plugins = $cache->data; + } + else { + // Allow plugins to have modulename.jquery.inc files for + // their implementation of hook_jquery_plugins(). + module_load_all_includes('jquery.inc'); + foreach (module_invoke_all('jquery_plugins') as $name => $details) { + // On conflicting plugin names, use the latest version. + if (isset($plugins[$name]) && isset($plugins[$name]['version'])) { + if (!isset($details['version']) || !is_numeric($details['version']) || $details['version'] < $plugins[$name]['version']) { + // Attempting to add an older plugin version. + continue; + } + } + $plugins[$name] = $details; + } + cache_set('jquery_plugins', $plugins); + } + } + if (isset($plugin)) { + return isset($plugins[$plugin]) ? $plugins[$plugin] : NULL; + } + return $plugins; +} + +/** * Aggregate JS files, putting them in the files directory. * * @param $files