2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('comment_form')].helpers({
|
2014-06-27 19:42:33 +09:00
|
|
|
canComment: function(){
|
|
|
|
return canComment(Meteor.user());
|
|
|
|
}
|
2014-09-16 15:18:27 -04:00
|
|
|
});
|
2014-06-27 19:42:33 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('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();
|
|
|
|
});
|
|
|
|
}
|
2014-09-16 15:18:27 -04:00
|
|
|
};
|
2012-09-25 09:20:49 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('comment_form')].events({
|
2013-04-26 17:28:09 +09:00
|
|
|
'submit form': function(e, instance){
|
2012-09-25 09:20:49 +09:00
|
|
|
e.preventDefault();
|
2012-10-01 18:48:46 +09:00
|
|
|
$(e.target).addClass('disabled');
|
2012-10-08 11:23:12 +09:00
|
|
|
clearSeenErrors();
|
2013-04-26 17:28:09 +09:00
|
|
|
var content = instance.editor.exportFile();
|
2013-10-14 12:14:12 +09:00
|
|
|
if(getCurrentTemplate() == 'comment_reply'){
|
2013-04-26 17:28:09 +09:00
|
|
|
// child comment
|
2013-10-09 20:11:58 +09:00
|
|
|
var parentComment = this.comment;
|
2014-08-04 11:22:43 +09:00
|
|
|
Meteor.call('comment', parentComment.postId, parentComment._id, content, function(error, newComment){
|
2013-10-09 20:11:58 +09:00
|
|
|
if(error){
|
|
|
|
console.log(error);
|
|
|
|
throwError(error.reason);
|
|
|
|
}else{
|
2014-08-04 11:22:43 +09:00
|
|
|
trackEvent("newComment", newComment);
|
|
|
|
Router.go('/posts/'+parentComment.postId+'/comment/'+newComment._id);
|
2013-10-09 20:11:58 +09:00
|
|
|
}
|
2013-04-26 17:28:09 +09:00
|
|
|
});
|
2012-09-25 09:20:49 +09:00
|
|
|
}else{
|
2013-04-26 17:28:09 +09:00
|
|
|
// root comment
|
2013-10-21 23:07:36 +08:00
|
|
|
var post = postObject;
|
2012-10-04 14:54:26 +09:00
|
|
|
|
2014-08-04 11:22:43 +09:00
|
|
|
Meteor.call('comment', post._id, null, content, function(error, newComment){
|
2013-10-09 20:11:58 +09:00
|
|
|
if(error){
|
|
|
|
console.log(error);
|
|
|
|
throwError(error.reason);
|
|
|
|
}else{
|
2014-08-04 11:22:43 +09:00
|
|
|
trackEvent("newComment", newComment);
|
|
|
|
Session.set('scrollToCommentId', newComment._id);
|
2013-10-09 20:11:58 +09:00
|
|
|
instance.editor.importFile('editor', '');
|
|
|
|
}
|
2013-04-26 17:28:09 +09:00
|
|
|
});
|
2012-09-25 09:20:49 +09:00
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|