2012-05-31 23:50:16 +00:00
|
|
|
/**
|
|
|
|
* DataModel annotation for a link.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.dm.Annotation}
|
|
|
|
*/
|
|
|
|
ve.dm.LinkAnnotation = function() {
|
|
|
|
// Inheritance
|
|
|
|
ve.dm.Annotation.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converters.
|
|
|
|
*
|
|
|
|
* @see {ve.dm.Converter}
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.LinkAnnotation.converters = {
|
2012-06-07 00:47:27 +00:00
|
|
|
'domElementTypes': ['a'],
|
|
|
|
'toDomElement': function( subType, annotation ) {
|
2012-06-07 22:02:25 +00:00
|
|
|
if ( annotation.type ) {
|
2012-06-08 04:16:55 +00:00
|
|
|
var link = document.createElement( 'a' );
|
2012-06-08 22:17:18 +00:00
|
|
|
link.setAttribute( 'href', annotation.data.href );
|
2012-06-11 07:36:20 +00:00
|
|
|
link.setAttribute( 'data-mw', annotation.data.mw );
|
|
|
|
if ( subType === 'wikiLink' || subType === 'extLink' ) {
|
|
|
|
link.setAttribute( 'rel', 'mw:' + subType );
|
|
|
|
}
|
2012-06-07 22:02:25 +00:00
|
|
|
return link;
|
|
|
|
}
|
2012-05-31 23:50:16 +00:00
|
|
|
},
|
2012-06-07 00:47:27 +00:00
|
|
|
'toDataAnnotation': function( tag, element ) {
|
2012-06-11 07:36:20 +00:00
|
|
|
return {
|
|
|
|
'type': 'link/' + ( element.getAttribute( 'rel' ).split( ':' )[1] || 'unknown' ),
|
|
|
|
'data': {
|
|
|
|
'href': element.getAttribute( 'href' ),
|
|
|
|
'mw': element.getAttribute( 'data-mw' )
|
|
|
|
}
|
|
|
|
};
|
2012-05-31 23:50:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.annotationFactory.register( 'link', ve.dm.LinkAnnotation );
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.LinkAnnotation, ve.dm.Annotation );
|