mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
cddb3f1b39
As jQuery hash problems in some cases converting HTML, it is easier just to store the original DOM elements. The bulk of this commit is fixing the tests as although we have an assertion for comparing DOM elements, we don't have one for comparing objects or arrays which may contain DOM elements. ve.js * copyObject & copyArray fixed to run cloneNode(true) on any item of type Node. * Added callback function so an object/array can be copied with modifications. ve.qunit.js * Added deepEqualWithDomElements: Using the new copyObect/Array callback, we can copy the incoming object and convert any nodes to node summaries, then just run the normal deep equal comparison. ve.dm.AlienNodes.js * Instead of storing HMTL we store cloned DOM elements which we can send straight back to the converter without any processing. ve.dm.example.js * Updated tests to expect DOM elements instead of HTML. ve.dm.Converter.test.js * Updated tests to use deepEqualWithDomElements Bug: 47737 Change-Id: I3df8f49b170c31da9610129d53cf8cb65dd5d5f8
97 lines
2.6 KiB
JavaScript
97 lines
2.6 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel AlienNode, AlienBlockNode and AlienInlineNode classes.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel alien node.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends ve.dm.GeneratedContentNode
|
|
* @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.AlienNode = function VeDmAlienNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.GeneratedContentNode.call( this, 0, element );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.AlienNode, ve.dm.GeneratedContentNode );
|
|
|
|
/* Static members */
|
|
|
|
ve.dm.AlienNode.static.name = 'alien';
|
|
|
|
ve.dm.AlienNode.static.storeHtmlAttributes = false;
|
|
|
|
// TODO: Develop better method to test for generated content
|
|
ve.dm.AlienNode.static.generatedContent = true;
|
|
|
|
ve.dm.AlienNode.static.toDataElement = function ( domElements, converter ) {
|
|
var isInline = this.isHybridInline( domElements, converter ),
|
|
type = isInline ? 'alienInline' : 'alienBlock';
|
|
|
|
return {
|
|
'type': type,
|
|
'attributes': {
|
|
'domElements': ve.copyArray( domElements )
|
|
}
|
|
};
|
|
};
|
|
|
|
ve.dm.AlienNode.static.toDomElements = function ( dataElement ) {
|
|
return dataElement.attributes.domElements;
|
|
};
|
|
|
|
/* Concrete subclasses */
|
|
|
|
/**
|
|
* DataModel alienBlock node.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.AlienNode
|
|
* @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.AlienBlockNode = function VeDmAlienBlockNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.AlienNode.call( this, length, element );
|
|
};
|
|
|
|
ve.inheritClass( ve.dm.AlienBlockNode, ve.dm.AlienNode );
|
|
|
|
ve.dm.AlienBlockNode.static.name = 'alienBlock';
|
|
|
|
/**
|
|
* DataModel alienInline node.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.AlienNode
|
|
* @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.AlienInlineNode = function VeDmAlienInlineNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.AlienNode.call( this, length, element );
|
|
};
|
|
|
|
ve.inheritClass( ve.dm.AlienInlineNode, ve.dm.AlienNode );
|
|
|
|
ve.dm.AlienInlineNode.static.name = 'alienInline';
|
|
|
|
ve.dm.AlienInlineNode.static.isContent = true;
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.AlienNode );
|
|
ve.dm.modelRegistry.register( ve.dm.AlienBlockNode );
|
|
ve.dm.modelRegistry.register( ve.dm.AlienInlineNode );
|