aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2011-04-10 16:51:22 -0400
committerjeresig <jeresig@gmail.com>2011-04-10 16:51:22 -0400
commit14ecd9a992fe97461297bb9c2fd55aa669f1e2e8 (patch)
treea5366eb9e5cc789d44c6e4ae92fd3ca373c22d4e /src/event.js
parent909a6ff60a88b17155bc000ab49d02c2dd6938f2 (diff)
parent574ae3b1be555dbd5242532739cd8e0a34e0569c (diff)
downloadjquery-14ecd9a992fe97461297bb9c2fd55aa669f1e2e8.tar.gz
jquery-14ecd9a992fe97461297bb9c2fd55aa669f1e2e8.zip
Merge branch 'proxy-native-bind' of https://github.com/gf3/jquery into gf3-proxy-native-bind
Diffstat (limited to 'src/event.js')
-rw-r--r--src/event.js44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/event.js b/src/event.js
index a4f02a7a0..ac0da6b7e 100644
--- a/src/event.js
+++ b/src/event.js
@@ -894,6 +894,8 @@ if ( !jQuery.support.focusinBubbles ) {
jQuery.each(["bind", "one"], function( i, name ) {
jQuery.fn[ name ] = function( type, data, fn ) {
+ var handler;
+
// Handle object literals
if ( typeof type === "object" ) {
for ( var key in type ) {
@@ -907,10 +909,15 @@ jQuery.each(["bind", "one"], function( i, name ) {
data = undefined;
}
- var handler = name === "one" ? jQuery.proxy( fn, function( event ) {
- jQuery( this ).unbind( event, handler );
- return fn.apply( this, arguments );
- }) : fn;
+ if ( name === "one" ) {
+ handler = function( event ) {
+ jQuery( this ).unbind( event, handler );
+ return fn.apply( this, arguments );
+ };
+ handler.guid = fn.guid || jQuery.guid++;
+ } else {
+ handler = fn;
+ }
if ( type === "unload" && name !== "one" ) {
this.one( type, data, fn );
@@ -974,24 +981,27 @@ jQuery.fn.extend({
toggle: function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
- i = 1;
+ guid = fn.guid || jQuery.guid++,
+ i = 0,
+ toggler = function( event ) {
+ // Figure out which function to execute
+ var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i;
+ jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 );
+
+ // Make sure that clicks stop
+ event.preventDefault();
+
+ // and execute the function
+ return args[ lastToggle ].apply( this, arguments ) || false;
+ };
// link all the functions, so any of them can unbind this click handler
+ toggler.guid = guid;
while ( i < args.length ) {
- jQuery.proxy( fn, args[ i++ ] );
+ args[ i++ ].guid = guid;
}
- return this.click( jQuery.proxy( fn, function( event ) {
- // Figure out which function to execute
- var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
- jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
-
- // Make sure that clicks stop
- event.preventDefault();
-
- // and execute the function
- return args[ lastToggle ].apply( this, arguments ) || false;
- }));
+ return this.click( toggler );
},
hover: function( fnOver, fnOut ) {