jQ

aaron - January 24, 2008 - 17:47

The jQ module allows other modules to register jQuery plugins in a central repository, and allows administrators of a site to enable or disable specific plugins globally.

The concept behind this module is to create a basic hook structure for jQuery wrapper modules, allowing other modules using these plugins to invoke them in a consistent fashion.

Current modules using the jQ system:

Current modules that optionally support jQ:

Current modules supported using the included jQ Bridge module:

  • jQuery Form (which is included as part of core in Drupal 6)
  • Cluetip (which favors a dependency on hoverIntent, but provides its own version if that module is not included)

The basic call to invoke a registered jQuery plugin on a page would be something like the following:

<?php
 
  jq_add
('plugin-2');
?>

This would load any files required by the plugin, unless an administrator has turned off the plugin manually.

The module defining the plugin would need at the least to provide the following hook:

<?php
function my_module_jq($op, $plugin = NULL) {
  switch (
$op) {
    case
'info':
      return array(
         
'plugin-1' => array(
             
'name' => t('Plugin One'),
             
'description' => t('This is the Plugin One jQuery plugin. It can make your coffee.'),
               
'version' => 'r5 // 2008-01-01 // jQuery 1.1.2',
               
'url' => 'http://plugins.jquery.com/project/plugin-1',
             
'files' => array(
                 
'js' => array(
                     
drupal_get_path('module', 'my_module') . '/js/plugin-1.js',
                  ),
              ),
          ),
         
'plugin-2' => array(
             
'name' => t('Plugin Two'),
             
'description' => t('This is the Plugin Two jQuery plugin. It can be found at !link.', array('!link' => l('jQuery Plugins', 'http://jquery.com/plugins/repository/whatever'))),
             
'files' => array(
                 
'js' => array(
                     
drupal_get_path('module', 'my_module') . '/js/plugin-2-min.js',
                     
drupal_get_path('module', 'my_module') . '/js/plugin-2-additional.js',
                  ),
                 
'css' => array(
                     
drupal_get_path('module', 'my_module') . '/css/plugin-2.css',
                  ),
              ),
          ),
      );
    case
'add':
       
// any additional processing required when adding a plugin to a page.
       
switch ($plugin) {
            case
'plugin-1':
               
// fancy code here...
               
break;
        }
    break;
  }
}
?>

In the future, we might add additional functionality, if we can identify other uses to simplify the jQuery invocation process, such as when jQuery calls are added inline.

Releases

Official releasesDateSizeLinksStatus
6.x-1.02008-Jun-2910.49 KBRecommended for 6.xThis is currently the recommended release for 6.x.
Development snapshotsDateSizeLinksStatus
5.x-1.x-dev2008-May-0510.05 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.
 
 

Drupal is a registered trademark of Dries Buytaert.