mediawiki-extensions-Discus.../modules/dt-ve/dt.dm.PingNode.js
Ed Sanders e6f7a9e679 Create a PingNode so user pings are single focusable nodes
Bug: T252083
Change-Id: I168e036d201b924e7fc9bda2f2f58e48ad2dbac0
2020-07-17 23:17:41 +01:00

68 lines
1.7 KiB
JavaScript

/*!
* VisualEditor DataModel MWPingNode class.
*
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MediaWiki ping node. A ping is just a link to a user page, but
* by defining it as a node we can make is a single FocusableNode.
*
* @class
* @extends ve.dm.LeafNode
* @mixins ve.dm.FocusableNode
*
* @constructor
* @param {Object} [element] Reference to element in linear model
*/
function DmMWPingNode() {
// Parent constructor
DmMWPingNode.super.apply( this, arguments );
// Mixin constructor
ve.dm.FocusableNode.call( this );
}
/* Inheritance */
OO.inheritClass( DmMWPingNode, ve.dm.LeafNode );
OO.mixinClass( DmMWPingNode, ve.dm.FocusableNode );
/* Static members */
DmMWPingNode.static.name = 'mwPing';
DmMWPingNode.static.isContent = true;
DmMWPingNode.static.matchTagNames = null;
DmMWPingNode.static.matchRdfaTypes = [];
DmMWPingNode.static.matchFunction = function () {
return false;
};
DmMWPingNode.static.disallowedAnnotationTypes = [ 'link' ];
DmMWPingNode.static.toDomElements = function ( dataElement, doc, converter ) {
var domElements,
title = mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).user, dataElement.attributes.user );
dataElement = ve.dm.MWInternalLinkAnnotation.static.dataElementFromTitle( title );
domElements = ve.dm.MWInternalLinkAnnotation.static.toDomElements( dataElement, doc, converter );
domElements[ 0 ].appendChild(
doc.createTextNode( title.getMainText() )
);
return domElements;
};
// toDataElement should never be called for this node
DmMWPingNode.static.toDataElement = null;
/* Registration */
ve.dm.modelRegistry.register( DmMWPingNode );