<commit_before>// Template.allPosts.rendered = function() { 
//   if (allPosts().count() > 0) {
//     Meteor.setTimeout(function() {
//       Session.set('animationBegun', true)
//     }, 0);
//   }
// }

Template.allPosts.helpers({
  posts: function() {
    return allPosts();
  },
  anySelected: function() {
    return anySelected();
  },
  anySelectedClass: function() {
    return anySelected() ? 'anySelected' : '';
  },
  animatingClass: function() { 
    return Session.get('animationBegun') ? 'animating' : ''; 
  },
  creatingNew: function() {
    return Session.get('creatingNew');
  },
  nextPost: function() {
    var current = getSelected(), next, found = false;
    
    allPosts().forEach(function(post) {
      if (found && ! next)
        next = post;
        
      if (post._id === current._id)
        found = true;
    });
    
    next && (next._isNext = true);
    return next;
  },
  prevPost: function() {
    var current = getSelected(), prev, found = false;
    
    allPosts().forEach(function(post) {
      if (post._id === current._id)
        found = true;
        
      if (!found)
        prev = post;
    });
    
    prev && (prev._isPrev = true);
    return prev;
  }
});


Template.post.preserve(['.post', '.post .header', '.post .header .slider', '.post .body']);

Template.post.helpers({
  open: function() {
    return isOpen(this);
  },
  openClass: function() {
    return isOpen(this) && ! this._isPrev && ! this._isNext ? 'open' : '';
  },
  selectedClass: function() {
    return isSelected(this) ? 'selected' : '';
  },
  editing: function() {
    return isEditing(this);
  },
  nextPrev: function() {
    if (this._isPrev)
      return 'previous';
    if (this._isNext)
      return 'next';
  }
});

Template.post.events({
  'click': function(event) {
    event.preventDefault();
    Meteor.Router.navigate(Routes.postUrl(this), {trigger: true});
  },
  
  // 'click .slider': function(event) {
  //   if (isOpen(this)) {
  //     setOpen(this, false);
  //     event.stopImmediatePropagation();
  //   }
  // },
  // 'click': function() {
  //   isOpen(this) || setOpen(this, true);
  // },
  
  'click .edit': function(event) {
    event.preventDefault();
    Meteor.Router.navigate(Routes.editPostUrl(this));
    setEditing(this, true);
  },
  
  'click .delete': function() {
    if (confirm('Are you sure you want to delete "' + this.title + '"?'))
      Posts.remove(this._id)
  }<commit_msg>Scroll to top when viewing posts<commit_after>// Template.allPosts.rendered = function() { 
//   if (allPosts().count() > 0) {
//     Meteor.setTimeout(function() {
//       Session.set('animationBegun', true)
//     }, 0);
//   }
// }

Template.allPosts.helpers({
  posts: function() {
    return allPosts();
  },
  anySelected: function() {
    return anySelected();
  },
  anySelectedClass: function() {
    return anySelected() ? 'anySelected' : '';
  },
  animatingClass: function() { 
    return Session.get('animationBegun') ? 'animating' : ''; 
  },
  creatingNew: function() {
    return Session.get('creatingNew');
  },
  nextPost: function() {
    var current = getSelected(), next, found = false;
    
    allPosts().forEach(function(post) {
      if (found && ! next)
        next = post;
        
      if (post._id === current._id)
        found = true;
    });
    
    next && (next._isNext = true);
    return next;
  },
  prevPost: function() {
    var current = getSelected(), prev, found = false;
    
    allPosts().forEach(function(post) {
      if (post._id === current._id)
        found = true;
        
      if (!found)
        prev = post;
    });
    
    prev && (prev._isPrev = true);
    return prev;
  }
});


Template.post.preserve(['.post', '.post .header', '.post .header .slider', '.post .body']);

Template.post.helpers({
  open: function() {
    return isOpen(this);
  },
  openClass: function() {
    return isOpen(this) && ! this._isPrev && ! this._isNext ? 'open' : '';
  },
  selectedClass: function() {
    return isSelected(this) ? 'selected' : '';
  },
  editing: function() {
    return isEditing(this);
  },
  nextPrev: function() {
    if (this._isPrev)
      return 'previous';
    if (this._isNext)
      return 'next';
  }
});

Template.post.events({
  'click': function(event) {
    event.preventDefault();
    Meteor.Router.navigate(Routes.postUrl(this), {trigger: true});
    $.smoothScroll({scrollTarget: 0});
  },
  
  // 'click .slider': function(event) {
  //   if (isOpen(this)) {
  //     setOpen(this, false);
  //     event.stopImmediatePropagation();
  //   }
  // },
  // 'click': function() {
  //   isOpen(this) || setOpen(this, true);
  // },
  
  'click .edit': function(event) {
    event.preventDefault();
    Meteor.Router.navigate(Routes.editPostUrl(this));
    setEditing(this, true);
  },
  
  'click .delete': function() {
    if (confirm('Are you sure you want to delete "' + this.title + '"?'))
      Posts.remove(this._id)
  }
{'fraction_non_alphanumeric': 0.18409366168752522, 'fraction_numerical': 0.0010092854259184498, 'mean_word_length': 2.5621854780733284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '196050', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1629, 'n_words': 325}