Allow line breaks in messages. Closes issue #291

Line breaks can now be insterted into message box using Shift+Enter or Alt+Enter. Messages with new lines are properly displayed in the conversation view (but only there, to keep inbox clean). The template was modified to allow HTML, but the message itself is sanitized before new line handling is run.
This commit is contained in:
adambar 2015-07-02 23:00:50 +02:00
parent 52857f09ea
commit 86f7b7adf5
3 changed files with 8 additions and 3 deletions

View file

@ -55,11 +55,16 @@
autoLink: function(text) {
return text.replace(/(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi, "$1<a href='$2' target='_blank'>$2</a>");
},
sanitizeMessage: function (message) {
var element = document.createElement('span');
element.innerText = message;
return element.innerHTML.trim().replace(/\n/g, '<br>');
},
render: function() {
var contact = this.model.getContact();
this.$el.html(
Mustache.render(this.template, {
message: this.model.get('body'),
message: this.sanitizeMessage(this.model.get('body')),
timestamp: moment(this.model.get('sent_at')).fromNow(),
sender: (contact && contact.getTitle()) || '',
avatar: (contact && contact.getAvatar())