| 1 |
// $Id: README.txt,v 1.3 2008/02/05 18:06:05 aaron Exp $
|
| 2 |
|
| 3 |
jQ
|
| 4 |
|
| 5 |
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.
|
| 6 |
|
| 7 |
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.
|
| 8 |
|
| 9 |
The basic call to invoke a registered jQuery plugin on a page would be something like the following:
|
| 10 |
|
| 11 |
<?php
|
| 12 |
jq_add('plugin-2');
|
| 13 |
jq_add('plugin-5', $extra1, $extra2, $extra3);
|
| 14 |
?>
|
| 15 |
|
| 16 |
This would load any files required by the plugin, unless an administrator has turned off the plugin manually.
|
| 17 |
|
| 18 |
The module defining the plugin would need at the least to provide the following hook:
|
| 19 |
|
| 20 |
Note that any extra arguments passed by jq_add will be passed after $plugin.
|
| 21 |
|
| 22 |
<?php
|
| 23 |
function my_module_jq($op, $plugin = NULL, $extra1 = NULL, $extra2 = NULL) {
|
| 24 |
switch ($op) {
|
| 25 |
case 'info':
|
| 26 |
return array(
|
| 27 |
'plugin-1' => array(
|
| 28 |
'name' => t('Plugin One'),
|
| 29 |
'description' => t('This is the Plugin One jQuery plugin. It can make your coffee.'),
|
| 30 |
'version' => 'r5 // 2008-01-01 // jQuery 1.1.2',
|
| 31 |
'url' => 'http://plugins.jquery.com/project/plugin-1',
|
| 32 |
'files' => array(
|
| 33 |
'js' => array(
|
| 34 |
drupal_get_path('module', 'my_module') . '/js/plugin-1.js',
|
| 35 |
),
|
| 36 |
),
|
| 37 |
),
|
| 38 |
'plugin-2' => array(
|
| 39 |
'name' => t('Plugin Two'),
|
| 40 |
'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'))),
|
| 41 |
'files' => array(
|
| 42 |
'js' => array(
|
| 43 |
drupal_get_path('module', 'my_module') . '/js/plugin-2-min.js',
|
| 44 |
drupal_get_path('module', 'my_module') . '/js/plugin-2-additional.js',
|
| 45 |
),
|
| 46 |
'css' => array(
|
| 47 |
drupal_get_path('module', 'my_module') . '/css/plugin-2.css',
|
| 48 |
),
|
| 49 |
),
|
| 50 |
),
|
| 51 |
);
|
| 52 |
case 'add':
|
| 53 |
// any additional processing required when adding a plugin to a page.
|
| 54 |
switch ($plugin) {
|
| 55 |
case 'plugin-1':
|
| 56 |
// fancy code here...
|
| 57 |
break;
|
| 58 |
}
|
| 59 |
break;
|
| 60 |
}
|
| 61 |
}
|
| 62 |
?>
|
| 63 |
|
| 64 |
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.
|