mediawiki-extensions-Visual.../modules/ve/dm/annotations/ve.dm.LanguageAnnotation.js
Trevor Parscal 8dfbc5baa5 Make tools generic and add fancy tool groups
Objectives:

* Got rid of mw prefixing in tools, inspectors and dialogs
* Simplify tool classes so they can be generically used as items in bars, lists and menus
* Add support for a catch-all toolbar group
* Simplify tool registration, leaning on tool classes' static name property
* Move default commands to command registry
* Move default triggers to trigger registry
* Get language tool working in standalone

Change-Id: Ic97a636f9a193374728629931b6702bee1b3416a
2013-09-03 11:27:39 -07:00

70 lines
1.8 KiB
JavaScript

/*!
* 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 */
ve.inheritClass( ve.dm.LanguageAnnotation, ve.dm.Annotation );
/* Static Properties */
ve.dm.LanguageAnnotation.static.name = 'meta/language';
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 {
'type': 'meta/language',
'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 */
// TODO:
// Set up a proper comparable method for lang and dir attributes
// ve.dm.LanguageAnnotation.prototype.getComparableObject
/* Registration */
ve.dm.modelRegistry.register( ve.dm.LanguageAnnotation );