Vulcan/client/templates/comment_item.js

74 lines
2.1 KiB
JavaScript
Raw Normal View History

2012-09-06 10:18:26 +09:00
Template.comment_item.events = {
2012-09-05 11:55:06 +09:00
'click .goto-comment': function(event){
2012-08-23 00:15:48 -04:00
event.preventDefault();
2012-09-05 11:55:06 +09:00
var href=event.target.href.replace(/^(?:\/\/|[^\/]+)*\//, "");
2012-08-23 00:15:48 -04:00
Session.set('selected_comment', this);
2012-09-05 11:55:06 +09:00
// Session.set('state', 'reply');
Router.navigate(href, {trigger: true});
},
'click .open-comment-link': function(e){
e.preventDefault();
console.log('clicked me', event.target, $(event.target).closest(".comment"));
$(event.target).closest(".comment").removeClass("queued");
2012-08-23 00:15:48 -04:00
}
};
2012-09-06 10:18:26 +09:00
Template.comment_item.ago = function(){
2012-08-22 23:40:09 -04:00
var submitted = new Date(this.submitted);
return submitted.toString();
};
2012-08-23 00:35:31 -04:00
2012-09-06 10:18:26 +09:00
Template.comment_item.child_comments = function(){
2012-09-05 11:55:06 +09:00
var post_id = Session.get('selected_post_id');
var comments = Comments.find({ post: post_id, parent: this._id });
2012-08-23 00:35:31 -04:00
return comments;
};
2012-09-06 10:18:26 +09:00
Template.comment_item.author = function(){
2012-09-08 11:54:08 +09:00
if(Meteor.users.findOne(this.user_id)){
return Meteor.users.findOne(this.user_id).username;
}
};
2012-09-06 10:18:26 +09:00
Template.comment_item.is_my_comment = function(){
if(this.user_id && Meteor.user() && Meteor.user()._id==this.user_id){
return true;
}
return false;
};
Template.comment_item.body_formatted = function(){
2012-09-08 12:11:26 +09:00
if(this.body){
var converter = new Markdown.Converter();
var html_body=converter.makeHtml(this.body);
return html_body.autoLink();
}
}
Template.comment_item.rendered=function(){
t("comment_item");
}
Template.comment_item.helpers({
isQueued: function() {
var commentIsNew=false;
var d=new Date(this.submitted);
commentIsNew=d > window.newCommentTimestamp;
console.log("comment submission date: "+d+" | newCommentTimestamp: "+window.newCommentTimestamp+" | isNew: "+commentIsNew);
2012-09-11 11:10:37 +09:00
if(Meteor.user() && Meteor.user()._id==this.user_id){
// if user is logged in, and the comment belongs to the user, then never queue it
return false;
}
2012-09-11 11:10:37 +09:00
// else, check if comment is newer than the global new comment timestamp, and return the result
return commentIsNew;
},
repress_recursion: function(){
if(window.repress_recursion){
return true;
}
return false;
}
});