Scroll the window to show language settings if necessary

Restores the feature removed while refactoring in
Iafb15ac9a7140fcce9e71ed933be6c55be81dc7e

Change-Id: I3aec168457190b7bfb40c09c97252e0cbb3dd1de
This commit is contained in:
Santhosh Thottingal
2013-05-20 13:59:47 +05:30
parent 00c37b9218
commit 146f0fc2a4

View File

@@ -158,18 +158,38 @@
}, },
position: function () { position: function () {
var top, pos, left; var top, pos, left, bottom, height,
$window = $( window ),
windowHeight = $window.height(),
windowScrollTop = $window.scrollTop(),
windowBottom = windowScrollTop + windowHeight,
scrollPosition;
pos = $.extend( {}, this.$element.offset(), { pos = $.extend( {}, this.$element.offset(), {
height: this.$element[0].offsetHeight height: this.$element[0].offsetHeight
} ); } );
top = this.top || pos.top + pos.height; top = this.top || pos.top + pos.height;
left = this.left || '25%'; left = this.left || '25%';
// FIXME this is not exactly correct. position may not
// be relative to the trigger.
this.$window.css( { this.$window.css( {
top: top, top: top,
left: left left: left
} ); } );
height = this.$window.height();
bottom = top + height;
// If the language settings windpw is out of the viewport,
// scroll the window to show it
if ( ( top < windowScrollTop ) || ( bottom > windowBottom ) ) {
if ( height > windowHeight ) {
// Scroll to show as much of the upper part of window as possible
scrollPosition = top;
} else {
// Scroll just enough to show the language settings window.
scrollPosition = bottom - windowHeight;
}
$( 'html, body' ).stop().animate( {
scrollTop: scrollPosition
}, 500 );
}
}, },
show: function () { show: function () {