Merge "Ensure ext.uls.mediawiki is loaded before use"
This commit is contained in:
@@ -57,7 +57,9 @@
|
|||||||
* Initialize the plugin
|
* Initialize the plugin
|
||||||
*/
|
*/
|
||||||
init: function () {
|
init: function () {
|
||||||
var max = this.options.max;
|
var self = this,
|
||||||
|
max = this.options.max;
|
||||||
|
|
||||||
this.interlanguageList = this.getInterlanguageList();
|
this.interlanguageList = this.getInterlanguageList();
|
||||||
this.listSize = Object.keys( this.interlanguageList ).length;
|
this.listSize = Object.keys( this.interlanguageList ).length;
|
||||||
|
|
||||||
@@ -66,13 +68,15 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're only a bit beyond max, limit to 7 instead of 9.
|
mw.loader.using( 'ext.uls.mediawiki' ).done( function () {
|
||||||
// FIXME: This assumes the max is 9.
|
// If we're only a bit beyond max, limit to 7 instead of 9.
|
||||||
this.compactSize = ( this.listSize <= 12 ) ? 7 : max;
|
// FIXME: This assumes the max is 9.
|
||||||
this.compactList = this.getCompactList();
|
self.compactSize = ( self.listSize <= 12 ) ? 7 : max;
|
||||||
this.hideOriginal();
|
self.compactList = self.getCompactList();
|
||||||
this.render();
|
self.hideOriginal();
|
||||||
this.listen();
|
self.render();
|
||||||
|
self.listen();
|
||||||
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,75 +109,73 @@
|
|||||||
return languageCode;
|
return languageCode;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return mw.loader.using( 'ext.uls.mediawiki' ).then( function () {
|
// Attach ULS to the trigger
|
||||||
// Attach ULS to the trigger
|
$trigger.uls( {
|
||||||
$trigger.uls( {
|
onReady: function () {
|
||||||
onReady: function () {
|
this.$menu.addClass( 'interlanguage-uls-menu' );
|
||||||
this.$menu.addClass( 'interlanguage-uls-menu' );
|
},
|
||||||
},
|
/**
|
||||||
/**
|
* Language selection handler
|
||||||
* Language selection handler
|
*
|
||||||
*
|
* @param {string} language language code
|
||||||
* @param {string} language language code
|
*/
|
||||||
*/
|
onSelect: function ( language ) {
|
||||||
onSelect: function ( language ) {
|
var previousLanguages = mw.uls.getPreviousLanguages();
|
||||||
var previousLanguages = mw.uls.getPreviousLanguages();
|
|
||||||
|
|
||||||
self.$trigger.removeClass( 'selector-open' );
|
self.$trigger.removeClass( 'selector-open' );
|
||||||
|
|
||||||
previousLanguages.push( language );
|
previousLanguages.push( language );
|
||||||
previousLanguages = unique( previousLanguages );
|
previousLanguages = unique( previousLanguages );
|
||||||
mw.uls.setPreviousLanguages( previousLanguages );
|
mw.uls.setPreviousLanguages( previousLanguages );
|
||||||
location.href = self.interlanguageList[ language ].href;
|
location.href = self.interlanguageList[ language ].href;
|
||||||
},
|
},
|
||||||
onVisible: function () {
|
onVisible: function () {
|
||||||
var offset, height, width, triangleWidth;
|
var offset, height, width, triangleWidth;
|
||||||
// The panel is positioned carefully so that our pointy triangle,
|
// The panel is positioned carefully so that our pointy triangle,
|
||||||
// which is implemented as a square box rotated 45 degrees with
|
// which is implemented as a square box rotated 45 degrees with
|
||||||
// rotation origin in the middle. See the corresponding style file.
|
// rotation origin in the middle. See the corresponding style file.
|
||||||
|
|
||||||
// These are for the trigger
|
// These are for the trigger
|
||||||
offset = $trigger.offset();
|
offset = $trigger.offset();
|
||||||
width = $trigger.outerWidth();
|
width = $trigger.outerWidth();
|
||||||
height = $trigger.outerHeight();
|
height = $trigger.outerHeight();
|
||||||
|
|
||||||
// Triangle width is: Math.sqrt( 2 * Math.pow( 25, 2 ) ) / 2 =~ 17.7;
|
// Triangle width is: Math.sqrt( 2 * Math.pow( 25, 2 ) ) / 2 =~ 17.7;
|
||||||
// Box width = 24 + 1 for border.
|
// Box width = 24 + 1 for border.
|
||||||
// The resulting value is rounded up 20 to have a small space between.
|
// The resulting value is rounded up 20 to have a small space between.
|
||||||
triangleWidth = 20;
|
triangleWidth = 20;
|
||||||
|
|
||||||
if ( dir === 'rtl' ) {
|
if ( dir === 'rtl' ) {
|
||||||
this.left = offset.left - this.$menu.outerWidth() - triangleWidth;
|
this.left = offset.left - this.$menu.outerWidth() - triangleWidth;
|
||||||
} else {
|
} else {
|
||||||
this.left = offset.left + width + triangleWidth;
|
this.left = offset.left + width + triangleWidth;
|
||||||
}
|
}
|
||||||
// Offset -250px from the middle of the trigger
|
// Offset -250px from the middle of the trigger
|
||||||
this.top = offset.top + ( height / 2 ) - 250;
|
this.top = offset.top + ( height / 2 ) - 250;
|
||||||
|
|
||||||
this.$menu.css( {
|
this.$menu.css( {
|
||||||
left: this.left,
|
left: this.left,
|
||||||
top: this.top
|
top: this.top
|
||||||
} );
|
} );
|
||||||
$trigger.addClass( 'selector-open' );
|
$trigger.addClass( 'selector-open' );
|
||||||
},
|
},
|
||||||
languageDecorator: function ( $languageLink, language ) {
|
languageDecorator: function ( $languageLink, language ) {
|
||||||
// set href and text exactly same as what was in
|
// set href and text exactly same as what was in
|
||||||
// interlanguage link. The ULS autonym might be different in some
|
// interlanguage link. The ULS autonym might be different in some
|
||||||
// cases like sr. In ULS it is "српски", while in interlanguage links
|
// cases like sr. In ULS it is "српски", while in interlanguage links
|
||||||
// it is "српски / srpski"
|
// it is "српски / srpski"
|
||||||
$languageLink
|
$languageLink
|
||||||
.prop( 'href', self.interlanguageList[ language ].href )
|
.prop( 'href', self.interlanguageList[ language ].href )
|
||||||
.text( self.interlanguageList[ language ].autonym );
|
.text( self.interlanguageList[ language ].autonym );
|
||||||
},
|
},
|
||||||
onCancel: function () {
|
onCancel: function () {
|
||||||
$trigger.removeClass( 'selector-open' );
|
$trigger.removeClass( 'selector-open' );
|
||||||
},
|
},
|
||||||
// Use compact version of ULS
|
// Use compact version of ULS
|
||||||
compact: true,
|
compact: true,
|
||||||
languages: ulsLanguageList,
|
languages: ulsLanguageList,
|
||||||
// Show common languages
|
// Show common languages
|
||||||
quickList: self.filterByCommonLanguages( languages )
|
quickList: self.filterByCommonLanguages( languages )
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -184,9 +186,8 @@
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.$trigger.one( 'click', function () {
|
this.$trigger.one( 'click', function () {
|
||||||
self.createSelector( self.$trigger ).then( function () {
|
self.createSelector( self.$trigger );
|
||||||
self.$trigger.click();
|
self.$trigger.click();
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user