Merge "Whitespace and comments cleanup"

This commit is contained in:
jenkins-bot
2014-04-05 15:14:09 +00:00
committed by Gerrit Code Review

View File

@@ -33,6 +33,7 @@
uniqueArray.push( v ); uniqueArray.push( v );
} }
} ); } );
return uniqueArray; return uniqueArray;
} }
@@ -63,7 +64,7 @@
return; return;
} }
// if the interlanguage list is of moderate size, the compact size is 7. // If the interlanguage list is of moderate size, the compact size is 7.
this.compactSize = ( this.listSize <= 12 ) ? 7 : this.options.max; this.compactSize = ( this.listSize <= 12 ) ? 7 : this.options.max;
this.hideOriginal(); this.hideOriginal();
this.compactList = this.getCompactList(); this.compactList = this.getCompactList();
@@ -80,6 +81,7 @@
for ( language in this.compactList ) { for ( language in this.compactList ) {
this.showLanguage( language ); this.showLanguage( language );
} }
this.addTrigger(); this.addTrigger();
}, },
@@ -87,18 +89,23 @@
* Bind to event handlers and listen for events * Bind to event handlers and listen for events
*/ */
listen: function () { listen: function () {
var cl = this, var languages,
triggerPosition = this.$trigger.offset(), ulsTop, ulsLeft,
ulsLanguageList = {}, compactLinks = this,
languages; triggerPosition = compactLinks.$trigger.offset(),
ulsLanguageList = {};
languages = $.map( this.interlanguageList, function ( language, languageCode ) { languages = $.map( compactLinks.interlanguageList, function ( language, languageCode ) {
ulsLanguageList[ languageCode ] = language.autonym; ulsLanguageList[ languageCode ] = language.autonym;
return languageCode; return languageCode;
} ); } );
ulsTop = triggerPosition.top - compactLinks.$trigger.height() / 2 - 250 + 'px';
ulsLeft = triggerPosition.left + compactLinks.$trigger.width() + compactLinks.$interlanguageList.width() + 'px';
// Attach ULS to the trigger // Attach ULS to the trigger
this.$trigger.uls( { compactLinks.$trigger.uls( {
onReady: function () { onReady: function () {
this.$menu.addClass( 'interlanguage-uls-menu' ); this.$menu.addClass( 'interlanguage-uls-menu' );
}, },
@@ -108,22 +115,23 @@
*/ */
onSelect: function ( language ) { onSelect: function ( language ) {
var previousLanguages = mw.uls.getPreviousLanguages(); var previousLanguages = mw.uls.getPreviousLanguages();
previousLanguages.push( language ); previousLanguages.push( language );
previousLanguages = unique( previousLanguages ); previousLanguages = unique( previousLanguages );
mw.uls.setPreviousLanguages( previousLanguages ); mw.uls.setPreviousLanguages( previousLanguages );
window.location.href = cl.interlanguageList[ language ].href; window.location.href = compactLinks.interlanguageList[ language ].href;
}, },
// Use compact version of ULS // Use compact version of ULS
compact: true, compact: true,
// Left position of the language selector // Left position of the language selector
left: triggerPosition.left + cl.$trigger.width() + cl.$interlanguageList.width() + 'px', left: ulsLeft,
// Top position of the language selector. Top it 250px above to take care of // Top position of the language selector. Top it 250px above to take care of
// caret pointing the trigger. See .interlanguage-uls-menu:after style definition // caret pointing the trigger. See .interlanguage-uls-menu:after style definition
top: triggerPosition.top - cl.$trigger.height() / 2 - 250 + 'px', top: ulsTop,
// List of languages to be shown // List of languages to be shown
languages: ulsLanguageList, languages: ulsLanguageList,
// Show common languages // Show common languages
quickList: cl.filterByCommonLanguages( languages ) quickList: compactLinks.filterByCommonLanguages( languages )
} ); } );
}, },
@@ -132,17 +140,20 @@
* @return {Object} * @return {Object}
*/ */
getCompactList: function () { getCompactList: function () {
var language, languages, compactLanguages, index, compactedList = {}; var language, languages, compactLanguages, index,
compactedList = {};
languages = $.map( this.interlanguageList, function ( element, index ) { languages = $.map( this.interlanguageList, function ( element, index ) {
return index; return index;
} ); } );
compactLanguages = this.compact( languages ); compactLanguages = this.compact( languages );
for ( index = 0; index < compactLanguages.length; index++ ) { for ( index = 0; index < compactLanguages.length; index++ ) {
language = compactLanguages[ index ]; language = compactLanguages[ index ];
compactedList[ language ] = this.interlanguageList[ language ]; compactedList[ language ] = this.interlanguageList[ language ];
} }
return compactedList; return compactedList;
}, },
@@ -154,45 +165,50 @@
compact: function ( languages ) { compact: function ( languages ) {
var compactLanguages = []; var compactLanguages = [];
// Add previous language selections to this array. Previous languages are always // Add previously selected languages.
// the better suggestion because user had explicitly chosen them. // Previous languages are always the better suggestion
// because user had explicitly chosen them.
compactLanguages = compactLanguages.concat( this.filterByPreviousLanguages() ); compactLanguages = compactLanguages.concat( this.filterByPreviousLanguages() );
// Add all common languages to the beginning of array. These are the most probable
// languages predicted by ULS // Add all common languages to the beginning of array.
// These are the most probable languages predicted by ULS.
compactLanguages = compactLanguages.concat( this.filterByCommonLanguages( languages ) ); compactLanguages = compactLanguages.concat( this.filterByCommonLanguages( languages ) );
// Finally add the whole languages array too. We will remove duplicate and cut down
// to required size. // Finally add the whole languages array too.
// We will remove duplicate and cut down to required size.
compactLanguages = compactLanguages.concat( languages ); compactLanguages = compactLanguages.concat( languages );
// Remove duplicates // Remove duplicates
compactLanguages = unique( compactLanguages ); compactLanguages = unique( compactLanguages );
// Cut to compact size and sort // Cut to compact size and sort
compactLanguages = compactLanguages.slice( 0, this.compactSize ).sort(); compactLanguages = compactLanguages.slice( 0, this.compactSize ).sort();
return compactLanguages; return compactLanguages;
}, },
/** /**
* Filter the language list by previous languages. Not all previous languages * Filter the language list by previous languages.
* will be present in interlanguage links. So filtering them. * Not all previous languages will be present in interlanguage links,
* so we are filtering them.
* @return {Array} List of those language codes which are supported by article * @return {Array} List of those language codes which are supported by article
*/ */
filterByPreviousLanguages: function ( languages ) { filterByPreviousLanguages: function ( languages ) {
var previousLanguages; var previousLanguages = mw.uls.getPreviousLanguages();
previousLanguages = mw.uls.getPreviousLanguages();
return $.grep( previousLanguages, function ( language ) { return $.grep( previousLanguages, function ( language ) {
return $.inArray( language, languages ) >= 0; return $.inArray( language, languages ) >= 0;
} ); } );
}, },
/** /**
* Filter the language list by common languages. Common languages are the most * Filter the language list by common languages.
* probable languages predicted by ULS * Common languages are the most probable languages predicted by ULS.
* @return {Array} List of those language codes which are supported by article * @return {Array} List of those language codes which are supported by article
*/ */
filterByCommonLanguages: function ( languages ) { filterByCommonLanguages: function ( languages ) {
var commonLanguages; var commonLanguages = mw.uls.getFrequentLanguageList();
commonLanguages = mw.uls.getFrequentLanguageList();
return $.grep( commonLanguages, function ( language ) { return $.grep( commonLanguages, function ( language ) {
return $.inArray( language, languages ) >= 0; return $.inArray( language, languages ) >= 0;
} ); } );
@@ -200,7 +216,7 @@
/** /**
* Find out the existing languages supported * Find out the existing languages supported
* by article and fetch their href * by article and fetch their href.
* @return {Object} List of existing language codes and their hrefs * @return {Object} List of existing language codes and their hrefs
*/ */
getInterlanguageList: function getInterlanguageList() { getInterlanguageList: function getInterlanguageList() {
@@ -208,11 +224,13 @@
this.$interlanguageList.find( 'li.interlanguage-link > a' ).each( function () { this.$interlanguageList.find( 'li.interlanguage-link > a' ).each( function () {
var $this = $( this ); var $this = $( this );
interlanguageList[ $this.attr( 'lang' ) ] = { interlanguageList[ $this.attr( 'lang' ) ] = {
href: $this.attr( 'href' ), href: $this.attr( 'href' ),
autonym: $this.text() autonym: $this.text()
}; };
} ); } );
return interlanguageList; return interlanguageList;
}, },
@@ -245,6 +263,7 @@
$triggerLabel = $( '<label>' ) $triggerLabel = $( '<label>' )
.attr( 'id', 'more-lang-label' ) .attr( 'id', 'more-lang-label' )
.text( $.i18n( 'ext-uls-compact-link-count', this.listSize - this.compactSize ) ); .text( $.i18n( 'ext-uls-compact-link-count', this.listSize - this.compactSize ) );
this.$interlanguageList.append( $trigger, $triggerLabel ); this.$interlanguageList.append( $trigger, $triggerLabel );
this.$trigger = $trigger; this.$trigger = $trigger;
}, },
@@ -288,5 +307,4 @@
$( document ).ready( function () { $( document ).ready( function () {
$( '#p-lang-list' ).compactInterlanguageList(); $( '#p-lang-list' ).compactInterlanguageList();
} ); } );
}( jQuery, mediaWiki ) ); }( jQuery, mediaWiki ) );