Detecting jQuery UI version in module I am developing a module in Drupal 7.56 that is going to rely on jQuery UI 1.12.1. I want my module to check to see if that version is installed on the site, if it is not I am going to use drupal_add_js() to add the correct version. I don't want to just add the js file if it already exists in the system.

I do not have access to the site the module is going to be installed on. I want this module to be used on many different sites and don't want the module to add the js if it is already there.

What is the best way to do this?
If you call drupal_add_js() without parameters it will return an array of all the JavaScript already installed. You can iterate over the elements to look for the jQuery UI version you need. For example

  $installed_js = drupal_add_js();
  foreach ($installed_js as $file =&gt; $details) {
    if (preg_match('/jquery\.ui/', $file)) {
      $version = $details['version'];
      break;
    }
  }
  list($major, $minor, $update) = explode('.', $version);
  if ($major != '1' &amp;&amp; $minor != '12' &amp;&amp; $update != '1') {
    // Add drupal_add_js call here
  }


You might need a more robust regex to check for a wider variety of possible filenames but the above code should work in principle. I should also point out, it's not totally robust - if for some bizarre reason the file was named blah.js, this approach would not find it, so your module's jQuery code should also check to make sure the right version is loaded.