jquery module--a place for jQuery plugins and extensions

Events happening in the community are now at Drupal community events on www.drupal.org.
nedjo's picture

As more of us start using jQuery, we're getting the same jQuery plugin included in two, three, or more modules. Personally I've included tabs, cookie, and history in the jstools package. I've now seen the form plugin in three different modules. As well as duplicating work and code, we get swollen pageloads that load multiple copies of the same file from different locations (one for each module). And, potentially, problems if two different modules use different versions of the same plugin, and one overwrites the other.

What we need to do, I'm thinking, is create a single central repository. So I've created a module, jquery: http://drupal.org/project/jquery.

The .module file is empty. It simply allows us to load js files like this:

<?php
drupal_add_js
(drupal_get_path('module', 'jquery') .'/plugin.js');
?>

Besides converting some existing drupal_add_js() calls to reference the jquery module path, the only other change needed would be to add a


dependencies = jquery

line to .info files.

Make sense? Are you with me? Can we all agree to move our jquery plugins there?

Comments

own directories?

sime's picture

If a particular plugin that I use was put in (jquery.flash.js), would it go into it's own directory so that a README.txt can be added that identifies authorship and and it's duel-license status?

Just thinking... do you foresee a jquery_add_js()? You might call jquery_add_js('interface'). The function could also organize settings, and look in some other place for non-GPL plugins that the admin adds themselves:

jquery_add_js('typewriter', 'plugins', array('speed'=>'slow')).

So the above is the equivalent of:
-- check for jquery.typewriter.js in jquery modules own directory
-- then look for it in /sites/default/files/plugins/ (or vice-versa).
-- check for the file typewriter.js
-- check for the file typewriter
-- drupal_add_js() the file
-- then call drupal_add_js() with the first parameter being 'settings' for the page variables.

jquery tab

kumar_naveen2007@hotmail.com's picture

I m not able to add jQuery tabs to my customize drupal theme . I tried a lot but not even reach near to it ! Itried to use Tabs module and jQuery UI module but it says " The jQuery UI plugin is missing. Download and extract it to your jquery_ui module directory. (Currently using jQuery UI Not found) " even though I download and extract required file ...... it would b a great favor to me if u can help me out with this problem.

Thanks

Naveen
MIT STUDENT

Hmmm... this discussion is

cleaver's picture

Hmmm... this discussion is about 4 years old...

However, it sounds like you are having problems getting the jQueryUI in the right place. I did something similar with jQuery UI accordion and had to figure out which versions would work together.

If you're interested, please have a look: http://www.cleaver.ca/content/jquery-ui-accordion-drupal-6

Great Idea

starbow's picture

This is a great idea. Otherwise form.js and ifx.js are going to be everywhere. Also, now that jQuery has moved to 1.1.1, it is getting harder to find the 1.0 compatible plugins.

jQuery Version & Interface Elements

KentBye's picture

I noticed in the CVS logs that the latest checked in version of jQuery was 1.0.4.
What is to prevent one from replacing this file with the 1.1.1 version? Will it break other things in Drupal?

I ask because I have my eye on some of the sortables functionality, which is included within the jQuery Interface elements extensions. Would this proposed jQuery module be the appropriate repository for these Interface extensions?

doubtful

moshe weitzman's picture

thats not likely to work well. 1.1 is not backwards compatible with 1.0

Not true

joshk's picture

"1.1 is not backwards compatible with 1.0" is a bit of a misnomer that seems to somehow have become conventional wisdom.

First of all, it's your .js files (e.g. textarea.js) that would be compatible or not

Secondly, if your JS is right, your scripts will work with both jQuery 1.0 and 1.1.

And the kicker: with minor patches drupal core's .js can be made compatible with jQuery 1.1. For instance:

http://drupal.org/node/118846
http://drupal.org/node/120291

These two patches made drupal core's .js files compatible with either jQuery 1.0 or 1.1

The question of backwards/forwards-compatibility is about the state of Drupal's .js files. Clearly we need to maintain compatibility with 1.0, but that doesn't in any way preclude compatibility with 1.1 as well.

If there are actually known issues which cannot be redressed between 1.0 and 1.1, I'm unaware of them (enlighten me!), and there's nothing on jQuery's site which suggests that cross-compatibility is impossible. Indeed, the anecdotal evidence of those two patches seems to indicate that it's actually not that hard.

http://www.chapterthreellc.com | http://www.outlandishjosh.com

So I don't forget, this info

sime's picture

So I don't forget, this info would be useful documented here: http://drupal.org/node/42403

joshk eats crow

joshk's picture

Well, it's John Resig who says 'jQuery 1.1 is not compatible with 1.0," so I suppose that's where the idea comes from.

However, that doesn't mean that scripts can't work with both. In fact, the major change is that the API has been paired down for 1.1. There's a actually a plugin to manage compatibility by re-creating the 1.0 functions for 1.1.

http://www.chapterthreellc.com | http://www.outlandishjosh.com

jQuery++

Gurpartap Singh's picture

Behaviors module was the same of it? Although deleted that project as there was no code to present unless there's more demand of it.

Also, my wish list with this would include something like:

<?php
  drupal_add_js
(array('jquery_plugin' => array('base_path' => base_path())), 'setting');
?>

and in the module we can include:

<?php
if (!module_exists('jquery') {
 
drupal_add_js(array('custom_module' => array('base_path' => base_path())), 'setting');
}
?>

This prevents loading the same values multiple times. Dependency on jQuery-module is not forced, just optional. Maybe further hooks could be provided for complex requests from the module? Something like behaviors was proposed for? Maybe we can rename it to behaviors, that name is slick :D hehe ;) ++++

Update: After reading sime's comment, another idea popped. To add settings js:

<?php
  jquery_add_js
(array('custom_module' => array('base_path' => base_path())), 'setting');
?>

Remember the second, 'setting', parameter. I'm not sure if drupal_get_js merges all of them, but if not, they could just be merged in jquery-module for all the modules calling that function. So in the 2nd code above, it could become:

<?php
if (!module_exists('jquery') {
 
drupal_add_js(array('custom_module' => array('base_path' => base_path())), 'setting');
}
else {
 
jquery_add_js(array('custom_module' => array('base_path' => base_path())), 'setting');
}
?>

There's lot more to express about some complex but useful possibilities like merge similar settings?, match same resultant settings and merge them? :S:S, but limited time now. Please correct me if i'm being silly here.

Idea on hold

nedjo's picture

I'm putting this module idea on hold a bit while we sort out whether or not we can include external code in CVS in the first place, see this post: http://drupal.org/node/124978.

Javascript

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: