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});
|
2012-09-09 14:29:23 +09:00
|
|
|
},
|
|
|
|
'click .open-comment-link': function(e){
|
|
|
|
e.preventDefault();
|
2012-09-10 18:12:04 +09:00
|
|
|
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 09:59:03 +09:00
|
|
|
|
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 09:59:03 +09:00
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.comment_item.is_my_comment = function(){
|
2012-09-06 09:59:03 +09:00
|
|
|
if(this.user_id && Meteor.user() && Meteor.user()._id==this.user_id){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-09-08 10:23:58 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2012-09-09 13:38:56 +09:00
|
|
|
}
|
|
|
|
|
2012-09-11 11:09:16 +09:00
|
|
|
Template.comment_item.rendered=function(){
|
|
|
|
t("comment_item");
|
|
|
|
}
|
|
|
|
|
2012-09-09 13:38:56 +09:00
|
|
|
Template.comment_item.helpers({
|
2012-09-11 11:09:16 +09:00
|
|
|
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:09:16 +09:00
|
|
|
}
|
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;
|
|
|
|
|
2012-09-10 22:35:35 +09:00
|
|
|
},
|
|
|
|
repress_recursion: function(){
|
|
|
|
if(window.repress_recursion){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-09-09 13:38:56 +09:00
|
|
|
}
|
|
|
|
});
|