2013-07-10 14:49:46 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel LanguageAnnotation class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel language annotation.
|
|
|
|
*
|
|
|
|
* Represents `<span>` tags with 'lang' and 'dir' properties.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.Annotation
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} element
|
|
|
|
*/
|
|
|
|
ve.dm.LanguageAnnotation = function VeDmLanguageAnnotation( element ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.Annotation.call( this, element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.LanguageAnnotation, ve.dm.Annotation );
|
2013-07-10 14:49:46 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.dm.LanguageAnnotation.static.name = 'meta/language';
|
2013-07-10 14:49:46 +00:00
|
|
|
|
|
|
|
ve.dm.LanguageAnnotation.static.matchTagNames = [ 'span' ];
|
|
|
|
|
|
|
|
ve.dm.LanguageAnnotation.static.matchFunction = function( domElement ) {
|
|
|
|
return ( domElement.getAttribute( 'lang' ) || domElement.getAttribute( 'dir' ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.LanguageAnnotation.static.applyToAppendedContent = false;
|
|
|
|
|
|
|
|
ve.dm.LanguageAnnotation.static.toDataElement = function ( domElements ) {
|
|
|
|
return {
|
2013-08-27 23:28:29 +00:00
|
|
|
'type': 'meta/language',
|
2013-07-10 14:49:46 +00:00
|
|
|
'attributes': {
|
|
|
|
'lang': domElements[0].getAttribute( 'lang' ),
|
|
|
|
'dir': domElements[0].getAttribute( 'dir' )
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.LanguageAnnotation.static.toDomElements = function ( dataElement, doc ) {
|
|
|
|
var domElement = doc.createElement( 'span' );
|
|
|
|
if ( dataElement.attributes.lang ) {
|
|
|
|
domElement.setAttribute( 'lang', dataElement.attributes.lang );
|
|
|
|
}
|
|
|
|
if ( dataElement.attributes.dir ) {
|
|
|
|
domElement.setAttribute( 'dir', dataElement.attributes.dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ domElement ];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-09-23 18:41:34 +00:00
|
|
|
/**
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
ve.dm.LanguageAnnotation.prototype.getComparableObject = function () {
|
|
|
|
return {
|
|
|
|
'type': 'meta/language',
|
|
|
|
'lang': this.getAttribute( 'lang' )
|
|
|
|
};
|
|
|
|
};
|
2013-07-10 14:49:46 +00:00
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.LanguageAnnotation );
|