2019-10-10 20:17:24 +00:00
|
|
|
var comments, threads,
|
|
|
|
widgetPromise = mw.loader.using( 'oojs-ui-core' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.discussionTools
|
|
|
|
* @singleton
|
|
|
|
*/
|
|
|
|
mw.dt = {
|
|
|
|
init: {},
|
|
|
|
ui: {},
|
2019-11-05 14:13:18 +00:00
|
|
|
parser: require( 'ext.discussionTools.parser' ),
|
|
|
|
modifier: require( 'ext.discussionTools.modifier' )
|
2019-10-10 20:17:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function setupComment( comment ) {
|
|
|
|
var $tsNode = $( comment.range.endContainer );
|
|
|
|
|
|
|
|
// Is it possible to have a heading nested in a thread?
|
|
|
|
if ( comment.type !== 'comment' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tsNode.after(
|
|
|
|
' ',
|
|
|
|
$( '<a>' ).text( 'Reply' ).on( 'click', function () {
|
2019-11-05 14:13:18 +00:00
|
|
|
var newList, newListItem,
|
2019-10-10 20:17:24 +00:00
|
|
|
$link = $( this );
|
|
|
|
|
|
|
|
$link.hide();
|
|
|
|
|
2019-11-05 14:13:18 +00:00
|
|
|
newList = mw.dt.modifier.addListAtComment( comment );
|
|
|
|
newListItem = mw.dt.modifier.addListItem( newList );
|
|
|
|
$( newListItem ).text( 'Loading...' );
|
2019-10-10 20:17:24 +00:00
|
|
|
|
|
|
|
widgetPromise.then( function () {
|
|
|
|
var replyWidget = new OO.ui.MultilineTextInputWidget( {
|
|
|
|
value: 'Reply to ' + comment.author
|
|
|
|
} );
|
2019-11-05 14:13:18 +00:00
|
|
|
$( newListItem ).empty().append( replyWidget.$element );
|
2019-10-10 20:17:24 +00:00
|
|
|
replyWidget.focus();
|
|
|
|
} );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function traverseNode( parent ) {
|
|
|
|
parent.replies.forEach( function ( comment ) {
|
|
|
|
setupComment( comment );
|
|
|
|
traverseNode( comment );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-10-24 14:38:31 +00:00
|
|
|
if ( new mw.Uri().query.dtdebug ) {
|
|
|
|
mw.loader.load( 'ext.discussionTools.debug' );
|
|
|
|
} else {
|
|
|
|
comments = mw.dt.parser.getComments( document.getElementById( 'mw-content-text' ) );
|
|
|
|
threads = mw.dt.parser.groupThreads( comments );
|
|
|
|
threads.forEach( traverseNode );
|
|
|
|
}
|