четверг, 30 октября 2008 г.

JQ, jQuery Interface Sortable, JQP


jQ

*** See #315100: Centralized jQuery plug-in manager for the patch to put jQ in core! ***

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.

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.

(Drupal 6 version only): You can also simply add new jQuery plugin files in your /plugins or /sites/example.com/plugins directory, and they'll be added to the registry. Then, for example, if you upload jquery.example.js, you could just jq_add('jquery.example'); and you're off. Additionally, if you have a .js and .css file with the same base name there, they'll both be added with the same call. Caveat: if you have two plugins with the same base name, there are no guarantees which will be added to the registry. Better off defining a hook_jq function in that case (see below for information on that).

Kudos to jjeff for his work on the jQuery Plugin Handler (JQP) module that inspired this latest functionality.

jQuery Interface Sortable

The Interface Sortable module makes it easy for developers to add JavaScript drag-and-drop form elements to forms and drag-and-drop widgets to non-form pages. It depends on the JQuery Interface module which in turn relies on the JQuery Update module.


jQuery Plugin Handler (JQP)

(Yet another) jQuery plugin module. This module aims to be a simple, lightweight, and easy to use jQuery plugin handler for Drupal 6.

Why do I need a manager/handler for your jQuery plugins?

If you have a module that is using a jQuery plugin, the usual reaction is to drop the plugin into the module directory and be done with it. However, this becomes a big problem when you have two different modules which use the same plugin. At minimum, the library will be included on the page (and downloaded by the browser) twice. At maximum, conflicting versions or multiple initializations of the same plugin can cause major problems for the page.

A plugin manager/handler will place all of your jQuery plugins in a central location so there is no duplication or conflict.

My frustration with the other jQuery plugin managers (such as JQ and Plugins) was that they required you to write a lot of PHP code just to have central access to a jQuery plugin. Each jQuery plugin got represented by a separate module and the overhead as compared to "just dropping it in my module directory" was frustrating.

To use JQP with your module or theme:

  1. Enable the module.
  2. Create a directory called "plugins" at sites/all/plugins or sites/[example.com]/plugins or similar.
2