2014-07-04 14:07:50 +09:00
|
|
|
var post = {};
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('post_item')].created = function () {
|
2014-07-04 14:07:50 +09:00
|
|
|
post = this.data;
|
2013-10-28 13:35:20 +09:00
|
|
|
};
|
2012-09-04 18:57:07 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('post_item')].helpers({
|
2014-07-04 14:07:50 +09:00
|
|
|
postModules: function () {
|
|
|
|
return postModules;
|
|
|
|
},
|
|
|
|
templateClass: function () {
|
|
|
|
return camelToDash(this.template);
|
|
|
|
},
|
|
|
|
templateContext: function () {
|
|
|
|
// extend post object with post module position and pass it as the module's context
|
|
|
|
var context = _.extend(post, {position: this.position});
|
|
|
|
return context;
|
|
|
|
},
|
|
|
|
log: function(a){
|
|
|
|
console.log(a);
|
|
|
|
},
|
2013-02-18 12:13:27 +09:00
|
|
|
postLink: function(){
|
2014-01-18 16:52:12 +09:00
|
|
|
return !!this.url ? getOutgoingUrl(this.url) : "/posts/"+this._id;
|
2012-11-21 14:31:58 +09:00
|
|
|
},
|
2014-07-03 10:09:22 +09:00
|
|
|
sourceLink: function(){
|
|
|
|
return !!this.url ? this.url : "/posts/"+this._id;
|
|
|
|
},
|
2013-10-14 11:43:55 +09:00
|
|
|
postTarget: function() {
|
|
|
|
return !!this.url ? '_blank' : '';
|
2012-10-01 14:52:32 +09:00
|
|
|
},
|
2013-10-28 13:35:20 +09:00
|
|
|
oneBasedRank: function(){
|
|
|
|
if(typeof this.rank != 'undefined')
|
|
|
|
return this.rank + 1;
|
2012-10-18 14:51:15 +09:00
|
|
|
},
|
2012-10-01 14:52:32 +09:00
|
|
|
domain: function(){
|
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = this.url;
|
|
|
|
return a.hostname;
|
|
|
|
},
|
|
|
|
current_domain: function(){
|
|
|
|
return "http://"+document.domain;
|
|
|
|
},
|
|
|
|
can_edit: function(){
|
2012-11-21 14:31:58 +09:00
|
|
|
return canEdit(Meteor.user(), this);
|
2012-10-01 14:52:32 +09:00
|
|
|
},
|
|
|
|
authorName: function(){
|
|
|
|
return getAuthorName(this);
|
|
|
|
},
|
2013-10-25 11:23:16 +09:00
|
|
|
profileUrl: function(){
|
2013-10-29 15:06:50 +09:00
|
|
|
// note: we don't want the post to be re-rendered every time user properties change
|
|
|
|
var user = Meteor.users.findOne(this.userId, {reactive: false});
|
2013-10-25 22:01:46 +09:00
|
|
|
if(user)
|
|
|
|
return getProfileUrl(user);
|
2013-10-25 11:23:16 +09:00
|
|
|
},
|
2012-10-01 14:52:32 +09:00
|
|
|
short_score: function(){
|
|
|
|
return Math.floor(this.score*1000)/1000;
|
|
|
|
},
|
|
|
|
ago: function(){
|
2013-01-13 08:52:35 +09:00
|
|
|
// if post is approved show submission time, else show creation time.
|
2014-07-03 13:15:23 +09:00
|
|
|
time = this.status == STATUS_APPROVED ? this.postedAt : this.createdAt;
|
2013-01-13 08:52:35 +09:00
|
|
|
return moment(time).fromNow();
|
2012-10-01 14:52:32 +09:00
|
|
|
},
|
2012-10-09 12:02:37 +09:00
|
|
|
timestamp: function(){
|
2014-07-03 13:15:23 +09:00
|
|
|
time = this.status == STATUS_APPROVED ? this.postedAt : this.createdAt;
|
2013-01-13 08:52:35 +09:00
|
|
|
return moment(time).format("MMMM Do, h:mm:ss a");
|
2012-10-09 12:02:37 +09:00
|
|
|
},
|
2012-10-01 14:52:32 +09:00
|
|
|
voted: function(){
|
|
|
|
var user = Meteor.user();
|
|
|
|
if(!user) return false;
|
|
|
|
return _.include(this.upvoters, user._id);
|
|
|
|
},
|
2012-10-22 09:28:42 +09:00
|
|
|
userAvatar: function(){
|
2013-11-16 17:19:35 +09:00
|
|
|
var author = Meteor.users.findOne(this.userId, {reactive: false});
|
|
|
|
if(!!author)
|
2012-10-22 09:28:42 +09:00
|
|
|
return getAvatarUrl(author);
|
2012-12-24 10:59:13 +01:00
|
|
|
},
|
|
|
|
inactiveClass: function(){
|
2013-11-03 23:45:54 +01:00
|
|
|
return (isAdmin(Meteor.user()) && this.inactive) ? i18n.t('inactive') : "";
|
2013-02-18 12:13:27 +09:00
|
|
|
},
|
|
|
|
categoryLink: function(){
|
|
|
|
return getCategoryUrl(this.slug);
|
2013-04-16 22:23:47 -07:00
|
|
|
},
|
|
|
|
commentsDisplayText: function(){
|
2013-11-03 23:45:54 +01:00
|
|
|
return this.comments == 1 ? i18n.t('comment') : i18n.t('comments');
|
2013-04-16 22:23:47 -07:00
|
|
|
},
|
2013-04-25 22:11:26 -07:00
|
|
|
pointsUnitDisplayText: function(){
|
2014-05-15 15:56:23 +09:00
|
|
|
return this.upvotes == 1 ? i18n.t('point') : i18n.t('points');
|
2014-05-23 13:08:52 +09:00
|
|
|
},
|
|
|
|
isApproved: function(){
|
|
|
|
return this.status == STATUS_APPROVED;
|
2014-07-03 10:09:22 +09:00
|
|
|
},
|
|
|
|
viaTwitter: function () {
|
|
|
|
return !!getSetting('twitterAccount') ? 'via='+getSetting('twitterAccount') : '';
|
2013-04-25 22:11:26 -07:00
|
|
|
}
|
2012-10-01 14:52:32 +09:00
|
|
|
});
|
2012-09-12 09:55:14 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('post_item')].events({
|
2012-10-01 14:52:32 +09:00
|
|
|
'click .upvote-link': function(e, instance){
|
2013-01-15 08:46:03 +09:00
|
|
|
var post = this;
|
2012-10-01 14:52:32 +09:00
|
|
|
e.preventDefault();
|
2013-10-29 15:06:50 +09:00
|
|
|
if(!Meteor.user()){
|
|
|
|
Router.go('/signin');
|
2013-11-09 02:02:05 +01:00
|
|
|
throwError(i18n.t("Please log in first"));
|
2013-10-29 15:06:50 +09:00
|
|
|
}
|
|
|
|
Meteor.call('upvotePost', post, function(error, result){
|
|
|
|
trackEvent("post upvoted", {'_id': post._id});
|
|
|
|
});
|
2013-07-04 12:51:26 +09:00
|
|
|
},
|
|
|
|
'click .share-link': function(e){
|
2013-10-29 15:06:50 +09:00
|
|
|
var $this = $(e.target).parents('.post-share').find('.share-link');
|
|
|
|
var $share = $this.parents('.post-share').find('.share-options');
|
|
|
|
e.preventDefault();
|
|
|
|
$('.share-link').not($this).removeClass("active");
|
|
|
|
$(".share-options").not($share).addClass("hidden");
|
|
|
|
$this.toggleClass("active");
|
|
|
|
$share.toggleClass("hidden");
|
2014-05-23 13:08:52 +09:00
|
|
|
},
|
|
|
|
'click .approve-link': function(e, instance){
|
|
|
|
Meteor.call('approvePost', this);
|
|
|
|
e.preventDefault();
|
|
|
|
},
|
|
|
|
'click .unapprove-link': function(e, instance){
|
|
|
|
Meteor.call('unapprovePost', this);
|
|
|
|
e.preventDefault();
|
2012-09-06 09:59:03 +09:00
|
|
|
}
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|