mediawiki-extensions-Visual.../modules/ve-mw/ce/nodes/ve.ce.MWNumberedExternalLinkNode.js
Roan Kattouw d3c706ff93 Add a node type for numbered external links
Since I0f0a826c in Parsoid, numbered external links are now empty
<a rel="mw:ExtLink"></a> tags. This means we have to put in a node type
for them to prevent them from being considered empty annotations and
getting converted to alienMeta.

MWNumberedExternalLinkNode is protected and focusable to avoid making
the link text (which isn't editable) clickable. It isn't inspectable
yet, we need to work on that.

Bug: 53505
Change-Id: I83f69695f3974089e51a84e799f31ab6ed879e05
2013-10-18 22:31:45 +02:00

70 lines
1.8 KiB
JavaScript

/*!
* VisualEditor ContentEditable MWNumberedExternalLinkNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MediaWiki numbered external link node.
*
* @class
* @extends ve.ce.LeafNode
* @constructor
* @param {ve.dm.MWNumberedExternalLinkNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWNumberedExternalLinkNode = function VeCeMWNumberedExternalLinkNode( model, config ) {
// Parent constructor
ve.ce.LeafNode.call( this, model, config );
// Mixin constructors
ve.ce.ProtectedNode.call( this );
ve.ce.FocusableNode.call( this );
// DOM changes
this.$.addClass( 've-ce-mwNumberedExternalLinkNode' );
// Need CE=false to prevent selection issues
this.$.prop( 'contentEditable', 'false' );
// Add link
this.$link = this.$$( '<a>' ).appendTo( this.$ );
// Events
this.model.connect( this, { 'update': 'onUpdate' } );
// Initialization
this.onUpdate();
};
/* Inheritance */
OO.inheritClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.LeafNode );
OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.ProtectedNode );
OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.FocusableNode );
/* Static Properties */
ve.ce.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
ve.ce.MWNumberedExternalLinkNode.static.tagName = 'span';
/* Methods */
/**
* Handle model update events.
*
* If the source changed since last update the image's src attribute will be updated accordingly.
*
* @method
*/
ve.ce.MWNumberedExternalLinkNode.prototype.onUpdate = function () {
this.$link.attr( 'href', this.model.getAttribute( 'href' ) );
};
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWNumberedExternalLinkNode );