|
|
|
@ -14,28 +14,30 @@ Template.messages.helpers({ |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Template.messages.events({ |
|
|
|
|
'keyup .input-message': function(event) { |
|
|
|
|
// Inital height is 28. If the scrollHeight is greater than that( we have more text than area ),
|
|
|
|
|
// increase the size of the textarea. The max-height is set at 200
|
|
|
|
|
// even if the scrollHeight become bigger than that it should never exceed that.
|
|
|
|
|
// Account for no text in the textarea when increasing the height.
|
|
|
|
|
// If there is no text, reset the height.
|
|
|
|
|
var inputScrollHeight; |
|
|
|
|
Template.instance().chatMessages.keyup(visitor.getRoom(), event, Template.instance()); |
|
|
|
|
inputScrollHeight = $(event.currentTarget).prop('scrollHeight'); |
|
|
|
|
if (inputScrollHeight > 28) { |
|
|
|
|
return $(event.currentTarget).height($(event.currentTarget).val() === '' ? '15px' : (inputScrollHeight >= 200 ? inputScrollHeight - 50 : inputScrollHeight - 20)); |
|
|
|
|
} |
|
|
|
|
'keyup .input-message': function(event, instance) { |
|
|
|
|
instance.chatMessages.keyup(visitor.getRoom(), event, instance); |
|
|
|
|
instance.updateMessageInputHeight(event.currentTarget); |
|
|
|
|
}, |
|
|
|
|
'keydown .input-message': function(event) { |
|
|
|
|
return Template.instance().chatMessages.keydown(visitor.getRoom(), event, Template.instance()); |
|
|
|
|
'keydown .input-message': function(event, instance) { |
|
|
|
|
$('.input-message.autogrow-short').val(); |
|
|
|
|
return instance.chatMessages.keydown(visitor.getRoom(), event, instance); |
|
|
|
|
}, |
|
|
|
|
'click .send-button': function(event, instance) { |
|
|
|
|
$('.input-message.autogrow-short').val(); |
|
|
|
|
|
|
|
|
|
let input = instance.find('.input-message'); |
|
|
|
|
let sent = instance.chatMessages.send(visitor.getRoom(), input); |
|
|
|
|
input.focus(); |
|
|
|
|
instance.updateMessageInputHeight(input); |
|
|
|
|
|
|
|
|
|
return sent; |
|
|
|
|
}, |
|
|
|
|
'click .new-message': function() { |
|
|
|
|
Template.instance().atBottom = true; |
|
|
|
|
return Template.instance().find('.input-message').focus(); |
|
|
|
|
'click .new-message': function(event, instance) { |
|
|
|
|
instance.atBottom = true; |
|
|
|
|
return instance.find('.input-message').focus(); |
|
|
|
|
}, |
|
|
|
|
'click .error': function(event) { |
|
|
|
|
return $(event.currentTarget).removeClass('show'); |
|
|
|
|
return $(input).removeClass('show'); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -53,6 +55,19 @@ Template.messages.onCreated(function() { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
self.atBottom = true; |
|
|
|
|
|
|
|
|
|
self.updateMessageInputHeight = function(input) { |
|
|
|
|
// Inital height is 28. If the scrollHeight is greater than that( we have more text than area ),
|
|
|
|
|
// increase the size of the textarea. The max-height is set at 200
|
|
|
|
|
// even if the scrollHeight become bigger than that it should never exceed that.
|
|
|
|
|
// Account for no text in the textarea when increasing the height.
|
|
|
|
|
// If there is no text, reset the height.
|
|
|
|
|
let inputScrollHeight; |
|
|
|
|
inputScrollHeight = $(input).prop('scrollHeight'); |
|
|
|
|
if (inputScrollHeight > 28) { |
|
|
|
|
return $(input).height($(input).val() === '' ? '15px' : (inputScrollHeight >= 200 ? inputScrollHeight - 50 : inputScrollHeight - 20)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Template.messages.onRendered(function() { |
|
|
|
|