<commit_before>var Card = Backbone.Model.extend({
  defaults: {
    'title': 'New Card',
    'left': 0,
    'top': 0,
    'grabbed': false
  },

	initialize: function(){
    var model = this
    _.bindAll(model, 'grab', 'move', 'letGo', 'delete')
		if (!model.id) model.set({id: 1 + Math.random() * 100000000000000000})

    Networking
      .bind('remote:card-moving', function(data) {
        if (data.id == model.id) {
          model.move(data.left, data.top, true)
        }
      })
      .bind('remote:card-grabbed', function(data) {
        if (data.id == model.id) {
          model.grab(true);
        }
      })
      .bind('remote:card-letgo', function(data) {
        if (data.id == model.id) {
          model.letGo(true);
        }
      })
      .bind('remote:card-changetitle', function(data) {
        if (data.id == model.id) {
          model.changeTitle(data.title, true);
        }
      })
      .bind('remote:card-destroyed', function(data){
        if (data.id == model.id) {
          model.delete(true)
        }
      });

    model
      .bind('change:title', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-changetitle', model.toJSON());
      })
      .bind('change:left', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-moving', model.toJSON());
      })
      .bind('change:top', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-moving', model.toJSON());
      })
      .bind('destroy', function(_card, collection, options) {
        if (!options.remote)
          Networking.trigger('card-destroyed', model.toJSON());
      })
      .bind('change:grabbed', function(_card, value, options) {
        if (!options.remote) {
          var eventName = model.get('grabbed') ? 'card-grabbed' : 'card-letgo';
          Networking.trigger(eventName, model.toJSON());
        }
      });
	},

  grab: function(remote) {
    var grabbed = this.get('grabbed');
    if (!grabbed) this.set({grabbed: true}, { remote: remote });

    return !grabbed;
  },

  move: function(left, top, remote){
    this.set({left: left, top: top}, { remote: remote });
    if (remote) this.set({ remoteMoving: true });
  },

  letGo: function(remote) {
    this.set({grabbed: false}, { remote : remote });
  },

  changeTitle: function(newTitle, remote) {
    this.set({title: newTitle}, { remote: remote });
  },

  delete: function(remote) {
    this.trigger('destroy', this, this.collection, { remote: remote });
  }
});

var Cards = Backbone.Collection.extend({
  model: Card,
});

var CardView = Backbone.View.extend({
	tagName: 'div',
	className: 'card',

	events: {
    'click .delete': 'delete'
	},

	initialize: function(){

		_.bindAll(this, 'render', 'unrender', 'delete', 'poop')

    var model = this.model;

		model.bind('change', this.render)
   	model.bind('destroy', this.unrender)
	},

	render: function(){

		var $el = $(this.el)
    var model = this.model

    $el.html(render('card', model.toJSON()))

    $el.find('.title')
      .keypress(function(e) {
        if (e.keyCode != 13) return;
        var $input = $(this).find('input');
        model.set({title: $input.val()});<commit_msg>fix binding to non-existing function, poop<commit_after>var Card = Backbone.Model.extend({
  defaults: {
    'title': 'New Card',
    'left': 0,
    'top': 0,
    'grabbed': false
  },

	initialize: function(){
    var model = this
    _.bindAll(model, 'grab', 'move', 'letGo', 'delete')
		if (!model.id) model.set({id: 1 + Math.random() * 100000000000000000})

    Networking
      .bind('remote:card-moving', function(data) {
        if (data.id == model.id) {
          model.move(data.left, data.top, true)
        }
      })
      .bind('remote:card-grabbed', function(data) {
        if (data.id == model.id) {
          model.grab(true);
        }
      })
      .bind('remote:card-letgo', function(data) {
        if (data.id == model.id) {
          model.letGo(true);
        }
      })
      .bind('remote:card-changetitle', function(data) {
        if (data.id == model.id) {
          model.changeTitle(data.title, true);
        }
      })
      .bind('remote:card-destroyed', function(data){
        if (data.id == model.id) {
          model.delete(true)
        }
      });

    model
      .bind('change:title', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-changetitle', model.toJSON());
      })
      .bind('change:left', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-moving', model.toJSON());
      })
      .bind('change:top', function(_card, value, options) {
        if (!options.remote)
          Networking.trigger('card-moving', model.toJSON());
      })
      .bind('destroy', function(_card, collection, options) {
        if (!options.remote)
          Networking.trigger('card-destroyed', model.toJSON());
      })
      .bind('change:grabbed', function(_card, value, options) {
        if (!options.remote) {
          var eventName = model.get('grabbed') ? 'card-grabbed' : 'card-letgo';
          Networking.trigger(eventName, model.toJSON());
        }
      });
	},

  grab: function(remote) {
    var grabbed = this.get('grabbed');
    if (!grabbed) this.set({grabbed: true}, { remote: remote });

    return !grabbed;
  },

  move: function(left, top, remote){
    this.set({left: left, top: top}, { remote: remote });
    if (remote) this.set({ remoteMoving: true });
  },

  letGo: function(remote) {
    this.set({grabbed: false}, { remote : remote });
  },

  changeTitle: function(newTitle, remote) {
    this.set({title: newTitle}, { remote: remote });
  },

  delete: function(remote) {
    this.trigger('destroy', this, this.collection, { remote: remote });
  }
});

var Cards = Backbone.Collection.extend({
  model: Card,
});

var CardView = Backbone.View.extend({
	tagName: 'div',
	className: 'card',

	events: {
    'click .delete': 'delete'
	},

	initialize: function(){

		_.bindAll(this, 'render', 'unrender', 'delete');

    var model = this.model;

		model.bind('change', this.render)
   	model.bind('destroy', this.unrender)
	},

	render: function(){

		var $el = $(this.el)
    var model = this.model

    $el.html(render('card', model.toJSON()))

    $el.find('.title')
      .keypress(function(e) {
        if (e.keyCode != 13) return;
        var $input = $(this).find('input');
        model.set({title: $input.val()});
{'fraction_non_alphanumeric': 0.18179040635502597, 'fraction_numerical': 0.007027192178429576, 'mean_word_length': 2.5542888165038002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3921735', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2121, 'n_words': 419}