mediawiki-extensions-Visual.../modules/ve/dm/nodes/ve.dm.MWReferenceListNode.js
Roan Kattouw dc798befcf Copy DOM elements properly, into the correct document
* Provide a utility for copying an array of DOM elements into a
  different document
* Copy the DOM elements returned in toDomElements(), otherwise weird
  issues arise when the same data is converted to DOM twice

Change-Id: Ie927420624f0d4af0692e18d1bc6f952c8013d61
2013-06-18 15:40:33 -07:00

56 lines
1.5 KiB
JavaScript

/*!
* VisualEditor DataModel MWReferenceListNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MediaWiki reference list node.
*
* @class
* @extends ve.dm.LeafNode
* @constructor
* @param {number} [length] Length of content data in document; ignored and overridden to 0
* @param {Object} [element] Reference to element in linear model
*/
ve.dm.MWReferenceListNode = function VeDmMWReferenceListNode( length, element ) {
// Parent constructor
ve.dm.LeafNode.call( this, 0, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.MWReferenceListNode, ve.dm.LeafNode );
/* Static members */
ve.dm.MWReferenceListNode.static.name = 'mwReferenceList';
ve.dm.MWReferenceListNode.static.matchTagNames = null;
ve.dm.MWReferenceListNode.static.matchRdfaTypes = [ 'mw:Extension/references' ];
ve.dm.MWReferenceListNode.static.storeHtmlAttributes = false;
ve.dm.MWReferenceListNode.static.toDataElement = function ( domElements ) {
var mw = JSON.parse( domElements[0].getAttribute( 'data-mw' ) || '{}' ),
refGroup = mw.attrs.group || '',
listGroup = 'mwReference/' + refGroup;
return {
'type': this.name,
'attributes': {
'domElements': ve.copyArray( domElements ),
'listGroup': listGroup
}
};
};
ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement, doc ) {
return ve.copyDomElements( dataElement.attributes.domElements, doc );
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWReferenceListNode );