From b057531602b0fcc3ae39324a70aac56c4780b898 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 5 Jun 2013 14:00:02 +0530 Subject: [PATCH] Update jquery.uls from upstream Change-Id: Id91d0551ec329fb6645d3e6c3610ca5f3e8670b4 --- lib/jquery.uls/src/jquery.uls.core.js | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/jquery.uls/src/jquery.uls.core.js b/lib/jquery.uls/src/jquery.uls.core.js index 4593f8d9..7286a743 100644 --- a/lib/jquery.uls/src/jquery.uls.core.js +++ b/lib/jquery.uls/src/jquery.uls.core.js @@ -181,7 +181,7 @@ $( '.uls-menu' ).hide(); this.$menu.show(); - this.$menu[0].scrollIntoView(); + this.$menu.scrollIntoView(); this.shown = true; if ( !this.isMobile() ) { @@ -423,5 +423,34 @@ }; } + /* + * Simple scrollIntoView plugin. + * Scrolls the element to the viewport smoothly if it is not already. + */ + $.fn.scrollIntoView = function () { + return this.each( function () { + var scrollPosition, + $window = $( window ), + windowHeight = $window.height(), + windowScrollTop = $window.scrollTop(), + windowBottom = windowScrollTop + windowHeight, + $element = $( this ), + panelHeight = $element.height(), + panelTop = $element.offset().top, + panelBottom = panelTop + panelHeight; + + if ( ( panelTop < windowScrollTop ) || ( panelBottom > windowBottom ) ) { + if ( panelHeight > windowHeight ) { + scrollPosition = panelTop; + } else { + scrollPosition = panelBottom - windowHeight; + } + $( 'html, body' ).stop().animate( { + scrollTop: scrollPosition + }, 500 ); + } + } ); + } + $.fn.uls.Constructor = ULS; } ( jQuery ) );