2012-10-10 13:54:48 +09:00
|
|
|
Template.posts_digest.helpers({
|
|
|
|
posts: function(){
|
2012-12-13 18:12:08 +11:00
|
|
|
return currentDigestHandle().fetch();
|
2012-10-09 12:02:37 +09:00
|
|
|
},
|
2012-10-19 09:05:02 +09:00
|
|
|
hasPosts: function(){
|
2012-12-13 18:46:09 +11:00
|
|
|
var handle = currentDigestHandle()
|
|
|
|
return handle && ! handle.loading() && handle.loaded() > 0;
|
2012-10-19 09:05:02 +09:00
|
|
|
},
|
2012-10-10 13:54:48 +09:00
|
|
|
currentDate: function(){
|
2012-12-23 11:15:36 +01:00
|
|
|
var currentDate=moment(Session.get('currentDate'));
|
|
|
|
var today=moment(new Date());
|
|
|
|
var diff=today.diff(currentDate, 'days');
|
|
|
|
if(diff === 0)
|
|
|
|
return "Today";
|
|
|
|
if(diff === 1)
|
|
|
|
return "Yesterday";
|
|
|
|
return currentDate.format("dddd, MMMM Do YYYY");
|
2012-10-10 13:54:48 +09:00
|
|
|
},
|
|
|
|
previousDateURL: function(){
|
2012-11-25 19:01:52 +11:00
|
|
|
var currentDate=moment(Session.get('currentDate'));
|
|
|
|
var newDate=currentDate.subtract('days', 1);
|
|
|
|
return getDigestURL(newDate);
|
2012-10-10 13:54:48 +09:00
|
|
|
},
|
|
|
|
showPreviousDate: function(){
|
|
|
|
// TODO
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
nextDateURL: function(){
|
2012-11-25 19:01:52 +11:00
|
|
|
var currentDate=moment(Session.get('currentDate'));
|
|
|
|
var newDate=currentDate.add('days', 1);
|
|
|
|
return getDigestURL(newDate);
|
2012-10-10 13:54:48 +09:00
|
|
|
},
|
|
|
|
showNextDate: function(){
|
2012-11-25 19:01:52 +11:00
|
|
|
var currentDate=moment(Session.get('currentDate')).startOf('day');
|
|
|
|
var today=moment(new Date()).startOf('day');
|
2012-11-26 11:27:27 +09:00
|
|
|
return isAdmin(Meteor.user()) || (today.diff(currentDate, 'days') > 0)
|
2012-10-09 12:02:37 +09:00
|
|
|
}
|
2012-10-22 09:28:42 +09:00
|
|
|
});
|
|
|
|
|
2012-10-22 14:00:47 +09:00
|
|
|
Template.posts_digest.created = function(){
|
2012-12-16 14:25:46 +01:00
|
|
|
$(document).unbind('keyup'); //remove any potential existing bindings to avoid duplicates
|
2012-11-25 19:01:52 +11:00
|
|
|
var currentDate=moment(Session.get('currentDate')).startOf('day');
|
|
|
|
var today=moment(new Date()).startOf('day');
|
2012-12-14 17:12:52 +09:00
|
|
|
$(document).bind('keyup', 'left', function(){
|
2012-11-26 12:18:29 +09:00
|
|
|
Meteor.Router.to($('.prev-link').attr('href'));
|
2012-11-25 19:01:52 +11:00
|
|
|
});
|
2012-12-14 17:12:52 +09:00
|
|
|
$(document).bind('keyup', 'right', function(){
|
2012-11-26 11:27:27 +09:00
|
|
|
if(isAdmin(Meteor.user()) || today.diff(currentDate, 'days') > 0)
|
2012-11-26 12:18:29 +09:00
|
|
|
Meteor.Router.to($('.next-link').attr('href'));
|
2012-11-25 19:01:52 +11:00
|
|
|
});
|
2012-12-20 21:34:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Template.posts_digest.rendered = function(){
|
|
|
|
var distanceFromTop = 0;
|
|
|
|
$('.post').each(function(){
|
|
|
|
distanceFromTop += $(this).height();
|
|
|
|
});
|
|
|
|
distanceFromTop+=55;
|
|
|
|
Session.set('distanceFromTop', distanceFromTop);
|
|
|
|
$('body').css('min-height',distanceFromTop+160);
|
|
|
|
$('.more-button').css('top', distanceFromTop+"px");
|
|
|
|
}
|