Rename "that = this" to meaningful names

This commit is contained in:
Amir E. Aharoni
2012-11-29 10:40:24 +02:00
parent b34cbbe9d2
commit 7a04c3c6e0
3 changed files with 35 additions and 32 deletions

View File

@@ -93,7 +93,7 @@
break; break;
default: default:
var that = this; var languageFilter = this;
if ( e.which < 32 ) { if ( e.which < 32 ) {
// ignore any ASCII control characters // ignore any ASCII control characters
@@ -103,11 +103,11 @@
this.selectedLanguage = null; this.selectedLanguage = null;
delay( function() { delay( function() {
if ( !that.$element.val() ) { if ( !languageFilter.$element.val() ) {
that.clear(); languageFilter.clear();
} else { } else {
that.options.$target.empty(); languageFilter.options.$target.empty();
that.search(); languageFilter.search();
} }
}, 300 ); }, 300 );
@@ -194,18 +194,18 @@
}, },
searchAPI: function( query ) { searchAPI: function( query ) {
var that = this; var languageFilter = this;
$.get( that.options.searchAPI, { search: query }, function( result ) { $.get( languageFilter.options.searchAPI, { search: query }, function( result ) {
$.each( result['languagesearch'], function( code, name ) { $.each( result['languagesearch'], function( code, name ) {
if ( that.resultCount === 0 ) { if ( languageFilter.resultCount === 0 ) {
// Autofill the first result. // Autofill the first result.
that.autofill( code, name ); languageFilter.autofill( code, name );
} }
that.render( code ); languageFilter.render( code );
that.resultCount++; languageFilter.resultCount++;
} ); } );
that.resultHandler( query ); languageFilter.resultHandler( query );
} ); } );
}, },

View File

@@ -72,8 +72,8 @@
* @param region Optional region * @param region Optional region
*/ */
addToRegion: function( langCode, region ) { addToRegion: function( langCode, region ) {
var that = this; var lcd = this,
var language = that.options.languages[langCode], language = lcd.options.languages[langCode],
langName = $.uls.data.getAutonym( langCode ) || language || langCode, langName = $.uls.data.getAutonym( langCode ) || language || langCode,
regions = []; regions = [];
@@ -102,7 +102,7 @@
); );
// Append the element to the column in the list // Append the element to the column in the list
var $column = that.getColumn( regionCode ); var $column = lcd.getColumn( regionCode );
var lastLanguage = $column.find( 'li:last' ).data( 'code' ); var lastLanguage = $column.find( 'li:last' ).data( 'code' );
if ( lastLanguage ) { if ( lastLanguage ) {
@@ -112,7 +112,7 @@
if ( lastScriptGroup !== currentScriptGroup ) { if ( lastScriptGroup !== currentScriptGroup ) {
if ( $column.find( 'li' ).length > 2 ) { if ( $column.find( 'li' ).length > 2 ) {
// If column already has 2 or more languages, add a new column // If column already has 2 or more languages, add a new column
$column = that.getColumn( regionCode, true ); $column = lcd.getColumn( regionCode, true );
} }
} }
} }
@@ -152,28 +152,30 @@
}, },
render: function() { render: function() {
var that = this; var $section, $sectionTitle,
var $section, $sectionTitle; lcd = this,
var regions = { regions = {
// These are fallback text when i18n library not present // These are fallback text when i18n library not present
WW: 'Worldwide', WW: 'Worldwide',
AM: 'America', AM: 'America',
EU: 'Europe', EU: 'Europe',
ME: 'Middle East', ME: 'Middle East',
AS: 'Asia', AS: 'Asia',
AF: 'Africa', AF: 'Africa',
PA: 'Pacific' PA: 'Pacific'
}; };
$.each( $.uls.data.regiongroups, function( regionCode, regionIndex ) { $.each( $.uls.data.regiongroups, function( regionCode, regionIndex ) {
$section = $( '<div>' ).addClass( 'twelve columns uls-lcd-region-section' ).prop( 'id', regionCode ); $section = $( '<div>' ).addClass( 'twelve columns uls-lcd-region-section' ).prop( 'id', regionCode );
$sectionTitle = $( '<h3 data-i18n="uls-region-'+ regionCode+'">' ) $sectionTitle = $( '<h3 data-i18n="uls-region-'+ regionCode+'">' )
.addClass( 'eleven columns uls-lcd-region-section uls-lcd-region-title offset-by-one' ) .addClass( 'eleven columns uls-lcd-region-section uls-lcd-region-title offset-by-one' )
.text( regions[regionCode] ); .text( regions[regionCode] );
$section.append( $sectionTitle ); $section.append( $sectionTitle );
that.$element.append( $section ); lcd.$element.append( $section );
$section.hide(); $section.hide();
that.regionDivs[regionCode] = $section; lcd.regionDivs[regionCode] = $section;
} ); } );
this.$noResults.hide(); this.$noResults.hide();
this.i18n(); this.i18n();
}, },

View File

@@ -104,10 +104,11 @@
if ( !this.$element.hasClass( 'active') ) { if ( !this.$element.hasClass( 'active') ) {
return true; return true;
} }
var that = this;
var regionSelector = this;
// Do not respond to all scroll end events, but only after a short interval // Do not respond to all scroll end events, but only after a short interval
delay( function () { delay( function () {
var regiongroup = that.$element.data( 'regiongroup' ); var regiongroup = regionSelector.$element.data( 'regiongroup' );
var nextRegiongroup = regiongroup + 1; var nextRegiongroup = regiongroup + 1;
var $nextRegion = $( '#uls-region-' + nextRegiongroup ); var $nextRegion = $( '#uls-region-' + nextRegiongroup );