My question is simple.
Is there a straightforward method to load a library e.g. ibeginshare (it contains 2 css, an images folder and 1 js) which I copied in sites/all/libraries
to use it in my module?
I have created a module that implements hook_block_info and hook_block_view and I want to load this library in its hook_init.
Is it mandatory to use hook_library and define there everysingle file then call it via drupal_add_library? I am confused. What if I have dozens of js/css files ? What if I don't want necessarly to share the library with other modules?
NOTE I managed to load the file like this:
METHOD 1
function MYMODULE_init() {
drupal_add_js('sites/all/libraries/ibeginshare/share.js');
}
I would like a more elegant way so I tried:
METHOD 2
function MYMODULE_init() {
drupal_add_library('MYMODULE', 'ibeginshare');
}
/**
* Implements hook_library().
* @return string
*/
function MYMODULE_library() {
$libraries['ibeginshare'] = array(
'title' => 'ibeginshare',
'website' => '',
'version' => '1.2',
'js' => array(
'sites/all/libraries/ibeginshare/share.js' => array(),
),
'css' => array(
'sites/all/libraries/ibeginshare/share.css' => array(),
),
'css' => array(
'sites/all/libraries/ibeginshare/share-print.css' => array(),
),
);
return $libraries;
}
this loads all libraries but the plugin doesn't initialize. I wonder why. I think will work if I add a weight property in the hook_library but anything I tried didn't work.