post_item.js 638 B

12345678910111213141516171819202122232425262728
  1. Template.postItem.helpers({
  2. ownPost: function () {
  3. // Template is invoked in the context of a Post, so 'this' is a Post.
  4. return this.userId === Meteor.userId();
  5. },
  6. domain: function () {
  7. var a = document.createElement('a');
  8. a.href = this.url;
  9. return a.hostname;
  10. },
  11. upvotedClass: function () {
  12. var userId = Meteor.userId();
  13. if (userId && !_.include(this.upvoters, userId)) {
  14. return "btn-primary upvotable";
  15. } else {
  16. return "disabled";
  17. }
  18. }
  19. });
  20. Template.postItem.events({
  21. 'click .upvotable': function (e) {
  22. e.preventDefault();
  23. Meteor.call('upvote', this._id);
  24. }
  25. });