Vulcan/client/views/comments/comment_form.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

Template.comment_form.rendered = function(){
2013-04-26 17:28:09 +09:00
if(Meteor.user() && !this.editor){
this.editor = new EpicEditor(EpicEditorOptions).load();
$(this.editor.editor).bind('keydown', 'meta+return', function(){
$(window.editor).closest('form').find('input[type="submit"]').click();
});
}
}
Template.comment_form.events = {
2013-04-26 17:28:09 +09:00
'submit form': function(e, instance){
e.preventDefault();
2012-10-01 18:48:46 +09:00
$(e.target).addClass('disabled');
clearSeenErrors();
2013-04-26 17:28:09 +09:00
var content = instance.editor.exportFile();
2013-10-09 12:39:05 +09:00
if(getCurrentRoute()=='comment_reply'){
2013-04-26 17:28:09 +09:00
// child comment
var parentCommentId=Session.get('selectedCommentId');
var postId=Comments.findOne(parentCommentId).post;
2012-10-04 14:54:26 +09:00
2013-04-26 17:28:09 +09:00
Meteor.call('comment', postId, parentCommentId, content, function(error, commentProperties){
if(error){
console.log(error);
throwError(error.reason);
}else{
Session.set('selectedCommentId', null);
trackEvent("newComment", commentProperties);
2012-10-04 10:09:20 +09:00
2013-04-26 17:28:09 +09:00
Session.set('scrollToCommentId', commentProperties.commentId);
2013-10-09 12:39:05 +09:00
Router.go('/posts/'+postId);
2013-04-26 17:28:09 +09:00
}
});
}else{
2013-04-26 17:28:09 +09:00
// root comment
2013-10-09 12:39:05 +09:00
var post = this.post;
2013-04-26 17:28:09 +09:00
var parentCommentId=null;
2012-10-04 14:54:26 +09:00
2013-10-09 12:39:05 +09:00
Meteor.call('comment', post._id, parentCommentId, content, function(error, commentProperties){
2013-04-26 17:28:09 +09:00
if(error){
console.log(error);
throwError(error.reason);
}else{
trackEvent("newComment", commentProperties);
Session.set('scrollToCommentId', commentProperties.commentId);
instance.editor.importFile('editor', '');
}
});
}
}
};