All files / src/dm/annotations ve.dm.DatetimeAnnotation.js

100% Statements 17/17
100% Branches 2/2
100% Functions 4/4
100% Lines 17/17

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                                1x   6x         1x       1x   1x   1x   2x 2x 2x     1x 6x 6x   3x   6x               1x 6x               1x  
/*!
 * VisualEditor DataModel DatetimeAnnotation class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * DataModel datetime annotation.
 *
 * Represents `<time>` tags.
 *
 * @class
 * @extends ve.dm.TextStyleAnnotation
 * @constructor
 * @param {Object} element
 */
ve.dm.DatetimeAnnotation = function VeDmDatetimeAnnotation() {
	// Parent constructor
	ve.dm.DatetimeAnnotation.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.DatetimeAnnotation, ve.dm.TextStyleAnnotation );
 
/* Static Properties */
 
ve.dm.DatetimeAnnotation.static.name = 'textStyle/datetime';
 
ve.dm.DatetimeAnnotation.static.matchTagNames = [ 'time' ];
 
ve.dm.DatetimeAnnotation.static.toDataElement = function ( domElements ) {
	// Parent method
	var dataElement = ve.dm.DatetimeAnnotation.super.static.toDataElement.apply( this, arguments );
	dataElement.attributes.datetime = domElements[ 0 ].getAttribute( 'datetime' );
	return dataElement;
};
 
ve.dm.DatetimeAnnotation.static.toDomElements = function ( dataElement, doc ) {
	var domElement = doc.createElement( 'time' );
	if ( dataElement.attributes.datetime ) {
		// If it's null, don't bother creating a blank attribute; <time> alone is valid
		domElement.setAttribute( 'datetime', dataElement.attributes.datetime );
	}
	return [ domElement ];
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.dm.DatetimeAnnotation.prototype.getComparableObject = function () {
	return {
		type: this.getType(),
		datetime: this.getAttribute( 'datetime' )
	};
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.DatetimeAnnotation );