mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-22 07:18:53 -05:00
scroll to selected message row
This commit is contained in:
parent
a161dedf0a
commit
cb3974f1b2
@ -161,13 +161,24 @@ class MailCatcher
|
||||
.append($('<td/>').text(message.subject or "No subject").toggleClass("blank", !message.subject))
|
||||
.append($('<td/>').text @formatDate message.created_at)
|
||||
|
||||
scrollToRow: (row) ->
|
||||
relativePosition = row.offset().top - $('#messages').offset().top
|
||||
if relativePosition < 0
|
||||
$('#messages').scrollTop($('#messages').scrollTop() + relativePosition - 20)
|
||||
else
|
||||
overflow = relativePosition + row.height() - $('#messages').height()
|
||||
if overflow > 0
|
||||
$('#messages').scrollTop($('#messages').scrollTop() + overflow + 20)
|
||||
|
||||
loadMessage: (id) ->
|
||||
id = id.id if id?.id?
|
||||
id ||= $('#messages tr.selected').attr 'data-message-id'
|
||||
|
||||
if id?
|
||||
$('#messages tbody tr:not([data-message-id="'+id+'"])').removeClass 'selected'
|
||||
$('#messages tbody tr[data-message-id="'+id+'"]').addClass 'selected'
|
||||
messageRow = $('#messages tbody tr[data-message-id="'+id+'"]')
|
||||
messageRow.addClass 'selected'
|
||||
@scrollToRow(messageRow)
|
||||
|
||||
$.getJSON '/messages/' + id + '.json', (message) =>
|
||||
$('#message .metadata dd.created_at').text @formatDate message.created_at
|
||||
|
@ -218,13 +218,29 @@
|
||||
return $('#messages tbody').append($('<tr />').attr('data-message-id', message.id.toString()).append($('<td/>').text(message.sender || "No sender").toggleClass("blank", !message.sender)).append($('<td/>').text((message.recipients || []).join(', ') || "No receipients").toggleClass("blank", !message.recipients.length)).append($('<td/>').text(message.subject || "No subject").toggleClass("blank", !message.subject)).append($('<td/>').text(this.formatDate(message.created_at))));
|
||||
};
|
||||
|
||||
MailCatcher.prototype.scrollToRow = function(row) {
|
||||
var overflow, relativePosition;
|
||||
relativePosition = row.offset().top - $('#messages').offset().top;
|
||||
if (relativePosition < 0) {
|
||||
return $('#messages').scrollTop($('#messages').scrollTop() + relativePosition - 20);
|
||||
} else {
|
||||
overflow = relativePosition + row.height() - $('#messages').height();
|
||||
if (overflow > 0) {
|
||||
return $('#messages').scrollTop($('#messages').scrollTop() + overflow + 20);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MailCatcher.prototype.loadMessage = function(id) {
|
||||
var _this = this;
|
||||
var messageRow,
|
||||
_this = this;
|
||||
if ((id != null ? id.id : void 0) != null) id = id.id;
|
||||
id || (id = $('#messages tr.selected').attr('data-message-id'));
|
||||
if (id != null) {
|
||||
$('#messages tbody tr:not([data-message-id="' + id + '"])').removeClass('selected');
|
||||
$('#messages tbody tr[data-message-id="' + id + '"]').addClass('selected');
|
||||
messageRow = $('#messages tbody tr[data-message-id="' + id + '"]');
|
||||
messageRow.addClass('selected');
|
||||
this.scrollToRow(messageRow);
|
||||
return $.getJSON('/messages/' + id + '.json', function(message) {
|
||||
var $ul;
|
||||
$('#message .metadata dd.created_at').text(_this.formatDate(message.created_at));
|
||||
|
Loading…
Reference in New Issue
Block a user