]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Replace accidentally removed scroll-handling code in focus
authorkborchers <kris.borchers@gmail.com>
Thu, 15 Dec 2011 19:28:33 +0000 (13:28 -0600)
committerkborchers <kris.borchers@gmail.com>
Thu, 15 Dec 2011 19:28:33 +0000 (13:28 -0600)
ui/jquery.ui.menu.js

index 6e534b1bafab20793ac5513ddab5e792c34d3d90..b73018a192c4673ddd503aba573c04ead0ce93f3 100644 (file)
@@ -294,6 +294,21 @@ $.widget( "ui.menu", {
        focus: function( event, item ) {
                this.blur( event );
 
+               if ( this._hasScroll() ) {
+                       var borderTop = parseFloat( $.curCSS( this.activeMenu[0], "borderTopWidth", true ) ) || 0,
+                               paddingTop = parseFloat( $.curCSS( this.activeMenu[0], "paddingTop", true ) ) || 0,
+                               offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop,
+                               scroll = this.activeMenu.scrollTop(),
+                               elementHeight = this.activeMenu.height(),
+                               itemHeight = item.height();
+
+                       if ( offset < 0 ) {
+                               this.activeMenu.scrollTop( scroll + offset );
+                       } else if ( offset + itemHeight > elementHeight ) {
+                               this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
+                       }
+               }
+
                this.active = item.first()
                        .children( "a" )
                                .addClass( "ui-state-focus" )