mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-13 18:37:07 +00:00
092cfd6075
Instead of doing a separate tree walk and finding all timestamps separately, make it part of the getComments tree walk, and find timestamps one at a time. Change-Id: I47f466eaf228504faa189fd99e07493bc7f022cd
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
var
|
|
parser = require( 'ext.discussionTools.init' ).parser,
|
|
highlighter = require( './highlighter.js' ),
|
|
comments = parser.getComments( document.getElementById( 'mw-content-text' ) ),
|
|
threads = parser.groupThreads( comments ),
|
|
timestampRegex = parser.getLocalTimestampRegexp();
|
|
|
|
highlighter.markThreads( threads );
|
|
|
|
// TODO: Use comment.signatureRanges to mark up signatures/timestamps
|
|
comments.forEach( function ( comment ) {
|
|
var signature, emptySignature, node, match;
|
|
|
|
if ( comment.type !== 'comment' ) {
|
|
return;
|
|
}
|
|
|
|
node = comment.range.endContainer;
|
|
match = parser.findTimestamp( node, timestampRegex );
|
|
signature = parser.findSignature( node )[ 0 ];
|
|
emptySignature = signature.length === 1 && signature[ 0 ] === node;
|
|
// Note that additional content may follow the timestamp (e.g. in some voting formats), but we
|
|
// don't care about it. The code below doesn't mark that due to now the text nodes are sliced,
|
|
// but we might need to take care to use the matched range of node in other cases.
|
|
highlighter.markTimestamp( node, match );
|
|
if ( !emptySignature ) {
|
|
highlighter.markSignature( signature );
|
|
}
|
|
} );
|