CommentController: Better handle clicking links while already commenting

Bug: T272389
Change-Id: If28a6cce250dca4810de3f51c0a2a4587d00649e
This commit is contained in:
Bartosz Dziewoński 2021-01-19 20:45:42 +01:00
parent 234198d9b1
commit 2798ee73f4

View file

@ -109,15 +109,33 @@ CommentController.prototype.onReplyLinkClick = function ( e ) {
// Only handle keypresses on the "Enter" or "Space" keys
return;
}
// TODO: Allow users to use multiple reply widgets simultaneously.
// Currently submitting a reply from one widget would also destroy the other ones.
// eslint-disable-next-line no-jquery/no-class-state
if ( this.$pageContainer.hasClass( 'dt-init-replylink-open' ) ) {
// Support: IE 11
// On other browsers, the link is made unclickable using 'pointer-events' in CSS
if ( e.type === 'click' && ( e.which !== OO.ui.MouseButtons.LEFT || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) ) {
// Only handle unmodified left clicks
return;
}
e.preventDefault();
// TODO: Allow users to use multiple reply widgets simultaneously.
// Currently submitting a reply from one widget would also destroy the other ones.
// If the reply widget is already open, activate it.
// Reply links are also made unclickable using 'pointer-events' in CSS, but that doesn't happen
// for new section links, because we don't have a good way of visually disabling them.
// (And it also doesn't work on IE 11.)
if ( this.opened ) {
// Show and focus the widget
this.replyWidget.scrollElementIntoView( { padding: scrollPadding } );
this.focus();
return;
}
// If another reply widget is open (or opening), do nothing.
// eslint-disable-next-line no-jquery/no-class-state
if ( this.$pageContainer.hasClass( 'dt-init-replylink-open' ) ) {
return;
}
this.setup();
};
@ -224,6 +242,7 @@ CommentController.prototype.setupReplyWidget = function ( replyWidget, data ) {
replyWidget.setup( data );
this.replyWidget = replyWidget;
this.opened = true;
};
/**
@ -250,6 +269,7 @@ CommentController.prototype.teardown = function ( abandoned ) {
}
modifier.removeAddedListItem( this.newListItem );
this.newListItem = null;
this.opened = false;
if ( abandoned ) {
this.$replyLink.trigger( 'focus' );
}