<commit_before>define(['jquery', 'mustache', 'scripts/modules/PubSub'],function($, mustache, PubSub){
  'use strict';
  function BaseState(game, name){
    this.game = game;
    this.name = name;
    this.mediator = PubSub;
    if(game){
      this.p1 = game.$player1;
      this.p2 = game.$player2;
      this.data = this.game;
    }
  }

  BaseState.prototype.templates = function(){
    return {
      page: $('#stateTemplate').html(),
      p1Hand: $('#visibleHandTemplate').html(),
      p2Hand: $('#hiddenHandTemplate').html(),
      p1Score: $('#scoreboardTemplate').html(),
      p2Score: $('#scoreboardTemplate').html(),

      play: $('#playTemplate').html(),
      deck: $('#hiddenDeckTemplate').html(),
      crib: $('#hiddenHandTemplate').html(),
      controls: $('#controlsTemplate').html(),
      messages: '{{#$messages}}<li>{{.}}</li>{{/$messages}}'
    };
  };

  BaseState.prototype.init = function() {
    this.render();
  };

  BaseState.prototype.deck = function() {
    this.render();
  };

  BaseState.prototype.selectCard = function() {
    this.render();
  };

  BaseState.prototype.action = function() {
    this.render();
  };

  function calculatePegPosition(points){
    if(points < 31)
      return points;
    if(points >= 31 && points < 61)
      return (61 - (points - 30));
    else if(points >= 61 && points < 91)
      return points - 60;
    else if(points >= 91 && points <121)
      return (61 - (points - 90));
    else
      return 0;
  }

  function renderBoardPegs(data){
    var p1 = {
      leadPoint: calculatePegPosition(data.$player1.points),
      currentPoint: calculatePegPosition(data.$player1.currentPoints)
    };
    var p2 = {
      leadPoint: calculatePegPosition(data.$player2.points),
      currentPoint: calculatePegPosition(data.$player2.currentPoints)
    };
    $('#cribbageBoard ul:first-of-type li:nth-child(' + p2.leadPoint + ')').addClass('player2-board-peg');
    $(' #cribbageBoard ul:first-of-type li:nth-child(' + p2.currentPoint + ')').addClass('player2-board-peg');

    $('#cribbageBoard ul:nth-of-type(2) li:nth-child(' + p1.leadPoint + ')').addClass('player1-board-peg');
    $(' #cribbageBoard ul:nth-of-type(2) li:nth-child(' + p1.currentPoint + ')').addClass('player1-board-peg');
  }

  BaseState.prototype.render = function() {
    var rendered = mustache.render(this.templates().page, this.data, this.templates());
    $('#content').html(rendered);
    this.bindEvents();
    this.mediator.publish('render', this.name, this.game);
    this.mediator.publish('messages-clear');
    if(this.data)
      renderBoardPegs(this.data);
  };

  BaseState.prototype.renderOnly = function(){
    this.render();
    this.unbindEvents();
  };

  BaseState.prototype.bindEvents = function(){
    $('#deck').on('click', function(e){
      this.unbindEvents();<commit_msg>fix error on home view<commit_after>define(['jquery', 'mustache', 'scripts/modules/PubSub'],function($, mustache, PubSub){
  'use strict';
  function BaseState(game, name){
    this.game = game;
    this.name = name;
    this.mediator = PubSub;
    if(game){
      this.p1 = game.$player1;
      this.p2 = game.$player2;
      this.data = this.game;
    }
  }

  BaseState.prototype.templates = function(){
    return {
      page: $('#stateTemplate').html(),
      p1Hand: $('#visibleHandTemplate').html(),
      p2Hand: $('#hiddenHandTemplate').html(),
      p1Score: $('#scoreboardTemplate').html(),
      p2Score: $('#scoreboardTemplate').html(),

      play: $('#playTemplate').html(),
      deck: $('#hiddenDeckTemplate').html(),
      crib: $('#hiddenHandTemplate').html(),
      controls: $('#controlsTemplate').html(),
      messages: '{{#$messages}}<li>{{.}}</li>{{/$messages}}'
    };
  };

  BaseState.prototype.init = function() {
    this.render();
  };

  BaseState.prototype.deck = function() {
    this.render();
  };

  BaseState.prototype.selectCard = function() {
    this.render();
  };

  BaseState.prototype.action = function() {
    this.render();
  };

  function calculatePegPosition(points){
    if(points < 31)
      return points;
    if(points >= 31 && points < 61)
      return (61 - (points - 30));
    else if(points >= 61 && points < 91)
      return points - 60;
    else if(points >= 91 && points <121)
      return (61 - (points - 90));
    else
      return 0;
  }

  function renderBoardPegs(data){
    var p1 = {
      leadPoint: calculatePegPosition(data.$player1.points),
      currentPoint: calculatePegPosition(data.$player1.currentPoints)
    };
    var p2 = {
      leadPoint: calculatePegPosition(data.$player2.points),
      currentPoint: calculatePegPosition(data.$player2.currentPoints)
    };
    $('#cribbageBoard ul:first-of-type li:nth-child(' + p2.leadPoint + ')').addClass('player2-board-peg');
    $(' #cribbageBoard ul:first-of-type li:nth-child(' + p2.currentPoint + ')').addClass('player2-board-peg');

    $('#cribbageBoard ul:nth-of-type(2) li:nth-child(' + p1.leadPoint + ')').addClass('player1-board-peg');
    $(' #cribbageBoard ul:nth-of-type(2) li:nth-child(' + p1.currentPoint + ')').addClass('player1-board-peg');
  }

  BaseState.prototype.render = function() {
    var rendered = mustache.render(this.templates().page, this.data, this.templates());
    $('#content').html(rendered);
    this.bindEvents();
    this.mediator.publish('render', this.name, this.game);
    this.mediator.publish('messages-clear');
    if(this.data && this.data.$player1)
      renderBoardPegs(this.data);
  };

  BaseState.prototype.renderOnly = function(){
    this.render();
    this.unbindEvents();
  };

  BaseState.prototype.bindEvents = function(){
    $('#deck').on('click', function(e){
      this.unbindEvents();
{'fraction_non_alphanumeric': 0.18858343547539835, 'fraction_numerical': 0.01768516897215899, 'mean_word_length': 3.3770114942528737, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '4313970', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1799, 'n_words': 304}