mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
Merge "Language Inspector Default Fix"
This commit is contained in:
commit
0ef918b6f0
|
@ -96,8 +96,8 @@ ve.ui.LanguageInspector.prototype.onSetup = function () {
|
||||||
// This will be called only if the annotation doesn't already exist, setting
|
// This will be called only if the annotation doesn't already exist, setting
|
||||||
// the default value as the current language/dir of the selected text.
|
// the default value as the current language/dir of the selected text.
|
||||||
if ( fragDOM ) {
|
if ( fragDOM ) {
|
||||||
this.initLang = fragDOM.$.closest('[lang]').attr('lang') || 'en';
|
this.initLang = fragDOM.$.closest('[lang]').attr('lang');
|
||||||
this.initDir = fragDOM.$.closest('[dir]').css('direction') || 'ltr';
|
this.initDir = fragDOM.$.closest('[dir]').css('direction');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent method
|
// Parent method
|
||||||
|
@ -146,43 +146,47 @@ ve.ui.LanguageInspector.prototype.getAnnotation = function () {
|
||||||
* @chainable
|
* @chainable
|
||||||
*/
|
*/
|
||||||
ve.ui.LanguageInspector.prototype.setAnnotation = function ( annotation ) {
|
ve.ui.LanguageInspector.prototype.setAnnotation = function ( annotation ) {
|
||||||
var langCode = '',
|
var langCode, langDir, annData;
|
||||||
langDir = '';
|
|
||||||
|
|
||||||
// Validate the given annotation:
|
// Validate the given annotation:
|
||||||
|
|
||||||
// Give precedence to dir value if it already exists
|
// Give precedence to dir value if it already exists
|
||||||
// in the annotation:
|
// in the annotation:
|
||||||
if ( annotation.getAttribute( 'dir' ) ) {
|
langDir = annotation.getAttribute( 'dir' );
|
||||||
langDir = annotation.getAttribute( 'dir' );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set language according to the one in the given annotation
|
// Set language according to the one in the given annotation
|
||||||
// or leave blank if element has no language set
|
// or leave blank if element has no language set
|
||||||
if ( annotation.getAttribute( 'lang' ) ) {
|
langCode = annotation.getAttribute( 'lang' );
|
||||||
langCode = annotation.getAttribute( 'lang' );
|
|
||||||
}
|
|
||||||
|
|
||||||
// If language exists, but dir is undefined/null,
|
// If language exists, but dir is undefined/null,
|
||||||
// fix the dir in terms of language:
|
// fix the dir in terms of language:
|
||||||
if ( langCode && !langDir ) {
|
if ( langCode && !langDir ) {
|
||||||
langDir = $.uls.data.getDir( this.lang );
|
langDir = $.uls.data.getDir( langCode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the annotation data:
|
||||||
|
annData = {
|
||||||
|
'type': 'language',
|
||||||
|
'attributes': {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if ( langCode ) {
|
||||||
|
annData.attributes.lang = langCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( langDir ) {
|
||||||
|
annData.attributes.dir = langDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the widget:
|
||||||
|
this.targetInput.setAttributes( langCode, langDir );
|
||||||
|
|
||||||
|
// Update inspector properties:
|
||||||
this.lang = langCode;
|
this.lang = langCode;
|
||||||
this.dir = langDir;
|
this.dir = langDir;
|
||||||
|
|
||||||
// Update the widget:
|
// Set up the annotation:
|
||||||
this.targetInput.setAttributes( this.lang, this.dir );
|
this.annotation = new ve.dm.LanguageAnnotation( annData );
|
||||||
|
|
||||||
// Set the annotation:
|
|
||||||
this.annotation = new ve.dm.LanguageAnnotation( {
|
|
||||||
'type': 'language',
|
|
||||||
'attributes': {
|
|
||||||
'lang': this.lang,
|
|
||||||
'dir': this.dir
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue