Well the changes were actually pretty simple. The first thing I did was 
change all of the various .bind() and .click() et. al. functions to pass 
all their arguments along. So

jQuery.fn[o] = function(f){
    return f ? this.bind(o, f) : this.trigger(o);
};

Becomes

jQuery.fn[o] = function(f){
    return f != undefined ? this.bind.apply(this, 
[o].concat(jQuery.map(arguments,"a"))) : this.trigger(o);
};

and similarly for the other event related functions.

Then inside jQuery.event.add, rather than doing:

handlers[handler.guid] = handler;

I turned that into an array of the handler followed by an array of the 
arguments that came with the event. Slicing the first three off of the 
arguments array to remove the actual required arguments to jQuery.event.add:

handlers[handler.guid] = [handler,jQuery.map(arguments,"a").slice(3)];

Then I had to modify jQuery.event.handle to both call the new location 
of the handler and also check for scope modification on the events it calls.

var c = this.events[event.type];

var args = [].slice.call( arguments, 1 );
args.unshift( event );

for ( var j in c ) {
    if ( c[j].apply( this, args ) === false ) {
        event.preventDefault();
        event.stopPropagation();
        returnValue = false;
    }
}

Becomes

var c = this.events[event.type];
           
for ( var j in c ) {
    var f = c[j][0];
    var a = c[j][1];
    var args = jQuery.map(arguments,"a").slice(1).concat(a);
    args.unshift(event);
    var scope = args[args.length-1] === true ? args[args.length-2] : this;
    if (scope != this) args = args.slice(0,-2);
    if ( c[j][0].apply( scope, args ) === false ) {
        event.preventDefault();
        event.stopPropagation();
        returnValue = false;
    }
}

I also added a fix to the global event trigger so that when multiple 
events of the same type are added to the same element, each event is 
only called once. In the current version of jQuery each event is called 
the number of unique events of the same type there are on any given 
element (i.e. two click events, each gets called twice):

in jQuery.event.trigger:

var g = this.global[type];

becomes

var g = jQuery.map(this.global[type],"a");

--
blair

Jörn Zaefferer wrote:
> Hi Blair!
>
>> I was saddened and chagrined to discover that the event system didn't 
>> have additional arbitrary arguments as I thought it did and so I wrote 
>> them in. I modified the event system very slightly to allow for both 
>> additional arguments and scope modification (two features of the Yahoo 
>> Event Utility I always thought were very useful when I developed with 
>> it). I have my typical level of documentation (read: as little as I can 
>> manage) at the demo page I set up ( http://jquery.offput.ca/event++/ ). 
>> It was a pretty simple rewrite and hopefully it will be of use to someone.
>
> Could you explain your actual changes? That would help a lot.
>
> --
> Jörn Zaefferer
>
> http://bassistance.de


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to