mediawiki-extensions-Visual.../modules/ve/dm/annotations/ve.dm.MWExternalLinkAnnotation.js
Catrope 613dd14332 New annotation API: convert existing annotations
This changes ve.dm.LinkAnnotation to be a generic annotation for <a>
tags, and adds ve.dm.MWInternalLinkAnnotation and
ve.dm.MWExternalLinkAnnotation as MW-specific subclasses. This nicely
splits out the MW-specific parts in LinkAnnotation, and ideally we'd
also move these files somewhere else to reflect their MW-specificity,
but I haven't gotten to that yet.

Similarly, ve.dm.TextStyleAnnotation is now a generic base class for
simple tag-only-no-metadata annotations, and it has 11 subclasses, one
for each tag we support. This is quite a bit more verbose than the
previous code, but I think it's cleaner and more flexible. I considered
writing a function that would generate a TextStyleAnnotation subclass,
then calling that 11 times, but that's not possible if we want to keep
named functions for the constructors.

Change-Id: Ifba10153eef40280e44025dd72d4e9d9f33b0632
2012-10-12 15:07:25 -07:00

29 lines
1.2 KiB
JavaScript

/**
* VisualEditor data model MWExternalLinkAnnotation class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Annotation representing an external link in MediaWiki, i.e. <a rel="mw:ExtLink">,
* <a rel="mw:ExtLink/Numbered"> and <a rel="mw:ExtLink/URL">. Those three are semantically
* slightly different, but they don't need to be treated differently by us, at least for now.
*/
ve.dm.MWExternalLinkAnnotation = function VeDmMWExternalLinkAnnotation( element ) {
ve.dm.LinkAnnotation.call( this, element );
};
ve.inheritClass( ve.dm.MWExternalLinkAnnotation, ve.dm.LinkAnnotation );
ve.dm.MWExternalLinkAnnotation.static.name = 'link/MWexternal';
ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = ['mw:ExtLink', 'mw:ExtLink/Numbered', 'mw:ExtLink/URL'];
ve.dm.MWExternalLinkAnnotation.prototype.toHTML = function () {
var parentResult = ve.dm.LinkAnnotation.prototype.toHTML.call( this );
parentResult.attributes.rel = parentResult.attributes.rel || 'mw:ExtLink';
return parentResult;
};
ve.dm.annotationFactory.register( 'link/MWexternal', ve.dm.MWExternalLinkAnnotation );