Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/annotations/ve.dm.DatetimeAnnotation.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel DatetimeAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel datetime annotation.
9 *
10 * Represents `<time>` tags.
11 *
12 * @class
13 * @extends ve.dm.TextStyleAnnotation
14 * @constructor
15 * @param {Object} element
16 */
17 ve.dm.DatetimeAnnotation = function VeDmDatetimeAnnotation() {
18 // Parent constructor
19 ve.dm.DatetimeAnnotation.super.apply( this, arguments );
20 };
21
22 /* Inheritance */
23
24 OO.inheritClass( ve.dm.DatetimeAnnotation, ve.dm.TextStyleAnnotation );
25
26 /* Static Properties */
27
28 ve.dm.DatetimeAnnotation.static.name = 'textStyle/datetime';
29
30 ve.dm.DatetimeAnnotation.static.matchTagNames = [ 'time' ];
31
32 ve.dm.DatetimeAnnotation.static.toDataElement = function ( domElements ) {
33 // Parent method
34 const dataElement = ve.dm.DatetimeAnnotation.super.static.toDataElement.apply( this, arguments );
35 dataElement.attributes.datetime = domElements[ 0 ].getAttribute( 'datetime' );
36 return dataElement;
37 };
38
39 ve.dm.DatetimeAnnotation.static.toDomElements = function ( dataElement, doc ) {
40 const domElement = doc.createElement( 'time' );
41 if ( dataElement.attributes.datetime ) {
42 // If it's null, don't bother creating a blank attribute; <time> alone is valid
43 domElement.setAttribute( 'datetime', dataElement.attributes.datetime );
44 }
45 return [ domElement ];
46 };
47
48 /* Methods */
49
50 /**
51 * @inheritdoc
52 */
53 ve.dm.DatetimeAnnotation.prototype.getComparableObject = function () {
54 return {
55 type: this.getType(),
56 datetime: this.getAttribute( 'datetime' )
57 };
58 };
59
60 /* Registration */
61
62 ve.dm.modelRegistry.register( ve.dm.DatetimeAnnotation );