1

I know you can add css / js with the drupal_add_css() or drupal_add_js(). Is there a way to define dependancies ?

Use Case Example:

I need a custom tabs/carousel jquery plugin working. I need jquery and jquery ui to load first. In order to ensure that i'd like it to load after jquery and jquery ui.

How would one do that?

Also, is there a way to declare if a script / library is already loaded? i.e. if i load two jquery (1.4 vs 1.8.1) libraries it'll conflict.

Or would this discussion be better suited for the drupal core issue queue?

1

This is pretty much what hook_library is for. You define your library

function mymodule_library ()
{
    $path = drupal_get_path("module", "mymodule");

    $libraries = array();

    $libraries["mymodule_util"] = array(
        "title" => "MyModule Utilities", 
        "version" => "0.0",
        "js" => array(
            $path . '/UTIL.js' => array(),
        ),

        'weight' => -10,
    );

    return $libraries;
}

You can add CSS and declare dependencies, if needed.

Then you say you want to use it

drupal_add_library("mymodule", "mymodule_util", TRUE);

This ensures all of the dependencies get loaded exactly once.

Check out drupal_add_library for more details. The core jQuery UI components are loaded this way, too. The module is system and the names all begin with ui., eg ui.scroller.

I would also check out jQuery Update to upgrade things so you stay in sync with that other jQuery plugins need.

0

This is built into drupal core with the hook_library.

This functionality isn't smart enough to figure out if you want to load two versions of the same thing, but I can't see a generics usage of loading different versions of the same library. Also with regard to jQuery and the version numbers, are you confusing jQuery and jQuery UI which can live side by side (has different version numbers).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.