I use a lot of plugins for my sites. Therefore I always put folder a plugin folder inside the module folder. It's just a little neater (is that an english word?).

Another great feature would be an plugin_exists function. This would become handy for other modules which require a jquery plugin to function.

I also gave the jquery_add_plugin an other argument '$packed'. If set to TRUE, the plugin will get the packed plugin. Otherwise it will get the source plugin.

Here's my code so far:

/**
 * Add a jQuery plugin to a page.
 */
function jquery_plugin_add($plugin, $packed = FALSE) {
  static $plugins = array();
  if (!isset($plugins[$plugin])) {
    drupal_add_js(drupal_get_path('module', 'jquery_plugin') .'/plugins/jquery.'. $plugin ($packed ? '.packed' : '.src') .'.js');
    $plugins[$plugin] = TRUE;
  }
}

/**
 * Add a jQuery plugin to a page.
 */
function jquery_plugin_exists($plugin) {
  $path = drupal_get_path('module', 'jquery_plugin').'/plugins';
  $exists = (file_exists("$path/jquery.$plugin.min.js"));
  if(!$exists) drupal_set_message(t('The required plugin %name is missing. Please download the plugin from !link and place it in %dir', array('%name' => $plugin, '!link' => l(t('here'), 'http://jquery.com/plugins/'), '%dir' => $path)));
  return $exists;
}

Comments

mfb’s picture

Status: Active » Closed (duplicate)

Duplicate of #271934: Add a plugin folder. Could you file a separate issue for each feature request?