]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip: Only bind blur when opening via focus, mouseleave for mouseover. Remove...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 19 Oct 2012 22:16:11 +0000 (18:16 -0400)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sun, 21 Oct 2012 16:50:12 +0000 (12:50 -0400)
tests/visual/tooltip/tooltip.html
ui/jquery.ui.tooltip.js

index 8f9b2e8df0f11f5f6cfb890710ce12a2f473bbfa..97fa99bb949d2c077abce1db3190c6e36b28f82e 100644 (file)
                                offset: "0 -5"
                        }
                });
+
+               $( "#blurs-on-click" ).tooltip().click(function() {
+                       $( "#focus-on-me" ).focus();
+               });
        });
        </script>
 </head>
                </div>
        </div>
 
+       <button id="blurs-on-click" title="button title text">click me to focus something else</button>
+       <input id="focus-on-me">
+
        <div class="group">
                <p>Play around with focusing and hovering of form elements.</p>
                <form>
index 73321633bdc3dd5f7fcd61b237e8cdfbd5f18ab1..b56d939e83145b4ce9b828b8aa14297b01c4b40d 100644 (file)
@@ -206,7 +206,7 @@ $.widget( "ui.tooltip", {
        },
 
        _open: function( event, target, content ) {
-               var tooltip, positionOption;
+               var tooltip, positionOption, events;
                if ( !content ) {
                        return;
                }
@@ -261,9 +261,7 @@ $.widget( "ui.tooltip", {
 
                this._trigger( "open", event, { tooltip: tooltip } );
 
-               this._on( target, {
-                       mouseleave: "close",
-                       focusout: "close",
+               events = {
                        keyup: function( event ) {
                                if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
                                        var fakeEvent = $.Event(event);
@@ -271,7 +269,14 @@ $.widget( "ui.tooltip", {
                                        this.close( fakeEvent, true );
                                }
                        }
-               });
+               };
+               if ( !event || event.type === "mouseover" ) {
+                       events.mouseleave = "close";
+               }
+               if ( !event || event.type === "focusin" ) {
+                       events.focusout = "close";
+               }
+               this._on( target, events );
        },
 
        close: function( event, force ) {
@@ -285,16 +290,6 @@ $.widget( "ui.tooltip", {
                        return;
                }
 
-               // don't close if the element has focus
-               // this prevents the tooltip from closing if you hover while focused
-               //
-               // we have to check the event type because tabbing out of the document
-               // may leave the element as the activeElement
-               if ( !force && event && event.type !== "focusout" &&
-                               this.document[0].activeElement === target[0] ) {
-                       return;
-               }
-
                // only set title if we had one before (see comment in _open())
                if ( target.data( "ui-tooltip-title" ) ) {
                        target.attr( "title", target.data( "ui-tooltip-title" ) );