2013-04-17 17:53:26 +00:00
|
|
|
/*!
|
|
|
|
* 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 */
|
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.dm.MWReferenceListNode.static.name = 'mwReferenceList';
|
2013-04-17 17:53:26 +00:00
|
|
|
|
|
|
|
ve.dm.MWReferenceListNode.static.matchTagNames = null;
|
|
|
|
|
2013-06-03 20:22:35 +00:00
|
|
|
ve.dm.MWReferenceListNode.static.matchRdfaTypes = [ 'mw:Extension/references' ];
|
2013-04-17 17:53:26 +00:00
|
|
|
|
2013-05-08 04:22:22 +00:00
|
|
|
ve.dm.MWReferenceListNode.static.storeHtmlAttributes = false;
|
2013-04-17 17:53:26 +00:00
|
|
|
|
2013-05-08 04:22:22 +00:00
|
|
|
ve.dm.MWReferenceListNode.static.toDataElement = function ( domElements ) {
|
2013-06-21 02:55:16 +00:00
|
|
|
var mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
|
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
|
|
|
refGroup = mwData.attrs && mwData.attrs.group || '',
|
2013-06-03 20:22:35 +00:00
|
|
|
listGroup = 'mwReference/' + refGroup;
|
|
|
|
|
2013-04-17 17:53:26 +00:00
|
|
|
return {
|
|
|
|
'type': this.name,
|
|
|
|
'attributes': {
|
2013-06-21 02:55:16 +00:00
|
|
|
'mw': mwData,
|
|
|
|
'about': domElements[0].getAttribute( 'about' ),
|
2013-06-03 20:22:35 +00:00
|
|
|
'domElements': ve.copyArray( domElements ),
|
2013-06-21 02:55:16 +00:00
|
|
|
'refGroup': refGroup,
|
2013-06-03 20:22:35 +00:00
|
|
|
'listGroup': listGroup
|
2013-04-17 17:53:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-18 18:51:39 +00:00
|
|
|
ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement, doc ) {
|
2013-06-21 02:55:16 +00:00
|
|
|
var el, els, mwData,
|
|
|
|
attribs = dataElement.attributes;
|
|
|
|
|
|
|
|
if ( attribs.domElements ) {
|
|
|
|
// If there's more than 1 element, preserve entire array, not just first element
|
|
|
|
els = ve.copyDomElements( attribs.domElements, doc );
|
|
|
|
el = els[0];
|
|
|
|
} else {
|
|
|
|
el = doc.createElement( 'div' );
|
|
|
|
els = [ el ];
|
|
|
|
}
|
|
|
|
|
|
|
|
mwData = attribs.mw ? ve.copyObject( attribs.mw ) : {};
|
|
|
|
|
|
|
|
mwData.name = 'references';
|
|
|
|
|
|
|
|
if ( attribs.refGroup ) {
|
|
|
|
ve.setProp( mwData, 'attrs', 'group', attribs.refGroup );
|
|
|
|
} else if ( mwData.attrs ) {
|
|
|
|
delete mwData.attrs.refGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( attribs.about ) {
|
|
|
|
el.setAttribute( 'about', attribs.about );
|
|
|
|
}
|
|
|
|
el.setAttribute( 'typeof', 'mw:Extension/references' );
|
|
|
|
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
|
|
|
|
|
|
|
|
return els;
|
2013-04-17 17:53:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2013-06-21 02:55:16 +00:00
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWReferenceListNode );
|