Created
November 2, 2015 12:20
-
-
Save gregtap/31b5af1d99acd09e94e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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