From 8f042d8be34fe2d197e45d6fa398456759a4c007 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Wed, 6 May 2009 02:17:24 +0000 Subject: [PATCH] fix for #4234. hover can take one function to use for both enter and leave. --- src/event.js | 2 +- test/unit/event.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index 8d737bf4b..ebf1231cb 100644 --- a/src/event.js +++ b/src/event.js @@ -569,7 +569,7 @@ jQuery.fn.extend({ }, hover: function( fnOver, fnOut ) { - return this.mouseenter( fnOver ).mouseleave( fnOut ); + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); }, ready: function( fn ) { diff --git a/test/unit/event.js b/test/unit/event.js index 63c640d11..98833ece8 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -233,6 +233,24 @@ test("unbind(eventObject)", function() { assert( 0 ); }); +test("hover()", function() { + var times = 0, + handler1 = function( event ) { ++times; }, + handler2 = function( event ) { ++times; }; + + jQuery("#firstp") + .hover(handler1, handler2) + .mouseenter().mouseleave() + .unbind("mouseenter", handler1) + .unbind("mouseleave", handler2) + .hover(handler1) + .mouseenter().mouseleave() + .unbind("mouseenter mouseleave", handler1) + .mouseenter().mouseleave(); + + equals( times, 4, "hover handlers fired" ); +}); + test("trigger() shortcuts", function() { expect(6); jQuery('
  • Change location
  • ').prependTo('#firstUL').find('a').bind('click', function() {