2013-07-08 21:20:31 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface LanguageInputWidget class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.LanguageInputWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.TextInputWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-07-08 21:20:31 +00:00
|
|
|
*/
|
|
|
|
ve.ui.LanguageInputWidget = function VeUiLanguageInputWidget( config ) {
|
|
|
|
var ulsParams, langInpObj, table;
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.Widget.call( this, config );
|
|
|
|
|
2013-08-10 09:27:20 +00:00
|
|
|
// Visual Properties
|
2013-07-08 21:20:31 +00:00
|
|
|
this.$langCodeDisp = this.getDisplayElement( config ); // language code
|
|
|
|
this.$langNameDisp = this.getDisplayElement( config ); // human-readable language name
|
|
|
|
this.$dirDisp = this.getDisplayElement( config );
|
|
|
|
|
2013-08-10 09:27:20 +00:00
|
|
|
// Placeholders for attribute values
|
2013-07-08 21:20:31 +00:00
|
|
|
this.lang = '';
|
|
|
|
this.dir = '';
|
|
|
|
|
|
|
|
// Create the informational table:
|
|
|
|
table = $( '<table>' ).css( { 'width': '100%' } )
|
|
|
|
.addClass( 've-LanguageInspector-information' )
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-title' )
|
|
|
|
.text( ve.msg( 'visualeditor-languageinspector-widget-label-language' ) ) )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-langname' )
|
|
|
|
.append( this.$langNameDisp ) ) )
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-title' )
|
|
|
|
.text( ve.msg( 'visualeditor-languageinspector-widget-label-langcode' ) ) )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-langcode' )
|
|
|
|
.append( this.$langCodeDisp ) ) )
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-title' )
|
|
|
|
.text( ve.msg( 'visualeditor-languageinspector-widget-label-direction' ) ) )
|
|
|
|
.append( $( '<td>' )
|
|
|
|
.addClass( 've-ui-LanguageInspector-info-dir' )
|
|
|
|
.append( this.$dirDisp ) ) );
|
|
|
|
this.$.append( table );
|
|
|
|
|
|
|
|
// Use a different reference than 'this' to avoid scope problems
|
|
|
|
// inside the $.ULS callback:
|
|
|
|
langInpObj = this;
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$.addClass( 've-ui-LangInputWidget' );
|
|
|
|
|
|
|
|
ulsParams = {
|
|
|
|
onSelect: function( language ) {
|
2013-08-10 09:27:20 +00:00
|
|
|
// Save the attributes:
|
|
|
|
langInpObj.setAttributes( language, $.uls.data.getDir( language ) );
|
2013-07-08 21:20:31 +00:00
|
|
|
},
|
|
|
|
compact: true,
|
|
|
|
// Temporary Quicklist for the Prototype:
|
|
|
|
// (This will likely change once we find a better list)
|
|
|
|
quickList: [ 'en', 'hi', 'he', 'ml', 'ta', 'fr' ]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a 'change language' Button:
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$button = new ve.ui.PushButtonWidget({
|
2013-07-08 21:20:31 +00:00
|
|
|
'label': ve.msg( 'visualeditor-languageinspector-widget-changelang' ),
|
|
|
|
'flags': ['primary']
|
|
|
|
});
|
|
|
|
|
|
|
|
// Attach ULS event call
|
|
|
|
this.$button.$.uls( ulsParams );
|
|
|
|
|
|
|
|
this.$.append( this.$button.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.LanguageInputWidget, ve.ui.Widget );
|
|
|
|
|
2013-08-10 09:27:20 +00:00
|
|
|
/* Static properties */
|
|
|
|
|
2013-07-08 21:20:31 +00:00
|
|
|
/* Methods */
|
2013-08-10 09:27:20 +00:00
|
|
|
|
2013-07-08 21:20:31 +00:00
|
|
|
/**
|
|
|
|
* Get display element. This replaces the 'getInputElement'
|
|
|
|
* of the InputWidget
|
|
|
|
*
|
|
|
|
* @method
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-07-08 21:20:31 +00:00
|
|
|
* @returns {jQuery} span element
|
|
|
|
*/
|
|
|
|
ve.ui.LanguageInputWidget.prototype.getDisplayElement = function () {
|
|
|
|
return this.$$( '<span>' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-08-10 09:27:20 +00:00
|
|
|
* Return the current language attributes
|
2013-07-08 21:20:31 +00:00
|
|
|
*
|
2013-08-10 09:27:20 +00:00
|
|
|
*/
|
|
|
|
ve.ui.LanguageInputWidget.prototype.getAttributes = function () {
|
|
|
|
return {
|
|
|
|
'lang': this.lang,
|
|
|
|
'dir': this.dir
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current language attributes
|
2013-07-08 21:20:31 +00:00
|
|
|
*
|
|
|
|
*/
|
2013-08-10 09:27:20 +00:00
|
|
|
ve.ui.LanguageInputWidget.prototype.setAttributes = function ( lang, dir ) {
|
|
|
|
this.lang = lang;
|
|
|
|
this.dir = dir;
|
|
|
|
// Update the view:
|
|
|
|
this.updateLanguageTable();
|
2013-07-08 21:20:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-08-10 09:27:20 +00:00
|
|
|
* Get the language value of the current annotation
|
|
|
|
* This is required by the AnnotationInspector onClose method
|
2013-07-08 21:20:31 +00:00
|
|
|
*/
|
|
|
|
ve.ui.LanguageInputWidget.prototype.getValue = function () {
|
|
|
|
// Specifically to be displayed
|
2013-08-27 23:45:38 +00:00
|
|
|
return this.$langNameDisp.text();
|
2013-07-08 21:20:31 +00:00
|
|
|
};
|
2013-08-10 09:27:20 +00:00
|
|
|
|
2013-07-08 21:20:31 +00:00
|
|
|
/**
|
2013-08-10 09:27:20 +00:00
|
|
|
* Updates the language value in the display table
|
2013-07-08 21:20:31 +00:00
|
|
|
*
|
2013-08-10 09:27:20 +00:00
|
|
|
* This shouldn't be used directly. It is called from the
|
|
|
|
* setAttributes method after receiving annotation details
|
|
|
|
* to make sure the annotation and the table are synchronized.
|
2013-07-08 21:20:31 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-08-10 09:27:20 +00:00
|
|
|
ve.ui.LanguageInputWidget.prototype.updateLanguageTable = function () {
|
2013-07-08 21:20:31 +00:00
|
|
|
var langNameDisp = '';
|
|
|
|
|
2013-08-10 09:27:20 +00:00
|
|
|
if ( this.lang ) {
|
2013-07-08 21:20:31 +00:00
|
|
|
langNameDisp = $.uls.data.getAutonym( this.lang );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the information in the table:
|
|
|
|
this.$langCodeDisp.html( this.lang );
|
|
|
|
this.$langNameDisp.html( langNameDisp );
|
|
|
|
this.$dirDisp.html( this.dir );
|
|
|
|
};
|