2017-03-11 02:30:44 -05:00
|
|
|
const MAX_MESSAGE_LENGTH = 500;
|
|
|
|
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
class AbuseReports {
|
|
|
|
constructor() {
|
|
|
|
$(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
|
|
|
|
$(document)
|
|
|
|
.off('click', MESSAGE_CELL_SELECTOR)
|
|
|
|
.on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation);
|
|
|
|
}
|
2016-08-08 09:04:18 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
truncateLongMessage() {
|
|
|
|
const $messageCellElement = $(this);
|
|
|
|
const reportMessage = $messageCellElement.text();
|
|
|
|
if (reportMessage.length > MAX_MESSAGE_LENGTH) {
|
|
|
|
$messageCellElement.data('original-message', reportMessage);
|
|
|
|
$messageCellElement.data('message-truncated', 'true');
|
2017-03-13 15:08:49 -04:00
|
|
|
$messageCellElement.text(window.gl.text.truncate(reportMessage, MAX_MESSAGE_LENGTH));
|
2016-08-08 09:04:18 -04:00
|
|
|
}
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
2016-08-08 09:04:18 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
toggleMessageTruncation() {
|
|
|
|
const $messageCellElement = $(this);
|
|
|
|
const originalMessage = $messageCellElement.data('original-message');
|
|
|
|
if (!originalMessage) return;
|
|
|
|
if ($messageCellElement.data('message-truncated') === 'true') {
|
|
|
|
$messageCellElement.data('message-truncated', 'false');
|
|
|
|
$messageCellElement.text(originalMessage);
|
|
|
|
} else {
|
|
|
|
$messageCellElement.data('message-truncated', 'true');
|
|
|
|
$messageCellElement.text(`${originalMessage.substr(0, (MAX_MESSAGE_LENGTH - 3))}...`);
|
2016-08-08 09:04:18 -04:00
|
|
|
}
|
|
|
|
}
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
2016-08-08 09:04:18 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
window.gl.AbuseReports = AbuseReports;
|