How can I check if a plugin is already available?
a_c_m - December 4, 2008 - 21:29
| Project: | jQ |
| Version: | 6.x-1.2 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I'm porting cluetips to D6 and making it a JQ module.
Cluetips zip comes with all the JS files it needs (hoverIntent and dimensions), currently the module just uses them, however i would love it, if it could work out if a JQ module exists to take over the work and use that file instead (if avilable).
The problem is the jq_plugins() function. We need to call it in the MODULENAME_jq() hook, to assess if the local files for hoverIntent need to be used, but in calling jq_plugins() it triggers its own hook again, causing a loop.
Any nice way around this? or have i missed the point?

#1
If you are porting the module to Drupal 6, you should know that the dimensions plugin is already included within jQuery 1.2.6 used by Drupal 6 (see the jQuery 1.2.6 release notes on Dimensions Plugin is Now Part of Core).
#2
If what you want to do is to check if a plugin is available, before to use your own version of the plugin, you can call
jq_add()which returns a value useful to understand if the function has been able to load the required plugin (therefore, the plugin is already available).#3
I am changing the request title, as it seemed you were asking how to generally check if a module is available (which would lead somebody to reply with ).
#4
#5
Would this work ?
if ( !empty(jq_plugins('your_plugin') ) {...
}
#6
Oups that was producing a fatal PHP error. Use
if ( in_array('your_plugin', jq_plugins()) ) {
...
}
#7
I believe the correct syntax for #6 would be:
if (array_key_exists('cycle', jq_plugins())) {
}
Though it doesn't seem to be necessary because you can just check the return value of jq_add('your_plugin'); .
#8
@ #7 if I remember well this is not right when the module is unavailable, since it adds a warning in watchdog.
#9
<?phpif (module_exists('jq') && array_key_exists('cycle', jq_plugins())) {
// ...
}
?>