mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 22:16:15 +00:00
8a2c9431e6
Fixes (follows-up I1b48ef5240, I6daff5c596): * Invalid html passed to jQuery constructor. * Use prop() instead of attr() for boolean values. * Use append() instead of html() when appending nodes instead of parsing html. * Rename shadowed variable name clash 'mw' to 'mwData'. * Fix odd construction where we parse '{}' to create an empty object. * Have ve.ce.MWReferenceListNode#update perform changes off-document in a detached tree. * Fix deep property access that can fail. mwData is set to either JSON parse of data-mw attr or empty object. Accessing mwData.attrs.group needs to be guarded by whether mw.attrs is indeed set. * Have `mw` and `about` attribtue in references list roundtrip (especially mw which can data we aren't editing/re-creating). * Add missing 'refGroup' property to MWReferenceListNode's data element (similar to what MWReferenceNode already has). Change-Id: I67e4f378ccd04e97361d8e58ae57db5353075756
89 lines
2.3 KiB
JavaScript
89 lines
2.3 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 mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
|
refGroup = mwData.attrs && mwData.attrs.group || '',
|
|
listGroup = 'mwReference/' + refGroup;
|
|
|
|
return {
|
|
'type': this.name,
|
|
'attributes': {
|
|
'mw': mwData,
|
|
'about': domElements[0].getAttribute( 'about' ),
|
|
'domElements': ve.copyArray( domElements ),
|
|
'refGroup': refGroup,
|
|
'listGroup': listGroup
|
|
}
|
|
};
|
|
};
|
|
|
|
ve.dm.MWReferenceListNode.static.toDomElements = function ( dataElement, doc ) {
|
|
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;
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWReferenceListNode );
|