jqp.module in jQuery Plugin Handler (JQP) 6
Same filename and directory in other branches
File
jqp.moduleView source
<?php
/**
* Add a shared Javascript file from the plugins directory
*
* @param $file_name
* the name of the file to add
*
* @param ...additional arguments to pass to drupal_add_js
*
*/
function jqp_add_js() {
$args = func_get_args();
$file_name = array_shift($args);
$files = jqp_scan_dir();
if ($files[$file_name]) {
array_unshift($args, $files[$file_name]->filename);
call_user_func_array('drupal_add_js', $args);
}
else {
return FALSE;
}
}
/**
* Add a shared CSS file from the plugins directory
*
* @param $file_name
* the name of the file to add
*
* @param ...additional arguments to pass to drupal_add_css
*
*/
function jqp_add_css() {
$args = func_get_args();
$file_name = array_shift($args);
$files = jqp_scan_dir();
if ($files[$file_name]) {
array_unshift($args, $files[$file_name]->filename);
call_user_func_array('drupal_add_css', $args);
}
else {
return FALSE;
}
}
/**
* Check the existence of a given plugin in the plugins directory
*
* @param $file_name
* The name of the .js or .css file to check in the plugins directory
*
* @return boolean
* TRUE/FALSE representing whether the file was found
*/
function jqp_plugin_exists($file_name) {
$files = jqp_scan_dir();
return $files[$file_name] ? TRUE : FALSE;
}
/**
* Scan the 'plugins' directories for .js and .css files
*
* @return an array where key is file name and value is file path
*
* Example: array('color.js' => 'sites/all/plugins/twolibrary/color.js')
*
* If there are multiple plugins with the same filename in the directory,
* the LAST file read will be used.
* Example:
* plugins/onelibrary/color.js
* plugins/twolibrary/color.js <-- this file will *probably* get used
*
* LIKE MODULES, plugins should have unique file names
*/
function jqp_scan_dir() {
static $files;
if (!isset($files)) {
if ($cache = cache_get('jqp_plugins')) {
$files = $cache->data;
}
else {
$files = drupal_system_listing('(\\.js$|\\.css$)', 'plugins', 'basename', 0);
cache_set('jqp_plugins', $files);
}
}
return $files;
}
Functions
Name![]() |
Description |
---|---|
jqp_add_css | Add a shared CSS file from the plugins directory |
jqp_add_js | Add a shared Javascript file from the plugins directory |
jqp_plugin_exists | Check the existence of a given plugin in the plugins directory |
jqp_scan_dir | Scan the 'plugins' directories for .js and .css files |