Index: jquery_ui.module =================================================================== --- jquery_ui.module (revision 459) +++ jquery_ui.module (working copy) @@ -20,7 +20,7 @@ * on the page, or a string with a single file name. */ function jquery_ui_add($files = array()) { - static $loaded_files, $ui_core, $effects_core; + static $loaded_files, $dependencies = array(); $jquery_ui_path = jquery_ui_get_path(); if ($jquery_ui_path === FALSE) { @@ -28,6 +28,14 @@ } $jquery_ui_path .= '/ui'; $compression = variable_get('jquery_update_compression_type', 'mini'); + $jquery_ui_version = version_compare(jquery_ui_get_version(), '1.8', '>=') ? 'jquery.' : ''; + + if (empty($dependencies)) { + $cache_dependencies = cache_get('jquery_ui_dependencies'); + if ($cache_dependencies->data) { + $dependencies = $cache_dependencies->data; + } + } // Convert file to an array if it's not one already, to compensate for // lazy developers. ;) @@ -35,20 +43,9 @@ $files = array($files); } - // If core hasn't been added yet, add it. - if (!isset($ui_core)) { - $ui_core = TRUE; - jquery_ui_add(array('ui.core')); - } - // Loop through list of files to include and add them to the page. foreach ($files as $file) { - // Any effects files require the effects core file. - if (!isset($effects_core) && strpos($file, 'effects.') === 0) { - $effects_core = TRUE; - jquery_ui_add(array('effects.core')); - } - + $file = $jquery_ui_version . $file; // Load other files. if (!isset($loaded_files[$file])) { switch ($compression) { @@ -66,10 +63,27 @@ break; } $js_path = $jquery_ui_path . '/' . $file_path; + + if (!isset($dependencies[$file])) { + $file_contents = file_get_contents($js_path); + preg_match('/^\/\*.*Depends:(.*?)\*\//ismu', $file_contents, $matches); + preg_match_all('/\s*\*\s*(jquery\.)?(.+)\n/miu', $matches[1], $depends); + + $dependencies[$file] = $depends[2]; + foreach ($dependencies[$file] as &$depend) { + $depend = basename(trim($depend), '.js'); + } + } + + if (!empty($dependencies[$file])) { + jquery_ui_add($dependencies[$file]); + } + drupal_add_js($js_path); $loaded_files[$file] = $js_path; } } + cache_set('jquery_ui_dependencies', $dependencies); } /**