mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
22d1908bd4
The easy part is getting the correct numbers from the InternalList and generating the ordered list HTML. The tricky part is connecting up the events to make sure the renumberings/list generations are triggered when required. InternalList can emit an update event on document transaction, which triggers the renumbering/relisting if any references have been added or deleted during that transaction. ve.ce.MWReferenceListNode also listens to changes on the InternalListNode (i.e. changes to the contents of the references) and always triggers a rebuild. Change-Id: I1b48ef5240e433c3b314259aa68cde13841ea98b
56 lines
1.5 KiB
JavaScript
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 ) {
|
|
return dataElement.attributes.domElements;
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWReferenceListNode ); |