Vulcan/client/views/comments/comment_edit.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

Template.comment_edit.rendered = function(){
2013-10-09 12:39:05 +09:00
var comment = this.data.comment;
if(comment && Meteor.user() && !this.editor){
this.editor = new EpicEditor(EpicEditorOptions).load();
this.editor.importFile('editor', comment.body);
$(this.editor.editor).bind('keydown', 'meta+return', function(){
$(window.editor).closest('form').find('input[type="submit"]').click();
});
}
}
Template.comment_edit.events = {
2013-10-09 12:39:05 +09:00
'click input[type=submit]': function(e, instance){
var comment = this;
var content = cleanUp(instance.editor.exportFile());
e.preventDefault();
if(!Meteor.user())
throw 'You must be logged in.';
Comments.update(comment._id, {
$set: {
body: content
}
});
trackEvent("edit comment", {'postId': comment.post, 'commentId': comment._id});
Router.go("/posts/"+comment.post+"/comments/"+comment._id);
},
'click .delete-link': function(e){
var comment = this;
e.preventDefault();
if(confirm("Are you sure?")){
Meteor.call('removeComment', comment._id);
Router.go("/comments/deleted");
}
}
};