<commit_before>var app = app || {};

(function ($) {
  'use strict';

  app.FirewoodsView = Backbone.View.extend({
    el: '#firewoods',
    count: 0,
    maxCount: 150,

    initialize: function () {
      this.$list = this.$('#timeline');
      this.$stack = this.$('#timeline_stack');
      this.$form = this.$('#new_firewood');
      this.$input = this.$('#contents');
      this.$title = $('#title');
      this.$commitBtn = this.$('#commit');
      this.$prevMt = this.$('#firewood_prev_mt');

      this.listenTo(app.firewoods, 'reset', this.addAll);
      this.listenTo(app.firewoods, 'add:prepend', this.prepend);
      this.listenTo(app.firewoods, 'add:append', this.append);
      this.listenTo(app.firewoods, 'add:stack', this.updateStackNotice);
      this.listenTo(app.firewoods, 'change:isHighlighted', this.highlightOne);

      this.listenTo(app.channel, 'ajaxSuccess', this.formClear);
      this.listenTo(app.firewoods, 'form:appendMt', this.appendMt);
      this.listenTo(app.firewoods, 'form:flash', this.flashForm);
      this.listenTo(app.firewoods, 'timeline:foldAll', this.foldAll);
      this.listenTo(app.firewoods, 'timeline:unFoldAll', this.unFoldAll);

      this.$('span[rel=tooltip]').tooltip();
      this.originTitle = this.$title.text();
      
      $(document).ajaxError(app.channel.ajaxError);
      app.channel.load();
      app.channel.setPullingTimer();
      setInterval(this.isNearBottom, 1000, this);
    },

    events: {
      'input #contents': 'update_count',
      'keyup #contents': 'update_count',
      'keydown #contents': 'keydown',
      'paste #contents': 'update_count',
      'click #timeline_stack': 'flushStack',
      'submit #new_firewood': 'submit',
      'blur #contents': function () {
        if ($('#contents').html() == '<br>')
          $('#contents').html('');
      }
    },

    keydown: function (e) {
      if (e.keyCode == window.ENTER_KEY) {
        this.submit(e);
      } else if (e.keyCode == window.ESC_KEY) {
        $('#contents').blur();
      } else {
        $('#contents').attr('bw-text-empty',"false");
        e.stopPropagation();
      }
    },

    // Collection Event
    addAll: function () {
      this.$list.html('');
      app.firewoods.each(function (fw) {
        var view = new app.FirewoodView({ model: fw });
        this.$list.append(view.render().el);
      }, this);
    },

    prepend: function () {
      var fws = app.firewoods.where({ state: FW_STATE.IN_STACK }).reverse();
      _.each(fws, function(fw) {
        var view = new app.FirewoodView({ model: fw });
        this.$list.prepend(view.render().el);
        fw.set('state', 0);<commit_msg>fixed #68. filter after paste text from outside. escape html.<commit_after>var app = app || {};

(function ($) {
  'use strict';

  app.FirewoodsView = Backbone.View.extend({
    el: '#firewoods',
    count: 0,
    maxCount: 150,

    initialize: function () {
      this.$list = this.$('#timeline');
      this.$stack = this.$('#timeline_stack');
      this.$form = this.$('#new_firewood');
      this.$input = this.$('#contents');
      this.$title = $('#title');
      this.$commitBtn = this.$('#commit');
      this.$prevMt = this.$('#firewood_prev_mt');

      this.listenTo(app.firewoods, 'reset', this.addAll);
      this.listenTo(app.firewoods, 'add:prepend', this.prepend);
      this.listenTo(app.firewoods, 'add:append', this.append);
      this.listenTo(app.firewoods, 'add:stack', this.updateStackNotice);
      this.listenTo(app.firewoods, 'change:isHighlighted', this.highlightOne);

      this.listenTo(app.channel, 'ajaxSuccess', this.formClear);
      this.listenTo(app.firewoods, 'form:appendMt', this.appendMt);
      this.listenTo(app.firewoods, 'form:flash', this.flashForm);
      this.listenTo(app.firewoods, 'timeline:foldAll', this.foldAll);
      this.listenTo(app.firewoods, 'timeline:unFoldAll', this.unFoldAll);

      this.$('span[rel=tooltip]').tooltip();
      this.originTitle = this.$title.text();
      
      $(document).ajaxError(app.channel.ajaxError);
      app.channel.load();
      app.channel.setPullingTimer();
      setInterval(this.isNearBottom, 1000, this);
    },

    events: {
      'input #contents': 'update_count',
      'keyup #contents': 'update_count',
      'keydown #contents': 'keydown',
      'paste #contents': 'paste_something',
      'click #timeline_stack': 'flushStack',
      'submit #new_firewood': 'submit',
      'blur #contents': function () {
        if ($('#contents').html() == '<br>')
          $('#contents').html('');
      }
    },

    paste_something: function () {
      setTimeout(function() {
        $('#contents').html($('#contents').text());
        this.update_count();
      }.bind(this), 0);
    },

    keydown: function (e) {
      if (e.keyCode == window.ENTER_KEY) {
        this.submit(e);
      } else if (e.keyCode == window.ESC_KEY) {
        $('#contents').blur();
      } else {
        $('#contents').attr('bw-text-empty',"false");
        e.stopPropagation();
      }
    },

    // Collection Event
    addAll: function () {
      this.$list.html('');
      app.firewoods.each(function (fw) {
        var view = new app.FirewoodView({ model: fw });
        this.$list.append(view.render().el);
      }, this);
    },

    prepend: function () {
      var fws = app.firewoods.where({ state: FW_STATE.IN_STACK }).reverse();
      _.each(fws, function(fw) {
        var view = new app.FirewoodView({ model: fw });
        this.$list.prepend(view.render().el);
        fw.set('state', 0);
{'fraction_non_alphanumeric': 0.18913553510196715, 'fraction_numerical': 0.003789929615592853, 'mean_word_length': 2.8566457898399444, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6577', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1770, 'n_words': 303}