Skip to content

Instantly share code, notes, and snippets.

@gfargo
Forked from jackiig/client-app.js
Last active August 29, 2015 14:22
Show Gist options
  • Save gfargo/3810492e547fc30b8176 to your computer and use it in GitHub Desktop.
Save gfargo/3810492e547fc30b8176 to your computer and use it in GitHub Desktop.
Template.CommentAdd.events({
'submit form': function(e, tmpl) {
e.preventDefault();
formEl = tmpl.find('form');
comment = tmpl.find('[name=comment]').value;
if (comment.trim().length == 0) { return false; };
Comments.insert({
login: Meteor.user().profile.login,
timestamp: new Date,
room: Session.get('activeRoom'),
comment: comment
}, function(err, res) {
if (err) { throw err };
console.log('Inserted comment', res);
});
formEl.reset();
chatCount.set($('.comment-item').length);
}
});
chatCount = new ReactiveVar;
Tracker.autorun(function() {
Session.get('activeRoom');
chatCount.get();
var newHeight = $('.comment-list').height();
$('.main-list').animate({scrollTop: newHeight}, 'slow');
});
Template.CommentItem.onRendered(function() {
chatCount.set($('.comment-item').length);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment