diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-05-21 16:42:14 +0200 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-05-21 16:42:14 +0200 |
commit | 1e586dcd486f24fda9ed277abc2d94fb8d29aee1 (patch) | |
tree | 3ce167384836155c3cfc3d7a43771d3afe945aee | |
parent | f89971a2c378a170f5eb1e9bd6317cf64b52d3e8 (diff) | |
download | jquery-ui-1e586dcd486f24fda9ed277abc2d94fb8d29aee1.tar.gz jquery-ui-1e586dcd486f24fda9ed277abc2d94fb8d29aee1.zip |
Menu: Refactor focus method, extract _scrollIntroView method
-rw-r--r-- | ui/jquery.ui.menu.js | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 8de1eb47a..d3c32e3a0 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -311,23 +311,10 @@ $.widget( "ui.menu", { }, focus: function( event, item ) { - var nested, borderTop, paddingTop, offset, scroll, elementHeight, itemHeight, focused; + var nested, focused; this.blur( event, event && event.type === "focus" ); - if ( this._hasScroll() ) { - borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; - paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 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._scrollIntoView( item ); this.active = item.first(); focused = this.active.children( "a" ).addClass( "ui-state-focus" ); @@ -357,6 +344,24 @@ $.widget( "ui.menu", { this._trigger( "focus", event, { item: item } ); }, + _scrollIntoView: function( item ) { + var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; + if ( this._hasScroll() ) { + borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; + paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 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 ); + } + } + }, + blur: function( event, fromFocus ) { if ( !fromFocus ) { clearTimeout( this.timer ); |