Bug Tracker

Ticket #2249: one+proxy.diff

File one+proxy.diff, 1.6 kB (added by flesler, 8 months ago)

Should fix the proxy issue, and adds a generic function for jQuery to reuse. Implemented it in jQuery.event.add.

  • core.js

     
    661661     
    662662    cache: {}, 
    663663     
     664    proxy: function( fn, proxy ){ 
     665        // Set the guid of unique handler to the same of original handler, so it can be removed  
     666        proxy.guid = fn.guid = fn.guid || jQuery.event.guid++; 
     667        return proxy;//so proxy can be declared as an argument 
     668    }, 
     669     
    664670    data: function( elem, name, data ) { 
    665671        elem = elem == window ? 
    666672            windowData : 
  • event.js

     
    2626            var fn = handler;  
    2727 
    2828            // Create unique handler function, wrapped around original handler  
    29             handler = function() {  
     29            handler = jQuery.proxy( fn, function() {  
    3030                // Pass arguments and context to original handler  
    3131                return fn.apply(this, arguments);  
    32             }; 
     32            }); 
    3333 
    3434            // Store data in unique handler  
    3535            handler.data = data; 
    36  
    37             // Set the guid of unique handler to the same of original handler, so it can be removed  
    38             handler.guid = fn.guid; 
    3936        } 
    4037 
    4138        // Init the element's event structure 
     
    401398    }, 
    402399     
    403400    one: function( type, data, fn ) { 
     401        var one = jQuery.proxy( fn || data, function(event) { 
     402            jQuery(this).unbind(event, one); 
     403            return (fn || data).apply( this, arguments); 
     404        }); 
    404405        return this.each(function(){ 
    405             jQuery.event.add( this, type, function(event) { 
    406                 jQuery(this).unbind(event); 
    407                 return (fn || data).apply( this, arguments); 
    408             }, fn && data); 
     406            jQuery.event.add( this, type, one, fn && data); 
    409407        }); 
    410408    }, 
    411409