Changeset 5352
- Timestamp:
- 04/29/08 22:06:54 (7 months ago)
- Files:
-
- 1 modified
-
trunk/jquery/src/event.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/event.js
r5351 r5352 27 27 28 28 // Create unique handler function, wrapped around original handler 29 handler = function() {29 handler = this.proxy( fn, function() { 30 30 // Pass arguments and context to original handler 31 31 return fn.apply(this, arguments); 32 } ;32 }); 33 33 34 34 // Store data in unique handler … … 347 347 }, 348 348 349 proxy: function( fn, proxy ){ 350 // Set the guid of unique handler to the same of original handler, so it can be removed 351 proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++; 352 return proxy;//so proxy can be declared as an argument 353 }, 354 349 355 special: { 350 356 ready: { … … 412 418 413 419 one: function( type, data, fn ) { 420 var one = jQuery.event.proxy( fn || data, function(event) { 421 jQuery(this).unbind(event, one); 422 return (fn || data).apply( this, arguments ); 423 }); 414 424 return this.each(function(){ 415 jQuery.event.add( this, type, function(event) { 416 jQuery(this).unbind(event); 417 return (fn || data).apply( this, arguments); 418 }, fn && data); 425 jQuery.event.add( this, type, one, fn && data); 419 426 }); 420 427 }, … … 438 445 }, 439 446 440 toggle: function( ) {447 toggle: function( fn ) { 441 448 // Save reference to arguments for access in closure 442 var args = arguments; 443 444 return this.click(function(event) { 449 var args = arguments, i = 1; 450 451 // link all the functions, so any of them can unbind this click handler 452 while( i < args.length ) 453 jQuery.event.proxy( fn, args[i++] ); 454 455 return this.click( jQuery.event.proxy( fn, function(event) { 445 456 // Figure out which function to execute 446 this.lastToggle = ( this.lastToggle || 0 ) % args.length;457 this.lastToggle = ( this.lastToggle || 0 ) % i; 447 458 448 459 // Make sure that clicks stop … … 451 462 // and execute the function 452 463 return args[ this.lastToggle++ ].apply( this, arguments ) || false; 453 }) ;464 })); 454 465 }, 455 466
