Update jquery.uls from upstream

Performance improvements by matmarex

Change-Id: Ie89bd56702dec231a8c27f9cf8eeb7bbffe9b251
This commit is contained in:
Santhosh Thottingal
2013-07-04 16:20:35 +05:30
parent f9498661a2
commit 44c6b50d84
4 changed files with 27 additions and 48 deletions

View File

@@ -201,11 +201,7 @@
defaultSearch: function () {
this.$resultsView.lcd( 'empty' );
if ( this.options.lazyload ) {
this.$regionFilters.first().regionselector( 'show' );
} else {
this.$regionFilters.regionselector( 'show' );
}
this.$regionFilters.regionselector( 'show' );
},
/**
@@ -269,7 +265,6 @@
languages: uls.languages,
quickList: uls.options.quickList,
clickhandler: $.proxy( uls.select, uls ),
lazyload: uls.options.lazyload,
source: uls.$languageFilter,
showRegions: uls.options.showRegions
} ).data( 'lcd' );
@@ -412,7 +407,6 @@
searchAPI: null, // Language search API
languages: $.uls.data.getAutonyms(), // Languages to be used for ULS, default is all languages
quickList: null, // Array of language codes or function that returns such
lazyload: true, // Lazy load the language list when scrolled.
compact: false, // Show ULS in compact mode
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA']
};

View File

@@ -287,11 +287,6 @@
scrollTop = $ulsLanguageList.position().top,
scrollBottom = $ulsLanguageList.height();
if ( lcd.options.lazyload && lcd.options.source.val() === '' ) {
if ( this.offsetHeight + this.scrollTop >= this.scrollHeight / 2 ) {
lcd.$element.trigger( 'scrollend' );
}
}
// The region section need to be in sync with the map filter.
inviewRegion = 'WW';
lcd.$element.find( 'div.uls-lcd-region-section' ).each( function () {
@@ -332,8 +327,7 @@
$.fn.lcd.defaults = {
languages: null,
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'],
lazyload: true
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA']
};
$.fn.lcd.Constructor = LanguageCategoryDisplay;

View File

@@ -22,7 +22,7 @@
/* RegionSelector plugin definition */
var RegionSelector, delay;
var RegionSelector;
/**
* Region selector is a language selector based on regions.
@@ -70,7 +70,16 @@
},
show: function () {
var result, languagesByScriptGroup, scriptGroup, languages, i;
var result, languagesByScriptGroup, scriptGroup, languages, i,
$element = this.options.$target && this.options.$target.$element,
$parent = $element && $element.parent(),
$prev = $element && $element.prev();
if ( $element && $parent ) {
// Avoid reflows while adding new elements to the list
// Use .detach() to keep jQuery events and data associated with elements
$element.detach();
}
if ( this.cache ) {
// If the result cache is present, render the results from there.
@@ -106,6 +115,15 @@
}
}
if ( $element && $parent ) {
// Restore the element to where we removed it from
if ( $prev ) {
$prev.after( $element );
} else {
$parent.append( $element );
}
}
if ( this.options.success ) {
this.options.success( this );
}
@@ -121,32 +139,8 @@
$target.append( langCode, region );
},
next: function () {
var regionSelector = this;
if ( !this.$element.hasClass( 'active' ) ) {
return true;
}
// Do not respond to all scroll end events, but only after a short interval
delay( function () {
var nextRegionGroupNumber = regionSelector.$element.data( 'regiongroup' ) + 1,
$nextRegion = $( '#uls-region-' + nextRegionGroupNumber ),
nextRegionSelector = $nextRegion.length && $nextRegion.data( 'regionselector' );
// If cache is defined, then it is already rendered and there's no need
// to re-render it.
if ( nextRegionSelector && nextRegionSelector.cache === null ) {
nextRegionSelector.show();
}
}, 100 );
return false;
},
listen: function () {
this.$element.on( 'click', $.proxy( this.click, this ) );
this.options.$target.$element.bind( 'scrollend', $.proxy( this.next, this ) );
},
click: function () {
@@ -195,12 +189,4 @@
$.fn.regionselector.Constructor = RegionSelector;
delay = ( function () {
var timer = 0;
return function ( callback, milliseconds ) {
clearTimeout( timer );
timer = setTimeout( callback, milliseconds );
};
} () );
} ( jQuery ) );