jQ
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:
- jCarousel
- Block Refresh
- jQuery Media
- jMedia
- Magnifier
- jQuery Plugins (which includes the Metadata and Validation plugins)
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 releases | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.0 | 2008-Jun-29 | 10.49 KB | Download · Release notes | Recommended for 6.x | |
| Development snapshots | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 5.x-1.x-dev | 2008-May-05 | 10.05 KB | Download · Release notes | Development snapshot | |
