decoration of the message body in iframe's load event handler

This commit is contained in:
Jakub Pavlík jn 2013-07-28 22:57:36 +02:00
parent ffb4ec4e4c
commit 2f5c2ff01c
2 changed files with 29 additions and 28 deletions

View File

@ -23,6 +23,9 @@ class MailCatcher
e.preventDefault()
@loadMessageAnalysis @selectedMessage()
$('#message iframe').load =>
@decorateMessageBody()
$('#resizer').live
mousedown: (e) ->
e.preventDefault()
@ -253,16 +256,15 @@ class MailCatcher
$('#message iframe').attr "src", "/messages/#{id}.#{format}"
app = this
$('#message iframe').load ( -> app.decorateMessageBody format )
decorateMessageBody: (format) ->
if format == 'html'
setTimeout ( ->
decorateMessageBody: ->
format = $('#message .views .tab.format.selected').attr 'data-message-format'
switch format
when 'html'
body = $('#message iframe').contents().find('body')
$("a", body).attr("target", "_blank")
), 10
else if format == 'plain'
when 'plain'
message_iframe = $('#message iframe').contents()
text = message_iframe.text()
text = text.replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)/g, '<a href="$1" target="_blank">$1</a>')

View File

@ -36,6 +36,9 @@
e.preventDefault();
return _this.loadMessageAnalysis(_this.selectedMessage());
});
$('#message iframe').load(function() {
return _this.decorateMessageBody();
});
$('#resizer').live({
mousedown: function(e) {
var events;
@ -331,22 +334,18 @@
$("#message .views .tab:not([data-message-format=\"" + format + "\"]).selected").removeClass('selected');
if (id != null) {
$('#message iframe').attr("src", "/messages/" + id + "." + format);
app = this;
return $('#message iframe').load((function() {
return app.decorateMessageBody(format);
}));
return app = this;
}
};
MailCatcher.prototype.decorateMessageBody = function(format) {
var message_iframe, text;
if (format === 'html') {
return setTimeout((function() {
var body;
MailCatcher.prototype.decorateMessageBody = function() {
var body, format, message_iframe, text;
format = $('#message .views .tab.format.selected').attr('data-message-format');
switch (format) {
case 'html':
body = $('#message iframe').contents().find('body');
return $("a", body).attr("target", "_blank");
}), 10);
} else if (format === 'plain') {
case 'plain':
message_iframe = $('#message iframe').contents();
text = message_iframe.text();
text = text.replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)/g, '<a href="$1" target="_blank">$1</a>');