Update jquery.uls from upstream

Change-Id: Id91d0551ec329fb6645d3e6c3610ca5f3e8670b4
This commit is contained in:
Santhosh Thottingal
2013-06-05 14:00:02 +05:30
committed by Gerrit Code Review
parent 84355a422d
commit b057531602

View File

@@ -181,7 +181,7 @@
$( '.uls-menu' ).hide(); $( '.uls-menu' ).hide();
this.$menu.show(); this.$menu.show();
this.$menu[0].scrollIntoView(); this.$menu.scrollIntoView();
this.shown = true; this.shown = true;
if ( !this.isMobile() ) { 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; $.fn.uls.Constructor = ULS;
} ( jQuery ) ); } ( jQuery ) );