]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Passed the original event that causes a blur through collapseAll to blur, then...
authorkborchers <k_borchers@yahoo.com>
Tue, 19 Jul 2011 21:15:59 +0000 (16:15 -0500)
committerCorey Frang <gnarf@gnarf.net>
Tue, 19 Jul 2011 21:15:59 +0000 (16:15 -0500)
tests/unit/menu/menu_events.js
ui/jquery.ui.menu.js

index a03bec3f6405216f318b60468b955afc411e7802..2f713acf8513ea5f62df087a533c6695915444ed 100644 (file)
@@ -21,4 +21,25 @@ test("handle click on menu", function() {
        equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
 });
 
+test( "handle blur: click", function() {
+       expect( 4 );
+       var $menu = $( "#menu1" ).menu({
+               focus: function( event, ui ) {
+                       equal( event.originalEvent.type, "click", "focus triggered 'click'" );
+                       equal( event.type, "menufocus", "focus event.type is 'menufocus'" );
+
+               },
+               blur: function( event, ui ) {
+                       console.log( event, ui );
+                       equal( event.originalEvent.type, "click", "blur triggered 'click'" );
+                       equal( event.type, "menublur", "blur event.type is 'menublur'" );
+               }
+       });
+
+       $menu.find( "li a:first" ).trigger( "click" );
+       $( "<a/>", { id: "remove"} ).appendTo("body").trigger( "click" );
+
+       $("#remove").remove();
+});
+
 })(jQuery);
index f6012de4f38d08bf153f254e1a62081721a88027..4717946f10b8ea51659035de73eceb6248d9cc44 100644 (file)
@@ -176,7 +176,7 @@ $.widget( "ui.menu", {
                this._bind( document, {
                        click: function( event ) {
                                if ( !$( event.target ).closest( ".ui-menu" ).length ) {
-                                       this.collapseAll();
+                                       this.collapseAll( event );
                                }
                        }
                });
@@ -249,7 +249,7 @@ $.widget( "ui.menu", {
                var nested,
                        self = this;
 
-               this.blur();
+               this.blur( event );
 
                if ( this._hasScroll() ) {
                        var borderTop = parseFloat( $.curCSS( this.element[0], "borderTopWidth", true ) ) || 0,
@@ -297,6 +297,8 @@ $.widget( "ui.menu", {
 
                this.active.children( "a" ).removeClass( "ui-state-focus" );
                this.active = null;
+
+               this._trigger( "blur", event, { item: this.active } );
        },
 
        _startOpening: function( submenu ) {
@@ -336,7 +338,7 @@ $.widget( "ui.menu", {
                        .position( position );
        },
 
-       collapseAll: function() {
+       collapseAll: function( event ) {
                this.element
                        .find( "ul" )
                                .hide()
@@ -346,7 +348,7 @@ $.widget( "ui.menu", {
                        .find( "a.ui-state-active" )
                        .removeClass( "ui-state-active" );
 
-               this.blur();
+               this.blur( event );
                this.activeMenu = this.element;
        },
 
@@ -470,7 +472,7 @@ $.widget( "ui.menu", {
                var ui = {
                        item: this.active
                };
-               this.collapseAll();
+               this.collapseAll( event );
                this._trigger( "select", event, ui );
        }
 });