diff options
author | Greg Lavallee <greglavallee@wapolabs.com> | 2012-10-16 14:36:47 -0400 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2012-10-16 14:47:11 -0400 |
commit | e83bc970f2dc11fc0fd545cb0ec756a0eab64eda (patch) | |
tree | 2ca887f2d66ff407045f1616e51c53db9e4e2843 /src/deprecated.js | |
parent | fd5facf1d1db40149e0221ce8215b56f155b9394 (diff) | |
download | jquery-e83bc970f2dc11fc0fd545cb0ec756a0eab64eda.tar.gz jquery-e83bc970f2dc11fc0fd545cb0ec756a0eab64eda.zip |
Fixes #12736. Move hover event hack to deprecated.js for removal in 1.9. Closes gh-982.
Signed-off-by: Timmy Willison <timmywillisn@gmail.com>
Diffstat (limited to 'src/deprecated.js')
-rw-r--r-- | src/deprecated.js | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/deprecated.js b/src/deprecated.js index 4ea47b333..3c2763ddc 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -1,7 +1,12 @@ // Limit scope pollution from any deprecated API (function() { -var matched, browser; +var matched, browser, eventAdd, eventRemove, + oldToggle = jQuery.fn.toggle, + rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, + hoverHack = function( events ) { + return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" ); + }; // Use of jQuery.browser is frowned upon. // More details: http://api.jquery.com/jQuery.browser @@ -60,10 +65,6 @@ jQuery.sub = function() { return jQuerySub; }; -// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9 -jQuery.attrFn = {}; - -var oldToggle = jQuery.fn.toggle; jQuery.fn.toggle = function( fn, fn2 ) { if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) { @@ -72,19 +73,19 @@ jQuery.fn.toggle = function( fn, fn2 ) { // 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 ); + 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(); + // Make sure that clicks stop + event.preventDefault(); - // and execute the function - return args[ lastToggle ].apply( this, arguments ) || false; - }; + // 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; @@ -95,4 +96,32 @@ jQuery.fn.toggle = function( fn, fn2 ) { return this.click( toggler ); }; + +// Support for 'hover' type +eventAdd = jQuery.event.add; + +// Duck punch jQuery.event.add, and jquery.event.remove +// Signatures: +// jQuery.event = { +// add: function( elem, types, handler, data, selector ) { +// remove: function( elem, types, handler, selector, mappedTypes ) { +jQuery.event.add = function( elem, types, handler, data, selector ){ + if ( types ) { + types = hoverHack( types ); + } + eventAdd.call( this, elem, types, handler, data, selector ); +}; + +eventRemove = jQuery.event.remove; + +jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){ + if ( types ) { + types = hoverHack( types ); + } + eventRemove.call( this, elem, types, handler, selector, mappedTypes ); +}; + +// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9 +jQuery.attrFn = {}; + })(); |