<commit_before>(function () {
  'use strict';

  moj.Modules.SubTotal = {
    el: '.js-SubTotal',

    init: function () {
      _.bindAll(this, 'render', 'showSummary', 'calculate');
      this.cacheEls();
      this.bindEvents();
      moj.log('init');
    },

    bindEvents: function () {
      this.$sets.on('keyup', 'input[type=number]', this.showSummary);

      moj.Events.on('render', this.render);
    },

    cacheEls: function () {
      this.$sets = $(this.el);
    },

    render: function () {
      this.$sets.each(this.showSummary);
    },

    calculate: function (set) {
      var total = 0;

      set.find('input[type=number]').each(function (i, el) {
        var val = parseFloat($(el).val());
        if (!isNaN(val)) {
          total += val;
        }
      });

      return total;
    },

    showSummary: function (e, el) {
      var $set = el !== undefined ? $(el) : $(e.target).closest(this.el),
          value = this.calculate($set);

      moj.log(CLA.templates);

      if ($set.find('.ValueSummary').length > 0) {
        $set.find('.ValueSummary').replaceWith(CLA.templates.SubTotal({value: value}));
      } else {
        $set.append(CLA.templates.SubTotal({value: value}));
      }
    }
  };
}());<commit_msg>Stop sub totals being appended<commit_after>(function () {
  'use strict';

  moj.Modules.SubTotal = {
    el: '.js-SubTotal',

    init: function () {
      _.bindAll(this, 'render', 'showSummary', 'calculate');
      this.cacheEls();
      this.bindEvents();
      moj.log('init');
    },

    bindEvents: function () {
      this.$sets.on('keyup', 'input[type=number]', this.showSummary);

      moj.Events.on('render', this.render);
    },

    cacheEls: function () {
      this.$sets = $(this.el);
    },

    render: function () {
      this.$sets.each(this.showSummary);
    },

    calculate: function (set) {
      var total = 0;

      set.find('input[type=number]').each(function (i, el) {
        var val = parseFloat($(el).val());
        if (!isNaN(val)) {
          total += val;
        }
      });

      return total;
    },

    showSummary: function (e, el) {
      var $set = el !== undefined ? $(el) : $(e.target).closest(this.el),
          value = this.calculate($set);

      moj.log(CLA.templates);

      if ($set.find('.SubTotal').length > 0) {
        $set.find('.SubTotal').replaceWith(CLA.templates.SubTotal({value: value}));
      } else {
        $set.append(CLA.templates.SubTotal({value: value}));
      }
    }
  };
}());
{'fraction_non_alphanumeric': 0.19545273234942162, 'fraction_numerical': 0.0015955325089748703, 'mean_word_length': 2.295663600525624, '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': '6886067', 'n_tokens_mistral': 851, 'n_tokens_neox': 819, 'n_words': 140}