2017-06-09 18:01:37 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWLanuageVariantNodeContextItem class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
|
2017-06-09 18:01:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-09-14 15:05:56 +00:00
|
|
|
* Context item for a ve.dm.MWLanguageVariantNode.
|
2017-06-09 18:01:37 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinearContextItem
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Context} context Context item is in
|
|
|
|
* @param {ve.dm.MWLanguageVariantNode} model Model item is related to
|
|
|
|
* @param {Object} config Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem = function VeUiMWLanguageVariantNodeContextItem() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwLanguageVariantNodeContextItem' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWLanguageVariantNodeContextItem, ve.ui.LinearContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.static.name = 'mwLanguageVariant';
|
|
|
|
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.static.icon = 'language';
|
|
|
|
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.static.label = null; // see #setup()
|
|
|
|
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.static.modelClasses = [
|
|
|
|
ve.dm.MWLanguageVariantBlockNode,
|
|
|
|
ve.dm.MWLanguageVariantInlineNode,
|
|
|
|
ve.dm.MWLanguageVariantHiddenNode
|
|
|
|
];
|
|
|
|
|
2017-06-28 18:15:29 +00:00
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.static.commandName = 'mwLanguageVariant';
|
2017-06-09 18:01:37 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.prototype.setup = function () {
|
|
|
|
// Set up label
|
|
|
|
var messageKey = 'visualeditor-mwlanguagevariantcontextitem-title-' +
|
|
|
|
this.model.getRuleType();
|
2019-11-01 16:20:22 +00:00
|
|
|
|
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-disabled
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-filter
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-name
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-oneway
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-twoway
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-title-unknown
|
2017-06-09 18:01:37 +00:00
|
|
|
this.setLabel( OO.ui.deferMsg( messageKey ) );
|
2019-11-01 16:20:22 +00:00
|
|
|
|
2017-06-09 18:01:37 +00:00
|
|
|
// Invoke superclass method.
|
|
|
|
return ve.ui.MWLanguageVariantNodeContextItem.super.prototype.setup.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.prototype.renderBody = function () {
|
|
|
|
var $body = this.$body,
|
|
|
|
$table = $( '<table>' ),
|
2018-11-21 18:47:19 +00:00
|
|
|
$header = $( '<tr>' ),
|
2017-06-09 18:01:37 +00:00
|
|
|
variantInfo = this.model.getVariantInfo(),
|
|
|
|
type = this.model.getRuleType(),
|
2022-02-21 18:07:07 +00:00
|
|
|
isHidden = this.model.isHidden();
|
2017-06-09 18:01:37 +00:00
|
|
|
|
|
|
|
$table.addClass(
|
|
|
|
've-ui-mwLanguageVariantNodeContextItem-rule-table'
|
|
|
|
);
|
|
|
|
$table.append( $header );
|
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
case 'filter':
|
|
|
|
case 'name':
|
|
|
|
$header
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-name-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-code-label' )
|
|
|
|
) );
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
var languageCodes = ( type === 'filter' ) ?
|
2017-06-09 18:01:37 +00:00
|
|
|
variantInfo.filter.l : [ variantInfo.name.t ];
|
|
|
|
languageCodes.forEach( function ( code ) {
|
|
|
|
var name = ve.init.platform.getLanguageName( code.toLowerCase() );
|
|
|
|
if ( !name ) {
|
|
|
|
name = ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-invalid-language-label' );
|
|
|
|
}
|
|
|
|
$table
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' ).text( name ).attr( 'lang', code ) )
|
|
|
|
.append( $( '<td>' ).text( code ) )
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'oneway':
|
|
|
|
$header
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-name-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-code-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-text-from-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-text-to-label' )
|
|
|
|
) );
|
|
|
|
|
|
|
|
variantInfo.oneway.forEach( function ( item ) {
|
2021-11-15 17:03:35 +00:00
|
|
|
// Safe HTML from the parser
|
|
|
|
// eslint-disable-next-line no-jquery/no-html
|
2017-06-09 18:01:37 +00:00
|
|
|
var $fromText = $( '<td>' ).html( item.f ),
|
2021-11-15 17:03:35 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-html
|
2017-06-09 18:01:37 +00:00
|
|
|
$toText = $( '<td>' ).html( item.t ),
|
|
|
|
code = item.l,
|
|
|
|
name = ve.init.platform.getLanguageName( code.toLowerCase() );
|
|
|
|
$table
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' ).text( name ).attr( 'lang', code ) )
|
|
|
|
.append( $( '<td>' ).text( code ) )
|
|
|
|
.append( $fromText )
|
|
|
|
.append( $toText )
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'twoway':
|
|
|
|
$header
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-name-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-code-label' )
|
|
|
|
) )
|
2021-10-25 15:51:29 +00:00
|
|
|
.append( $( '<th>' ).text(
|
2017-06-09 18:01:37 +00:00
|
|
|
ve.msg( 'visualeditor-mwlanguagevariantcontextitem-rule-text-twoway-label' )
|
|
|
|
) );
|
|
|
|
|
|
|
|
variantInfo.twoway.forEach( function ( item ) {
|
|
|
|
var code = item.l,
|
|
|
|
name = ve.init.platform.getLanguageName( code.toLowerCase() ),
|
2021-11-15 17:03:35 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-html
|
2017-06-09 18:01:37 +00:00
|
|
|
$text = $( '<td>' ).html( item.t );
|
|
|
|
ve.dm.MWLanguageVariantNode.static.processVariants(
|
2019-11-02 16:28:32 +00:00
|
|
|
$text[ 0 ], { showHidden: true }
|
2017-06-09 18:01:37 +00:00
|
|
|
);
|
|
|
|
$table
|
|
|
|
.append( $( '<tr>' )
|
|
|
|
.append( $( '<td>' ).text( name ).attr( 'lang', code ) )
|
|
|
|
.append( $( '<td>' ).text( code ) )
|
|
|
|
.append( $text )
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-09-06 12:52:40 +00:00
|
|
|
if ( $table.find( 'tr' ).length > 1 ) {
|
2017-06-09 18:01:37 +00:00
|
|
|
// Don't put $table in $body if the table is empty; this allows
|
|
|
|
// CSS :empty rules to have their proper effect.
|
|
|
|
ve.dm.MWLanguageVariantNode.static.processVariants(
|
2019-11-02 16:28:32 +00:00
|
|
|
$table[ 0 ], { showHidden: true }
|
2017-06-09 18:01:37 +00:00
|
|
|
);
|
|
|
|
$body.append( $table );
|
|
|
|
}
|
|
|
|
// Show "extra" properties, like describe, title, etc.
|
|
|
|
[ 'describe', 'title', 'hidden' ].forEach( function ( flag ) {
|
|
|
|
var f = ( flag === 'hidden' ) ? isHidden : variantInfo[ flag ];
|
|
|
|
if ( f ) {
|
2019-11-01 16:20:22 +00:00
|
|
|
// The following messages can be used here:
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-flag-describe
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-flag-hidden
|
|
|
|
// * visualeditor-mwlanguagevariantcontextitem-flag-title
|
2017-06-09 18:01:37 +00:00
|
|
|
$body.append( $( '<p>' ).text( OO.ui.msg(
|
|
|
|
'visualeditor-mwlanguagevariantcontextitem-flag-' + flag
|
|
|
|
) ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2017-06-28 18:15:29 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguageVariantNodeContextItem.prototype.getCommand = function () {
|
|
|
|
var type = this.model.getRuleType(),
|
|
|
|
cmdName = this.constructor.static.commandName + '-' + type;
|
|
|
|
return this.context.getSurface().commandRegistry.lookup( cmdName );
|
|
|
|
};
|
|
|
|
|
2017-06-09 18:01:37 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWLanguageVariantNodeContextItem );
|
2017-06-28 18:15:29 +00:00
|
|
|
|
|
|
|
[ 'disabled', 'filter', 'name', 'twoway', 'oneway' ].forEach( function ( type ) {
|
|
|
|
ve.ui.commandRegistry.register(
|
|
|
|
new ve.ui.Command(
|
|
|
|
'mwLanguageVariant-' + type, 'window', 'open',
|
|
|
|
{
|
|
|
|
args: [ 'mwLanguageVariant-' + type ],
|
|
|
|
supportedSelections: [ 'linear' ]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|