Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Created January 22, 2015 06:52
Show Gist options
  • Save gogogarrett/5702a1aeeedce89eedca to your computer and use it in GitHub Desktop.
Save gogogarrett/5702a1aeeedce89eedca to your computer and use it in GitHub Desktop.
A poor man's realtime chat application.. kinda :trollface:
#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
#timeline {
height: 450px;
overflow-y: scroll
}
$(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();
}
});
})
  • always scroll to bottom of the div
  • focus the new message form
  • allow cmd+enter to submit the form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment