mirror of
https://github.com/moparisthebest/mail
synced 2025-02-13 05:30:21 -05:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
app.view.ReadView = Backbone.View.extend({
|
|
|
|
initialize: function(args) {
|
|
this.template = _.template(app.util.tpl.get('read'));
|
|
this.model = args.dao.getItem(args.folder, args.messageId);
|
|
},
|
|
|
|
render: function(eventName) {
|
|
var params = this.model.toJSON();
|
|
params.account = this.options.dao.account.get('emailAddress');
|
|
params.folder = this.options.folder;
|
|
params.id = encodeURIComponent(params.id);
|
|
|
|
$(this.el).html(this.template(params));
|
|
this.renderBody();
|
|
|
|
return this;
|
|
},
|
|
|
|
renderBody: function(tryHtml) {
|
|
var page = $(this.el),
|
|
emailBody = this.model.get('body');
|
|
|
|
if (!tryHtml && emailBody.indexOf('</') === -1) {
|
|
// render text email
|
|
page.find('#bodyItem').html('<textarea></textarea>');
|
|
page.find('#bodyItem textarea').text(emailBody);
|
|
|
|
} else if (tryHtml && emailBody.indexOf('</') !== -1) {
|
|
// render html email inside a sandboxed iframe
|
|
var iframe = page.find('#idMailContent'),
|
|
iframeDoc = iframe[0].contentDocument || iframe[0].contentWindow.document;
|
|
|
|
iframe.load(function() {
|
|
// resize
|
|
var newheight = iframeDoc.body.scrollHeight;
|
|
var newwidth = iframeDoc.body.scrollWidth;
|
|
iframe[0].height = (newheight) + 'px';
|
|
iframe[0].width = (newwidth) + 'px';
|
|
});
|
|
|
|
iframeDoc.write(emailBody);
|
|
iframeDoc.close();
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}()); |