2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.events = {
|
2012-09-04 18:57:07 +09:00
|
|
|
'click .go-to-comments': function(e){
|
|
|
|
e.preventDefault();
|
2012-09-04 18:59:59 +09:00
|
|
|
// Session.set('selected_post', this);
|
2012-09-04 18:57:07 +09:00
|
|
|
Session.set('state', 'view_post');
|
2012-09-04 18:59:59 +09:00
|
|
|
Router.navigate('posts/'+this._id, {trigger: true});
|
2012-09-04 18:57:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
, 'click .upvote-link': function(){
|
|
|
|
Meteor.call('voteForPost', this);
|
|
|
|
}
|
|
|
|
|
|
|
|
, 'click .share-link': function(e){
|
|
|
|
var $this = $(e.target);
|
|
|
|
e.preventDefault();
|
|
|
|
$(".share-link").not($this).next().addClass("hidden");
|
|
|
|
$this.next().toggleClass("hidden");
|
|
|
|
// $(".overlay").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.rendered = function(){
|
2012-09-04 18:57:07 +09:00
|
|
|
if (Meteor.is_client) {
|
|
|
|
if($(window).width()>400){ //do not load social media plugin on mobile
|
2012-09-06 12:08:12 +09:00
|
|
|
// $('.share-replace').sharrre({
|
|
|
|
// share: {
|
|
|
|
// googlePlus: true,
|
|
|
|
// facebook: true,
|
|
|
|
// twitter: true,
|
|
|
|
// },
|
|
|
|
// buttons: {
|
|
|
|
// googlePlus: {size: 'tall'},
|
|
|
|
// facebook: {layout: 'box_count'},
|
|
|
|
// twitter: {count: 'vertical'},
|
|
|
|
// },
|
|
|
|
// enableHover: false,
|
|
|
|
// enableCounter: false,
|
|
|
|
// enableTracking: true
|
|
|
|
// });
|
2012-09-04 18:57:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.rank = function(){
|
2012-09-04 18:57:07 +09:00
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.ago = function(){
|
2012-09-04 18:57:07 +09:00
|
|
|
var submitted = new Date(this.submitted);
|
|
|
|
var timeAgo=jQuery.timeago(submitted);
|
|
|
|
return timeAgo;
|
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.voted = function(){
|
2012-09-04 18:57:07 +09:00
|
|
|
var user = Meteor.user();
|
|
|
|
if(!user) return false;
|
|
|
|
var myvote = MyVotes.findOne({post: this._id, user: user._id});
|
|
|
|
return !!myvote;
|
|
|
|
};
|
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.domain = function(){
|
2012-09-04 18:57:07 +09:00
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = this.url;
|
|
|
|
return a.hostname;
|
|
|
|
};
|
2012-09-06 09:59:03 +09:00
|
|
|
|
2012-09-06 10:18:26 +09:00
|
|
|
Template.post_item.is_my_post = 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-06 10:18:26 +09:00
|
|
|
Template.post_item.author = function(){
|
2012-09-06 12:27:59 +09:00
|
|
|
if(this.user_id && Meteor.users.findOne(this.user_id)){
|
2012-09-06 09:59:03 +09:00
|
|
|
return Meteor.users.findOne(this.user_id).username
|
|
|
|
}
|
|
|
|
};
|