mediawiki-extensions-Visual.../modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js
Ed Sanders 5e6cbc187c Link pasting: Match RDFa-less links as external
Now that some targets support link pasting (Flow) we need to
make sure that pasted links match to an allowed type ('link/mwExternal')
instead of plain 'link' annotations which should never exist
in an MW document.

In a later commit we should auto-detect internal links.

Change-Id: I7faae834aa6e730c3cf93a691331a05fd0fe3d5c
2016-03-17 17:18:41 +00:00

79 lines
2 KiB
JavaScript

/*!
* VisualEditor DataModel MWNumberedExternalLinkNode class.
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MediaWiki numbered external link node.
*
* @class
* @extends ve.dm.LeafNode
* @mixins ve.dm.FocusableNode
*
* @constructor
* @param {Object} [element] Reference to element in linear model
*/
ve.dm.MWNumberedExternalLinkNode = function VeDmMWNumberedExternalLinkNode() {
// Parent constructor
ve.dm.LeafNode.apply( this, arguments );
// Mixin constructors
ve.dm.FocusableNode.call( this );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWNumberedExternalLinkNode, ve.dm.LeafNode );
OO.mixinClass( ve.dm.MWNumberedExternalLinkNode, ve.dm.FocusableNode );
/* Static Properties */
ve.dm.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
ve.dm.MWNumberedExternalLinkNode.static.isContent = true;
ve.dm.MWNumberedExternalLinkNode.static.matchTagNames = [ 'a' ];
ve.dm.MWNumberedExternalLinkNode.static.matchRdfaTypes = [ 'mw:ExtLink' ];
ve.dm.MWNumberedExternalLinkNode.static.blacklistedAnnotationTypes = [ 'link' ];
ve.dm.MWNumberedExternalLinkNode.static.matchFunction = function ( domElement ) {
// Must be empty
return domElement.childNodes.length === 0;
};
ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements ) {
return {
type: this.name,
attributes: {
href: domElements[ 0 ].getAttribute( 'href' )
}
};
};
ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc ) {
var domElement = doc.createElement( 'a' );
domElement.setAttribute( 'href', dataElement.attributes.href );
domElement.setAttribute( 'rel', 'mw:ExtLink' );
return [ domElement ];
};
/* Methods */
/**
* Convenience wrapper for .getHref() on the current element.
*
* @return {string} Link href
*/
ve.dm.MWNumberedExternalLinkNode.prototype.getHref = function () {
return this.element.attributes.href;
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWNumberedExternalLinkNode );