user status: Add "clear message (x)" button for status message input.

This adds the same "x" button as we have in "stream search" or "people
search" to the user status modal.

The button is shown if someone types something, or if the status
message was already set (meaning there was already a value in the
input field). If the input field is empty, the button is not visible.

This fixes the follow-up comments from #12179.
This commit is contained in:
Alexandra Ciobica
2019-04-28 22:32:38 +02:00
committed by Tim Abbott
parent 61758735f3
commit 8aa982f7ba
4 changed files with 31 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ exports.open_overlay = function () {
field.val(old_status_text);
field.select();
field.focus();
exports.toggle_clear_message_button();
var button = exports.submit_button();
button.attr('disabled', true);
@@ -66,6 +67,20 @@ exports.update_button = function () {
}
};
exports.toggle_clear_message_button = function () {
if (exports.input_field().val() !== '') {
$('#clear_status_message_button').prop('disabled', false);
} else {
$('#clear_status_message_button').prop('disabled', true);
}
};
exports.clear_message = function () {
var field = exports.input_field();
field.val('');
$('#clear_status_message_button').prop('disabled', true);
};
exports.initialize = function () {
$('body').on('click', '.user_status_overlay .set_user_status', function () {
exports.submit_new_status();
@@ -73,6 +88,12 @@ exports.initialize = function () {
$('body').on('keyup', '.user_status_overlay input.user_status', function () {
exports.update_button();
exports.toggle_clear_message_button();
});
$('#clear_status_message_button').on('click', function () {
exports.clear_message();
exports.update_button();
});
};