[jQuery] A plethora of patches

[jQuery] A plethora of patches

Here are several patches against today's version of jQuery:
http://mg.to/jquery/2006-02-18/
all.zip contains all of the .patch files, which are also found individually
in the same directory. The original/ directory contains today's versions of
the four jQuery files that the patches are based on. The patched/ directory
contains the four files with all the patches applied, along with a bonus:
The files are all converted to use tab indentation instead of the mix of
tabs and spaces in the originals. I noticed that you were using mostly tabs,
especially in the latest code. That's my preference too, so I tabified the
files.
I broke out the individual patches to make it easier to understand each
change. Here's what they do, with some comments noted by line number of the
patch file (not the source file line number).
* apply.patch - jQuery has code in several places to avoid using
Function.apply because it is not supported in old browsers. This patch
changes these to use a common $.apply() function. $.apply() uses
Function.apply if it exists, otherwise it falls back to the temporary method
trick.
Line 65: The existing calls to $.apply() have zero or one arguments; I
figured I'd support two arguments while I was at it. I wish there were a
more general way to do this, but I can't think of one that works on the old
browsers that this code supports.
Lines 67-77: I wrote some code here to use the delete operator if it is
supported, or fall back to "= undefined" if delete is not available. It does
the fallback fairly efficiently, taking an exception only the first time it
tries to use delete. It could be that this is overkill and just doing
"t.$$jQuery_method = undefined;" (like the original code) would be good
enough.
* class.patch - Adds a handy $().addOrRemoveClass method.
* cleanup.patch - Mostly some code cleanup and simplification, and one
little bug fix.
Lines 18-20: A line of code that you split in two a few days ago, probably
to make it more readable. To me it looks better as a single line with some
parentheses to solve the readability problem; see what you think.
Lines 73-75: OTOH, I think this one is easier to read and more idiomatic
without the parentheses.
Lines 149-153: I commented these out because I didn't see them used anywhere
and they seemed to go against the jQuery spirit of not changing existing
objects.
* context.patch - A very simple patch that adds a very powerful feature. If
you set $.context to any DOM node, the $() function will use that root
instead of document. Also, $() with no arguments is allowed now; instead of
failing it wraps either $.context or document.
$.context is most useful when combined with my "invisible jQuery" trick
which I'll blog about shortly. But it could also be useful in other contexts
(pun intended) and it doesn't break anything.
* dollarc.patch - Changes $C() to $.C() and deprecates $C().
* hover.patch - Renames the existing $().hover() method as over(), and adds
a new hover(in,out,time) method which does not call the "in" function until
the mouse has been inside the element for the specified time in milliseconds
(which defaults to 1/3 second). This is handy for things like tooltips or
delayed highlights.
$('example').over( mouseIn, mouseOut ).hover( mouseHover ).click(
mouseClick );
The "out" functions for over() and hover() both get called immediately when
the mouse leaves the element, so there's no need to provide them both if
you're using both methods. But it's handy to have both available, e.g. if
you are just calling hover() and not over().
I renamed the existing hover() method instead of leaving it alone and adding
a new method, because this seems to fit the names better. It won't break any
existing code that uses hover() except to introduce the time delay.
The hover() functions use the $.apply() function, so if you want to use
hover.patch you need apply.patch too.
Enjoy!
-Mike
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/