Skip to content
Permalink
Browse files

Fixes #123736 - move hover pseudo-eent to deprecated

  • Loading branch information
elgreg committed Oct 16, 2012
1 parent bf145b6 commit 6315c9ec28190a927c4d1283b7b8171e8d975b87
Showing with 64 additions and 27 deletions.
  1. +33 −1 src/deprecated.js
  2. +29 −0 test/unit/deprecated.js
  3. +2 −26 test/unit/event.js
@@ -1,7 +1,11 @@
// Limit scope pollution from any deprecated API
(function() {

var matched, browser;
var matched, browser, eventAdd, eventRemove,
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
@@ -95,4 +99,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;
// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9
jQuery.attrFn = {};

jQuery.event.remove = function(elem, types, handler, selector, mappedTypes){
if(types){
types = hoverHack(types);
}
eventRemove.call(this, elem, types, handler, selector, mappedTypes);
};


})();
@@ -107,4 +107,33 @@ if ( jQuery.browser ) {
ok(!!jQuery.attrFn, "attrFnPresent");
});

test("hover pseudo-event", function() {
expect(2);

var balance = 0;
jQuery( "#firstp" )
.on( "hovercraft", function() {
ok( false, "hovercraft is full of ills" );
})
.on( "click.hover.me.not", function( e ) {
equal( e.handleObj.namespace, "hover.me.not", "hover hack doesn't mangle namespaces" );
})
.bind("hover", function( e ) {
if ( e.type === "mouseenter" ) {
balance++;
} else if ( e.type === "mouseleave" ) {
balance--;
} else {
ok( false, "hover pseudo: unknown event type "+e.type );
}
})
.trigger("click")
.trigger("mouseenter")
.trigger("mouseleave")
.unbind("hover")
.trigger("mouseenter");

equal( balance, 0, "hover pseudo-event" );
});

}
@@ -798,8 +798,8 @@ test("unbind(eventObject)", function() {
assert( 0 );
});

test("hover() and hover pseudo-event", function() {
expect(3);
test("hover() mouseenter mouseleave", function() {
expect(1);

var times = 0,
handler1 = function( event ) { ++times; },
@@ -817,30 +817,6 @@ test("hover() and hover pseudo-event", function() {

equal( times, 4, "hover handlers fired" );

var balance = 0;
jQuery( "#firstp" )
.on( "hovercraft", function() {
ok( false, "hovercraft is full of ills" );
})
.on( "click.hover.me.not", function( e ) {
equal( e.handleObj.namespace, "hover.me.not", "hover hack doesn't mangle namespaces" );
})
.bind("hover", function( e ) {
if ( e.type === "mouseenter" ) {
balance++;
} else if ( e.type === "mouseleave" ) {
balance--;
} else {
ok( false, "hover pseudo: unknown event type "+e.type );
}
})
.trigger("click")
.trigger("mouseenter")
.trigger("mouseleave")
.unbind("hover")
.trigger("mouseenter");

equal( balance, 0, "hover pseudo-event" );
});

test("mouseover triggers mouseenter", function() {

0 comments on commit 6315c9e

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