' )
.addClass( 'settings-title' )
.text( module.name );
$settingsText = $( '
' )
.addClass( 'settings-text' )
.text( module.description );
$settingsLink = $( '' )
.addClass( moduleName + '-settings-block menu-section' )
.prop( 'id', moduleName + '-settings-block' )
.data( 'module', module )
.append( $settingsTitle )
.append( $settingsText );
$settingsMenuItems.append( $settingsLink );
$settingsLink.on( 'click', function () {
var scrollPosition,
panelHeight, panelTop, panelBottom,
padding = 10,
$window = $( window ),
windowHeight = $window.height(),
windowScrollTop = $window.scrollTop(),
windowBottom = windowScrollTop + windowHeight,
module = $( this ).data( 'module' );
module.render();
panelHeight = languageSettings.$window.height();
panelTop = languageSettings.$window.offset().top;
panelBottom = panelTop + panelHeight;
// If the ULS panel is out of the viewport,
// scroll the window to show it
if ( ( panelTop < windowScrollTop ) || ( panelBottom > windowBottom ) ) {
if ( panelHeight > windowHeight ) {
// Scroll to show as much of the upper
// part of ULS as possible
scrollPosition = panelTop - padding;
} else {
// Scroll just enough to show the ULS panel
scrollPosition = panelBottom - windowHeight + padding;
}
$( 'html, body' ).stop().animate( {
scrollTop: scrollPosition
}, 500 );
}
$settingsMenuItems.find( '.menu-section' ).removeClass( 'active' );
$( this ).addClass( 'active' );
} );
if ( active ) {
module.render();
$settingsLink.addClass( 'active' );
}
},
show: function () {
if ( !this.initialized ) {
var top, pos, left;
this.render();
this.initialized = true;
pos = $.extend( {}, this.$element.offset(), {
height: this.$element[0].offsetHeight
} );
top = this.top || pos.top + pos.height;
left = this.left || '25%';
// FIXME this is not exactly correct. position may not
// be relative to the trigger.
this.$window.css( {
top: top,
left: left
} );
}
this.$window.i18n();
this.shown = true;
this.$window.show();
},
/**
* Hide this window.
* Will be used when moving to a different context and
* need coming back.
*/
hide: function () {
this.shown = false;
this.$window.hide();
},
/**
* Close this language settings window, and
* call onClose if defined from the previous context.
*/
close: function () {
this.hide();
if ( this.options.onClose ) {
this.options.onClose();
}
},
click: function () {
if ( !this.shown ) {
this.show();
}
}
};
$.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
};
$.fn.languagesettings.Constructor = LanguageSettings;
}( jQuery ) );