diff --git a/nice_menus.module b/nice_menus.module index 2dd3ce0..85f7d98 100644 --- a/nice_menus.module +++ b/nice_menus.module @@ -165,10 +165,66 @@ function nice_menus_library() { ), ); + $jquery = drupal_get_library('system', 'jquery'); + if (version_compare($jquery['version'], '1.4', '>')) { + $plugins = array( + 'jquery.hoverIntent' => 'jquery.hoverIntent.minified.js', + 'jquery.bgiframe' => 'jquery.bgiframe.min.js', + 'superfish' => 'superfish.js' + ); + + foreach ($plugins as $plugin => $file) { + $library_directory = drupal_get_path('module', 'nice_menus') . '/js'; + + if (module_exists('libraries') && libraries_get_path($plugin) != '') { + $library_directory = libraries_get_path($plugin); + } + elseif (file_exists('profiles/' . drupal_get_profile() . '/libraries/' . $plugin)) { + $library_directory = 'profiles/' . drupal_get_profile() . '/libraries/' . $plugin; + } + + if (file_exists(DRUPAL_ROOT . '/' . $library_directory . '/' . $file)) { + $libraries[$plugin]['version'] = nice_menus_get_version($library_directory . '/' . $file, array( + 'pattern' => '@version\s+([0-9a-zA-Z\.-]+)@i' + )); + $libraries[$plugin]['js'] = array($library_directory . '/' . $file => array()); + } + } + } return $libraries; } /** + * Gets the version information from an arbitrary library. + * + * @return + * A string containing the version of the library. + */ +function nice_menus_get_version($file, $options = array()) { + // Provide defaults. + $options += array( + 'file' => '', + 'pattern' => '', + 'lines' => 20, + 'cols' => 200, + ); + $file = DRUPAL_ROOT . '/' . $file; + + if (!file_exists($file)) { + return; + } + $file = fopen($file, 'r'); + while ($options['lines'] && $line = fgets($file, $options['cols'])) { + if (preg_match($options['pattern'], $line, $version)) { + fclose($file); + return $version[1]; + } + $options['lines']--; + } + fclose($file); +} + +/** * Implements hook_block_info(). */ function nice_menus_block_info() {