All files / src/dm/nodes ve.dm.AlienNode.js

97.56% Statements 40/41
85.71% Branches 12/14
100% Functions 8/8
97.56% Lines 40/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122                                  1x   104x     104x         1x   1x       1x   1x   1x   1x   1x 77x     1x     96x 2x 94x 8x   8x 8x 8x 4x     86x 86x 86x     96x     1x 119x           1x 5x 4x       1x               8x 4x         4x 4x   4x 4x   4x                 1x 2x                   1x  
/*!
 * VisualEditor DataModel AlienNode class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * DataModel alien node.
 *
 * @class
 * @abstract
 * @extends ve.dm.LeafNode
 * @mixes ve.dm.FocusableNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 */
ve.dm.AlienNode = function VeDmAlienNode() {
	// Parent constructor
	ve.dm.AlienNode.super.apply( this, arguments );
 
	// Mixin constructor
	ve.dm.FocusableNode.call( this );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.AlienNode, ve.dm.LeafNode );
 
OO.mixinClass( ve.dm.AlienNode, ve.dm.FocusableNode );
 
/* Static members */
 
ve.dm.AlienNode.static.name = 'alien';
 
ve.dm.AlienNode.static.preserveHtmlAttributes = false;
 
ve.dm.AlienNode.static.enableAboutGrouping = true;
 
ve.dm.AlienNode.static.matchRdfaTypes = [ 've:Alien' ];
 
ve.dm.AlienNode.static.matchFunction = function () {
	return true;
};
 
ve.dm.AlienNode.static.toDataElement = function ( domElements, converter ) {
	let element;
 
	if ( this.name !== 'alien' ) {
		element = { type: this.name };
	} else if ( ve.dm.TableCellableNode.static.areNodesCellable( domElements ) ) {
		element = { type: 'alienTableCell' };
 
		const attributes = {};
		ve.dm.TableCellableNode.static.setAttributes( attributes, domElements, true );
		if ( !ve.isEmptyObject( attributes ) ) {
			element.attributes = attributes;
		}
	} else {
		const isInline = this.isHybridInline( domElements, converter );
		const type = isInline ? 'alienInline' : 'alienBlock';
		element = { type: type };
	}
 
	return element;
};
 
ve.dm.AlienNode.static.toDomElements = function ( dataElement, doc, converter ) {
	return ve.copyDomElements( converter.getStore().value( dataElement.originalDomElementsHash ) || [], doc );
};
 
/**
 * @inheritdoc
 */
ve.dm.AlienNode.static.isDiffComparable = function ( element, other, elementStore, otherStore ) {
	if ( element.type === other.type ) {
		Iif ( element.originalDomElementsHash === other.originalDomElementsHash ) {
			return true;
		}
	} else {
		return false;
	}
 
	// HACK: We can't strip 'about' attributes before converting, as we need them
	// for about grouping, but we should ignore them for diffing as they can be
	// non-persistent in historical diffs.
 
	function removeAboutAttributes( el ) {
		Array.prototype.forEach.call( el.querySelectorAll( '[about]' ), ( e ) => {
			e.removeAttribute( 'about' );
		} );
	}
 
	// Deep copy DOM nodes from store
	const elementOriginalDomElements = ve.copy( elementStore.value( element.originalDomElementsHash ) );
	const otherOriginalDomElements = ve.copy( otherStore.value( other.originalDomElementsHash ) );
	// Remove about attributes
	elementOriginalDomElements.forEach( removeAboutAttributes );
	otherOriginalDomElements.forEach( removeAboutAttributes );
	// Compare DOM trees
	return ve.compare(
		ve.copy( elementOriginalDomElements, ve.convertDomElements ),
		ve.copy( otherOriginalDomElements, ve.convertDomElements )
	);
};
 
/**
 * @inheritdoc
 */
ve.dm.AlienNode.static.getHashObject = function ( dataElement ) {
	return {
		type: dataElement.type,
		// Some comparison methods ignore the originalDomElementsHash
		// property. Rename it so it doesn't get ignored for alien nodes.
		alienDomElementsHash: dataElement.originalDomElementsHash
	};
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.AlienNode );