| 1 |
const ThreadItem = require( './ThreadItem.js' ), |
| 2 |
moment = require( './lib/moment-timezone/moment-timezone-with-data-1970-2030.js' ); |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
function CommentItem( level, range, signatureRanges, timestampRanges, timestamp, author, displayName ) { |
| 22 |
|
| 23 |
CommentItem.super.call( this, 'comment', level, range ); |
| 24 |
|
| 25 |
this.signatureRanges = signatureRanges || []; |
| 26 |
this.timestampRanges = timestampRanges || []; |
| 27 |
this.timestamp = timestamp || null; |
| 28 |
this.author = author || null; |
| 29 |
this.displayName = displayName || null; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
this.parent = null; |
| 35 |
} |
| 36 |
|
| 37 |
OO.inheritClass( CommentItem, ThreadItem ); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
CommentItem.prototype.getTimestampString = function () { |
| 54 |
const dtConfig = require( './config.json' ); |
| 55 |
const switchTime = moment.utc( dtConfig.switchTime ); |
| 56 |
if ( this.timestamp < switchTime ) { |
| 57 |
return this.timestamp.utc().toISOString(); |
| 58 |
} else { |
| 59 |
|
| 60 |
return this.timestamp.utc().locale( 'en' ).format( 'YYYYMMDDHHmmss' ); |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
CommentItem.prototype.getBodyRange = function () { |
| 68 |
if ( !this.signatureRanges.length ) { |
| 69 |
return this.getRange(); |
| 70 |
} |
| 71 |
|
| 72 |
const lastSignature = this.signatureRanges[ this.signatureRanges.length - 1 ]; |
| 73 |
const doc = this.range.startContainer.ownerDocument; |
| 74 |
const nativeRange = doc.createRange(); |
| 75 |
nativeRange.setStart( this.range.startContainer, this.range.startOffset ); |
| 76 |
|
| 77 |
nativeRange.setEnd( lastSignature.startContainer, lastSignature.startOffset - 1 ); |
| 78 |
return nativeRange; |
| 79 |
}; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
CommentItem.prototype.getHeading = function () { |
| 85 |
let parent = this; |
| 86 |
while ( parent && parent.type !== 'heading' ) { |
| 87 |
parent = parent.parent; |
| 88 |
} |
| 89 |
return parent; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
CommentItem.prototype.getSubscribableHeading = function () { |
| 96 |
let heading = this.getHeading(); |
| 97 |
while ( heading && heading.type === 'heading' && !heading.isSubscribable() ) { |
| 98 |
heading = heading.parent; |
| 99 |
} |
| 100 |
return ( heading && heading.type === 'heading' ) ? heading : null; |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
module.exports = CommentItem; |