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

  this.Skeletor = this.Skeletor || {};
  this.Skeletor.Smartboard = this.Skeletor.Smartboard || {};

  var Smartboard = this.Skeletor.Smartboard;

  Smartboard.View = Smartboard.View || {};

  Smartboard.View.Wall = Smartboard.View.Base.extend({
    initialize: function () {
      var wall = this;

      _.bindAll(this);

      Smartboard.runState.on('change', this.render);

      this.balloons = {};

      Skeletor.Model.awake.brainstorms.on('add', function(n) {
        // Filtering to only contain published brainstorms
        // if (n.get('published') === true) {
          wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
        // }
      });

      Skeletor.Model.awake.brainstorms.on('destroy', function(n) {
        console.warn("I was destoryed", n.id);
        // wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      });

      // Skeletor.Model.awake.brainstorms.on('change', function(n) {
      //   // Filtering to only contain published brainstorms
      //   if (n.get('published') === true) {
      //     wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      //   }
      // });
      // Filtering to only contain published brainstorms
      Skeletor.Model.awake.brainstorms.where({"published":true}).forEach(function(n) {
        wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      });

      Skeletor.Model.awake.tags.on('add', function(t) {
        wall.registerBalloon(t, Smartboard.View.TagBalloon, wall.balloons);
      });
      Skeletor.Model.awake.tags.each(function(t) {
        wall.registerBalloon(t, Smartboard.View.TagBalloon, wall.balloons);
      });
      Skeletor.Model.awake.tags.each(function(t) {
        wall.balloons[t.id].renderConnectors();
      });
    },

    events: {
      'click #add-tag-opener': 'toggleTagInputter',
      'click #submit-new-tag': 'submitNewTag',
      'keydown #new-tag': function(ev) { if (ev.keyCode === 13) return this.submitNewTag(); },
      'click #toggle-pause': 'togglePause'
    },

    ready: function () {
      this.render();
      this.$el.removeClass('loading');
      this.changeWatermark('Brainstorm');
      this.trigger('ready');
    },

    toggleTagInputter: function () {
      var wall = this;
      var addTagContainer = this.$el.find('#add-tag-container');
      addTagContainer.toggleClass('opened');
      if (addTagContainer.hasClass('opened')) {
        return setTimeout(function() {
          return wall.$el.find('#new-tag').focus();
        }, 500);
      }
    },

    submitNewTag: function () {
      var newTag = this.$el.find('#new-tag').val();
      if (jQuery.trim(newTag).length < 2) {
        return; // don't allow tags shorter than 2 characters
      }
      Smartboard.createNewTag(newTag);
      this.$el.find('#add-tag-container').removeClass('opened').blur();
      return this.$el.find('#new-tag').val('');
    },

    togglePause: function () {
      var paused = Smartboard.runState.get('paused');
      return Smartboard.runState.save({
        paused: !paused
      });
    },

    pause: function() {
      this.$el.find('#toggle-pause').addClass('paused').text('Resume');
      if (this.$el.data('phase') !== 'evaluate') {
        jQuery('body').addClass('paused');
        return this.changeWatermark("Paused");
      }
    },

    unpause: function() {
      jQuery('body').removeClass('paused');
      this.$el.find('#toggle-pause').removeClass('paused').text('Pause');
      return this.changeWatermark(this.$el.data('phase') || "brainstorm");
    },

    changeWatermark: function(text) {
      return jQuery('#watermark').fadeOut(800, function() {
        return jQuery(this).text(text).fadeIn(800);
      });
    },

    registerBalloon: function(brainstorm, BalloonView) {
      var wall = this;

      var bv = new BalloonView({
        model: brainstorm
      });
      brainstorm.wake(Smartboard.config.wakeful.url);

      bv.$el.css('visibility', 'hidden');
      bv.wall = wall; // FIXME: hmmm...
      bv.render();

      wall.$el.append(bv.$el);
      brainstorm.on('change:pos', function() {
        bv.pos = brainstorm.getPos();
      });

      brainstorm.on('change:z-index', function() {
        bv.$el.zIndex(brainstorm.get('z-index'));
      });

      if (brainstorm.hasPos()) {
        bv.pos = brainstorm.getPos();
      } else {
        wall.assignRandomPositionToBalloon(brainstorm, bv);
      }

      if (brainstorm.has('z-index')) {
        bv.$el.zIndex(brainstorm.get('z-index'));
      }

      wall.makeBalloonDraggable(brainstorm, bv);
      bv.$el.click(function() {
        wall.moveBalloonToTop(brainstorm, bv);
      });

      bv.render();
      brainstorm.save().done(function() {
        //WARNING: IMPLICIT AS HELL DAWG
        // we need a condition to determine if the 'brainstorm' is a balloon or a tag. For now, saying that if it has an author, it should be a balloon, if not it is a tag
        if (brainstorm.get('author')) {
          // only show balloon if published is true
          // if it isn't we listen to change:publish in the balloon view
          if (brainstorm.get('published')) {
            bv.$el.css('visibility', 'visible');
          }
        } else {
          bv.$el.css('visibility', 'visible');
        }

      });

      this.balloons[brainstorm.id] = bv;
    },

    assignRandomPositionToBalloon: function(doc, view) {
      var left, top, wallHeight, wallWidth;
      wallWidth = this.$el.width;
      wallHeight = this.$el.height;
      left = Math.random() * (wallWidth - view.width);
      top = Math.random() * (wallHeight - view.height);
      doc.setPos({
        left: left,
        top: top
      });
      this.moveBalloonToTop(doc, view);
    },

    moveBalloonToTop: function(doc, view) {
      var maxZ;
      maxZ = this.maxBalloonZ();
      maxZ++;
      return doc.set('z-index', maxZ);
    },

    maxBalloonZ: function() {
      return _.max(this.$el.find('.balloon').map(function(el) {
        return parseInt(jQuery(this).zIndex(), 10);
      }));
    },<commit_msg>minor commenting changes<commit_after>(function () {
  "use strict";

  this.Skeletor = this.Skeletor || {};
  this.Skeletor.Smartboard = this.Skeletor.Smartboard || {};

  var Smartboard = this.Skeletor.Smartboard;

  Smartboard.View = Smartboard.View || {};

  Smartboard.View.Wall = Smartboard.View.Base.extend({
    initialize: function () {
      var wall = this;

      _.bindAll(this);

      Smartboard.runState.on('change', this.render);

      this.balloons = {};

      Skeletor.Model.awake.brainstorms.on('add', function(n) {
        // Filtering to only contain published brainstorms
        // if (n.get('published') === true) {
          wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
        // }
      });

      Skeletor.Model.awake.brainstorms.on('destroy', function(n) {
        console.warn("I was destoryed", n.id);
        // wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      });

      // Skeletor.Model.awake.brainstorms.on('change', function(n) {
      //   // Filtering to only contain published brainstorms
      //   if (n.get('published') === true) {
      //     wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      //   }
      // });
      // Filtering to only contain published brainstorms
      Skeletor.Model.awake.brainstorms.where({"published":true}).forEach(function(n) {
        wall.registerBalloon(n, Smartboard.View.NoteBalloon, wall.balloons);
      });

      Skeletor.Model.awake.tags.on('add', function(t) {
        wall.registerBalloon(t, Smartboard.View.TagBalloon, wall.balloons);
      });
      Skeletor.Model.awake.tags.each(function(t) {
        wall.registerBalloon(t, Smartboard.View.TagBalloon, wall.balloons);
      });
      Skeletor.Model.awake.tags.each(function(t) {
        wall.balloons[t.id].renderConnectors();
      });
    },

    events: {
      'click #add-tag-opener': 'toggleTagInputter',
      'click #submit-new-tag': 'submitNewTag',
      'keydown #new-tag': function(ev) { if (ev.keyCode === 13) return this.submitNewTag(); },
      'click #toggle-pause': 'togglePause'
    },

    ready: function () {
      this.render();
      this.$el.removeClass('loading');
      this.changeWatermark('Brainstorm');
      this.trigger('ready');
    },

    toggleTagInputter: function () {
      var wall = this;
      var addTagContainer = this.$el.find('#add-tag-container');
      addTagContainer.toggleClass('opened');
      if (addTagContainer.hasClass('opened')) {
        return setTimeout(function() {
          return wall.$el.find('#new-tag').focus();
        }, 500);
      }
    },

    submitNewTag: function () {
      var newTag = this.$el.find('#new-tag').val();
      if (jQuery.trim(newTag).length < 2) {
        return; // don't allow tags shorter than 2 characters
      }
      Smartboard.createNewTag(newTag);
      this.$el.find('#add-tag-container').removeClass('opened').blur();
      return this.$el.find('#new-tag').val('');
    },

    togglePause: function () {
      var paused = Smartboard.runState.get('paused');
      return Smartboard.runState.save({
        paused: !paused
      });
    },

    pause: function() {
      this.$el.find('#toggle-pause').addClass('paused').text('Resume');
      if (this.$el.data('phase') !== 'evaluate') {
        jQuery('body').addClass('paused');
        return this.changeWatermark("Paused");
      }
    },

    unpause: function() {
      jQuery('body').removeClass('paused');
      this.$el.find('#toggle-pause').removeClass('paused').text('Pause');
      return this.changeWatermark(this.$el.data('phase') || "brainstorm");
    },

    changeWatermark: function(text) {
      return jQuery('#watermark').fadeOut(800, function() {
        return jQuery(this).text(text).fadeIn(800);
      });
    },

    registerBalloon: function(brainstorm, BalloonView) {
      var wall = this;

      var bv = new BalloonView({
        model: brainstorm
      });
      brainstorm.wake(Smartboard.config.wakeful.url);

      bv.$el.css('visibility', 'hidden');
      bv.wall = wall; // FIXME: hmmm...
      bv.render();

      wall.$el.append(bv.$el);
      brainstorm.on('change:pos', function() {
        bv.pos = brainstorm.getPos();
      });

      brainstorm.on('change:z-index', function() {
        bv.$el.zIndex(brainstorm.get('z-index'));
      });

      if (brainstorm.hasPos()) {
        bv.pos = brainstorm.getPos();
      } else {
        wall.assignRandomPositionToBalloon(brainstorm, bv);
      }

      if (brainstorm.has('z-index')) {
        bv.$el.zIndex(brainstorm.get('z-index'));
      }

      wall.makeBalloonDraggable(brainstorm, bv);
      bv.$el.click(function() {
        wall.moveBalloonToTop(brainstorm, bv);
      });

      bv.render();
      brainstorm.save().done(function() {
        //WARNING: IMPLICIT AS HELL DAWG
        // we need a condition to determine if the 'brainstorm' is a balloon or a tag. For now, saying that if it has an author, it should be a balloon, if not it is a tag
        if (brainstorm.get('author')) {
          // only show balloon if published is true
          // if it isn't we listen to change:publish in the balloon view
          if (brainstorm.get('published')) {
            bv.$el.css('visibility', 'visible');
          }
        }
        // this else is to show the Tag balloons
        else {
          bv.$el.css('visibility', 'visible');
        }

      });

      this.balloons[brainstorm.id] = bv;
    },

    assignRandomPositionToBalloon: function(doc, view) {
      var left, top, wallHeight, wallWidth;
      // changed from this.$el.width;   very strange - maybe changed backbone api?
      wallWidth = this.$el.width();
      wallHeight = this.$el.height();
      left = Math.random() * (wallWidth - view.width);
      top = Math.random() * (wallHeight - view.height);
      doc.setPos({
        left: left,
        top: top
      });
      this.moveBalloonToTop(doc, view);
    },

    moveBalloonToTop: function(doc, view) {
      var maxZ;
      maxZ = this.maxBalloonZ();
      maxZ++;
      return doc.set('z-index', maxZ);
    },

    maxBalloonZ: function() {
      return _.max(this.$el.find('.balloon').map(function(el) {
        return parseInt(jQuery(this).zIndex(), 10);
      }));
    },
{'fraction_non_alphanumeric': 0.16369934745830983, 'fraction_numerical': 0.002416821074679771, 'mean_word_length': 2.471476510067114, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '2255788', 'n_tokens_mistral': 4084, 'n_tokens_neox': 3863, 'n_words': 683}