Skip to content
Permalink
Browse files

Move .toggle(fn, fn, ...) to deprecated.js.

  • Loading branch information
dmethvin committed Jul 2, 2012
1 parent 0d90065 commit 502337fab37748950a1f185c7480d7b5ad419233
Showing with 32 additions and 30 deletions.
  1. +1 −3 src/css.js
  2. +27 −1 src/deprecated.js
  3. +0 −26 src/event.js
  4. +4 −0 test/unit/event.js
@@ -13,8 +13,6 @@ var curCSS, iframe, iframeDoc,
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
rposition = /^(top|right|bottom|left)$/,

eventsToggle = jQuery.fn.toggle,

cssNormalTransform = {
letterSpacing: 0,
fontWeight: 400,
@@ -112,7 +110,7 @@ jQuery.fn.extend({
var bool = typeof fn === "boolean";

if ( jQuery.isFunction( fn ) && jQuery.isFunction( fn2 ) ) {
return eventsToggle.apply( this, arguments );
return jQuery._etoggle && jQuery._etoggle.apply( this, arguments );
}

return this.each(function() {
@@ -58,5 +58,31 @@ jQuery.sub = function() {
var rootjQuerySub = jQuerySub(document);
return jQuerySub;
};


jQuery._etoggle = jQuery.fn.toggle = function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
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 ) {
args[ i++ ].guid = guid;
}

return this.click( toggler );
};

})();
@@ -987,32 +987,6 @@ jQuery.fn.extend({
}
},

toggle: function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
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 ) {
args[ i++ ].guid = guid;
}

return this.click( toggler );
},

hover: function( fnOver, fnOut ) {
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
}
@@ -1447,6 +1447,8 @@ test("jQuery.Event.currentTarget", function(){
.off( "click" );
});

if ( jQuery._etoggle ) {

test("toggle(Function, Function, ...)", function() {
expect(16);

@@ -1525,6 +1527,8 @@ test("toggle(Function, Function, ...)", function() {
$div.remove();
});

} // .toggle(fn, fn)

test(".live()/.die()", function() {
expect(66);

0 comments on commit 502337f

Please sign in to comment.
You can’t perform that action at this time.