/*!
* ULS-based language settings dialog for MediaWiki.
*
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
* contributors. See CREDITS for a list.
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
( function () {
'use strict';
var closeRow, settingsMenu, settingsPanel, windowTemplate, panelsRow, buttonsRow;
closeRow = '
' +
'
' +
'
';
settingsMenu = '
' +
'' +
'
' +
'
' +
'
';
settingsPanel = '
' +
'
';
// Apply and Cancel buttons
buttonsRow = '
' +
'
' +
'' +
'' +
'
' +
'
' +
'';
panelsRow = '
' +
settingsMenu +
settingsPanel +
'
';
windowTemplate = '
' +
closeRow +
panelsRow +
buttonsRow +
'
';
function LanguageSettings( element, options ) {
this.$element = $( element );
this.options = $.extend( {}, $.fn.languagesettings.defaults, options );
this.$window = $( this.options.template );
this.shown = false;
this.initialized = false;
this.left = this.options.left;
this.top = this.options.top;
this.modules = {};
this.$settingsPanel = this.$window.find( '#languagesettings-settings-panel' );
this.init();
this.listen();
}
LanguageSettings.prototype = {
constructor: LanguageSettings,
init: function () {
$( 'body' ).append( this.$window );
this.hide();
},
// Register all event listeners to the ULS language settings here.
listen: function () {
this.$element.on( 'click', this.click.bind( this ) );
this.$window.find( '#languagesettings-close, button.uls-settings-cancel' )
.on( 'click', mw.hook( 'mw.uls.settings.cancel' ).fire.bind( this ) );
this.$window.find( 'button.uls-settings-apply' )
.on( 'click', mw.hook( 'mw.uls.settings.apply' ).fire.bind( this ) );
// Hide the window when clicked outside
$( 'html' ).on( 'click', this.hide.bind( this ) );
// ... but when clicked on window do not hide.
this.$window.on( 'click', function ( event ) {
event.stopPropagation();
} );
// Map Escape to same action as the close button. This is keyup (and not keydown)
// because ULS also listens to keyup and we need to stop propagation.
this.$window.on( 'keyup', function ( event ) {
if ( event.which === 27 ) {
event.stopPropagation();
mw.hook( 'mw.uls.settings.cancel' ).fire();
}
} );
},
render: function () {
var modules,
languageSettings = this,
defaultModule = this.options.defaultModule;
// Get the name of all registered modules and list them in left side menu.
// Sort the modules based on id
modules = Object.keys( $.fn.languagesettings.modules ).sort();
modules.forEach( function ( moduleName ) {
if ( !defaultModule ) {
defaultModule = moduleName;
}
// Call render function on the current setting module.
languageSettings.initModule( moduleName, defaultModule === moduleName );
} );
},
/**
* Initialize the module.
* Render the link and settings area for a language setting module.
*
* @param {string} moduleName Name of the setting module
* @param {boolean} active boolean Make this module active and show by default
*/
initModule: function ( moduleName, active ) {
var $settingsTitle, $settingsText, $settingsLink,
languageSettings = this,
module = new $.fn.languagesettings.modules[ moduleName ]( languageSettings ),
$settingsMenuItems = languageSettings.$window.find( '.settings-menu-items' );
$settingsTitle = $( '