- always scroll to bottom of the div
- focus the new message form
- allow cmd+enter to submit the form
Created
January 22, 2015 06:52
-
-
Save gogogarrett/5702a1aeeedce89eedca to your computer and use it in GitHub Desktop.
A poor man's realtime chat application.. kinda
![:trollface: :trollface:](https://github.githubassets.com/images/icons/emoji/trollface.png)
This file contains 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
#timeline.timeline-container | |
- @conversation.messages.each do |message| | |
%article.timeline-entry | |
%p= message.body | |
= form_for [@conversation, @form], html: { style: 'overflow: hidden' } do |f| | |
= f.text_area :body, placeholder: "Type your message here ...", rows: 5 | |
= f.button "Send", type: :submit |
This file contains 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
#timeline { | |
height: 450px; | |
overflow-y: scroll | |
} |
This file contains 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
$(function() { | |
var objDiv = document.getElementById("timeline"); | |
objDiv.scrollTop = objDiv.scrollHeight; | |
var myTextarea = document.getElementById("message_body"); | |
myTextarea.focus(); | |
myTextarea.addEventListener('keydown', function(e) { | |
if(e.keyCode == 13 && e.metaKey) { | |
this.form.submit(); | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment