2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor data model TextStyleAnnotation class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-31 23:50:16 +00:00
|
|
|
/**
|
|
|
|
* DataModel annotation for a text style.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.dm.Annotation}
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.TextStyleAnnotation = function () {
|
2012-05-31 23:50:16 +00:00
|
|
|
// Inheritance
|
|
|
|
ve.dm.Annotation.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converters.
|
|
|
|
*
|
|
|
|
* @see {ve.dm.Converter}
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.TextStyleAnnotation.converters = {
|
2012-06-07 00:47:27 +00:00
|
|
|
'domElementTypes': ['i', 'b', 'u', 's', 'small', 'big', 'span'],
|
2012-08-07 01:50:44 +00:00
|
|
|
'toDomElement': function ( subType, annotation ) {
|
2012-08-09 20:30:21 +00:00
|
|
|
var map = {
|
2012-06-01 00:02:50 +00:00
|
|
|
'italic': 'i',
|
|
|
|
'bold': 'b',
|
|
|
|
'underline': 'u',
|
|
|
|
'strike': 's',
|
|
|
|
'small': 'small',
|
|
|
|
'big': 'big',
|
2012-06-21 21:46:43 +00:00
|
|
|
'span': 'span',
|
|
|
|
'strong': 'strong',
|
|
|
|
'emphasize': 'em',
|
|
|
|
'superScript': 'sup',
|
|
|
|
'subScript': 'sub'
|
2012-06-07 00:47:27 +00:00
|
|
|
// TODO: Add other supported inline DOM elements to this list
|
2012-08-09 20:30:21 +00:00
|
|
|
};
|
|
|
|
return $( document.createElement( map[subType] ) )
|
|
|
|
// Restore HTML attributes
|
|
|
|
// Will be done for us in the new annotation API
|
2012-08-10 17:23:14 +00:00
|
|
|
.attr( annotation.htmlAttributes || {} )
|
2012-08-09 20:30:21 +00:00
|
|
|
.get( 0 );
|
2012-06-01 00:02:50 +00:00
|
|
|
},
|
2012-08-07 01:50:44 +00:00
|
|
|
'toDataAnnotation': function ( tag, element ) {
|
2012-08-09 20:30:21 +00:00
|
|
|
var annotation, i, length,
|
|
|
|
map = {
|
2012-06-01 00:02:50 +00:00
|
|
|
'i': 'italic',
|
|
|
|
'b': 'bold',
|
|
|
|
'u': 'underline',
|
|
|
|
's': 'strike',
|
2012-05-31 23:50:16 +00:00
|
|
|
'small': 'small',
|
|
|
|
'big': 'big',
|
2012-06-21 21:46:43 +00:00
|
|
|
'span': 'span',
|
|
|
|
'strong': 'strong',
|
|
|
|
'em': 'emphasize',
|
|
|
|
'sup': 'superScript',
|
|
|
|
'sub': 'subScript'
|
2012-06-07 00:47:27 +00:00
|
|
|
// TODO: Add other supported inline DOM elements to this list
|
2012-08-09 20:30:21 +00:00
|
|
|
};
|
|
|
|
annotation = {
|
2012-08-10 23:49:14 +00:00
|
|
|
type: 'textStyle/' + map[tag]
|
2012-06-01 00:02:50 +00:00
|
|
|
};
|
2012-08-09 20:30:21 +00:00
|
|
|
// Preserve HTML attributes
|
|
|
|
// Will be done for us in the new annotation API
|
2012-08-10 17:23:14 +00:00
|
|
|
length = element.attributes.length;
|
|
|
|
if ( length > 0 ) {
|
|
|
|
annotation.htmlAttributes = {};
|
|
|
|
for ( i = 0; i < length; i++ ) {
|
|
|
|
annotation.htmlAttributes[element.attributes[i].name] = element.attributes[i].value;
|
|
|
|
}
|
2012-08-09 20:30:21 +00:00
|
|
|
}
|
|
|
|
return annotation;
|
2012-05-31 23:50:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.annotationFactory.register( 'textStyle', ve.dm.TextStyleAnnotation );
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.TextStyleAnnotation, ve.dm.Annotation );
|