Merge pull request #12 from amire80/2012/bug_39224/stabilize_scrolling

Refactoring scrolling code
This commit is contained in:
Santhosh Thottingal
2012-10-08 08:48:52 -07:00

View File

@@ -249,37 +249,42 @@
}, },
listen: function () { listen: function () {
var that = this; var lcd = this;
if ( this.options.clickhandler ) { if ( this.options.clickhandler ) {
this.$element.on( 'click', 'div.row li', function() { this.$element.on( 'click', 'div.row li', function() {
that.options.clickhandler.call( this, $( this ).data( 'code' ) ); lcd.options.clickhandler.call( this, $( this ).data( 'code' ) );
} ); } );
} }
// The region section need to be in sync with the map filter. // The region section need to be in sync with the map filter.
that.$element.scroll( function () { lcd.$element.scroll( function () {
var scrollTop = $( this ).position().top; var $ulsLanguageList = $( this ),
var scrollBottom = $( this ).height(); scrollTop = $ulsLanguageList.position().top,
if ( this.offsetHeight + this.scrollTop >= this.scrollHeight/2 ) { scrollBottom = $ulsLanguageList.height();
that.$element.trigger( 'scrollend' );
if ( this.offsetHeight + this.scrollTop >= this.scrollHeight / 2 ) {
lcd.$element.trigger( 'scrollend' );
} }
// The region section need to be in sync with the map filter. // The region section need to be in sync with the map filter.
var inviewRegion = 'WW'; var inviewRegion = 'WW';
that.$element.find( 'div.uls-lcd-region-section' ).each( function () { lcd.$element.find( 'div.uls-lcd-region-section' ).each( function () {
var top = $( this ).position().top; var $lcdRegionSection = $( this ),
var height = $( this ).height(); top = $lcdRegionSection.position().top,
height = $lcdRegionSection.height();
if ( top < scrollTop && height > scrollBottom ) { if ( top < scrollTop && height > scrollBottom ) {
inviewRegion = $( this ).attr( 'id' ); inviewRegion = $lcdRegionSection.attr( 'id' );
return true; return true;
} }
} ); } );
var inview = $.uls.data.regiongroups[inviewRegion]; var inview = $.uls.data.regiongroups[inviewRegion];
$( '.regionselector' ).removeClass( 'active' ); $( '.regionselector' ).removeClass( 'active' );
$( '#uls-region-' + inview ).addClass( 'active' ); $( '#uls-region-' + inview ).addClass( 'active' );
} ); } );
} }
}; };
$.fn.lcd = function( option ) { $.fn.lcd = function( option ) {