' )
.addClass( 'settings-title' )
.attr( 'data-i18n', module.nameI18n );
$settingsText = $( '
' )
.addClass( 'settings-text' )
.attr( 'data-i18n', module.descriptionI18n );
$settingsLink = $( '' )
.addClass( moduleName + '-settings-block menu-section' )
.prop( 'id', moduleName + '-panel-trigger' )
.data( 'module', module )
.append(
$settingsTitle,
$settingsText
);
if ( active ) {
$settingsLink.addClass( 'active' );
}
$settingsMenuItems.append( $settingsLink );
$settingsLink.on( 'click', function () {
var $this = $( this );
$this.data( 'module' ).render();
languageSettings.$window.scrollIntoView();
$settingsMenuItems.find( '.menu-section' ).removeClass( 'active' );
$this.addClass( 'active' );
} );
this.modules[ moduleName ] = module;
// Register cancel and apply hooks
mw.hook( 'mw.uls.settings.cancel' ).add( $.proxy( module.cancel, module ) );
mw.hook( 'mw.uls.settings.apply' ).add( $.proxy( module.apply, module ) );
},
position: function () {
this.top = this.top || this.$element.offset().top + this.$element.outerHeight();
this.left = this.left || '25%';
this.$window.css( {
top: this.top,
left: this.left
} );
},
i18n: function () {
this.$window.i18n();
},
show: function () {
this.position();
if ( !this.initialized ) {
this.render();
this.initialized = true;
}
// Close other modal windows which listen to click events outside them
$( 'html' ).click();
this.i18n();
// Every time we show this window, make sure the current
// settings panels is up-to-date. So just click on active menu item.
this.$window.find( '.settings-menu-items > .active' ).click();
this.shown = true;
this.$window.show();
this.visible();
this.$window.scrollIntoView();
},
/**
* A "hook" that runs after the ULS panel becomes visible
* by using the show method.
*
* To use it, pass a function as the onVisible parameter
* in the options when initializing ULS.
*/
visible: function () {
if ( this.options.onVisible ) {
this.options.onVisible.call( this );
}
},
/**
* Hide this window.
* Will be used when moving to a different context and
* need coming back.
*/
hide: function () {
this.shown = false;
this.$window.hide();
},
/**
* Put the language settings panel in busy mode.
* Busy mode means displaying a progress cursor,
* and showing the 'apply' button as disabled and with
* a different label.
*
* @param {boolean} busy set true to put the panel in busy mode,
* false to unset the busy mode.
*/
setBusy: function ( busy ) {
var $applyButton = this.$window.find( 'button.uls-settings-apply' );
if ( busy ) {
this.$window.addClass( 'waiting' );
$applyButton
.text( $.i18n( 'ext-uls-language-settings-applying' ) )
.prop( 'disabled', true );
} else {
this.$window.removeClass( 'waiting' );
$applyButton.text( $.i18n( 'ext-uls-language-settings-apply' ) );
}
},
/**
* Close this language settings window, and
* call onClose if defined from the previous context.
*/
close: function () {
if ( !this.shown ) {
return;
}
this.hide();
// optional callback
if ( this.options.onClose ) {
this.options.onClose();
}
},
click: function ( e ) {
e.stopPropagation();
e.preventDefault();
if ( this.shown ) {
this.hide();
} else {
this.show();
}
},
disableApplyButton: function () {
this.$window.find( 'button.uls-settings-apply' ).prop( 'disabled', true );
}
};
$.fn.languagesettings = function ( option ) {
return this.each( function () {
var $this = $( this ),
data = $this.data( 'languagesettings' ),
options = typeof option === 'object' && option;
if ( !data ) {
$this.data( 'languagesettings', ( data = new LanguageSettings( this, options ) ) );
}
if ( typeof option === 'string' ) {
data[ option ]();
}
} );
};
$.fn.languagesettings.modules = {};
$.fn.languagesettings.defaults = {
template: windowTemplate,
defaultModule: false, // Name of the default module
onClose: null, // An onClose event handler.
top: null, // Top position of this window
left: null, // Left position of this window
onVisible: null // A callback that runs after the ULS panel becomes visible
};
$.fn.languagesettings.Constructor = LanguageSettings;
}( jQuery, mediaWiki ) );