Skip to content

Instantly share code, notes, and snippets.

@gregtap
Created November 2, 2015 12:20
Show Gist options
  • Select an option

  • Save gregtap/31b5af1d99acd09e94e0 to your computer and use it in GitHub Desktop.

Select an option

Save gregtap/31b5af1d99acd09e94e0 to your computer and use it in GitHub Desktop.
<div class="input-container">
{{content-editable value=message
placeholder="Type a message"
type="text"
maxlength=500
on-paste="paste"
on-input="input"
spellcheck=false}}
</div>
<button {{action "addMessage" message}} class="icon-message"></button>
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
addMessage(message) {
// Clear input.
this.set('message', '');
// Focus back to input.
this.$('.ember-content-editable').focus();
// Replace new lines with <br>.
message = message.replace(/(?:\r\n|\r|\n)/g, '<br>');
// Send action up to router.
this.sendAction('addMessage', message);
},
// On content editable paste we check if we have text to send
// and show the `send` button accordingly.
paste(newContent) {
this.send('input', newContent);
},
// Same thing for input change.
input(newContent) {
var isEmpty = newContent.match(/^\s+$/) || newContent === '';
this.set('shouldShowSendButton', !isEmpty);
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment