<commit_before>/**
 * Row class.
 * @partof Editor
 */

var Model = require('tiny-model');
var Column = require('./column');
var Sortable = require('sortablejs');
var merge = require('./merge');
var currentSortable;
/**
 * Check array of column for equal size
 * @param {array} columns
 * @param {number} colNumber
 * @return {bool}
 */
var checkEqualColumns = function(columns, colNumber) {
  return columns.length < 2 ? colNumber : columns.every(function(col) {
    var size = col.model.get('size')
    return size.large == size.medium && size.medium == size.small &&
      size.small == Math.round(colNumber / columns.length);
  });
};

/**
 * Set equal size to all columns
 * @param {array} columns
 * @param {number} colNumber
 * @return {void}
 */
var justifyColumns = function(columns, colNumber) {
  columns.forEach(function(col) {
    var size = {};
    size.large = size.medium = size.small = Math.round(colNumber / columns.length);
    col.model.set({size: size});
  }, this);
};

var Row = function(parentEditor, options) {
  Object.defineProperty(this, 'class', {
    value: 'Row',
    configurable: false,
    writable: false
  });

  if (parentEditor.class === 'Editor') {
    if (options && options.columns) {
      var columns = options.columns;
      delete options.columns;
    }
    this.model = new Model(merge({
      collapsed: false,
      class: '',
      id: '',
      style: ''
    }, options));
    this.parent = parentEditor;
    this.el = this.render();
    this.childrenHolder = this.el.getElementsByClassName('row-columns-holder')[0];
    this.parent.childrenHolder.appendChild(this.el);
    this.bindEvents();
    this.storage = [];
    if (columns) {
      while (columns.length) {
        this.addColumn(columns.shift());
      }
    } else {
      this.addColumn();
    }

    var sorter = this.sortColumns.bind(this);
    new Sortable(this.childrenHolder, {
      group: 'column',
      handle: '.column-handle',
      draggable: '.editor-column',
      ghostClass: 'sortable-ghost',
      onAdd: sorter,
      onRemove: sorter,
      onUpdate: sorter
    });
  } else {
    throw new Error('Parent editor should be specified');
  }
};

Row.prototype = {
  bindEvents: function() {
    this.el.addEventListener('click', function(event) {

      if (event.target.className === 'row-remove') {
        this.remove();
      } else
      if (event.target.className === 'column-add') {

        if (checkEqualColumns(this.storage, 12)) { //create equal columns
          this.addColumn();
          justifyColumns(this.storage, 12);
        } else { //create simple column
          this.addColumn();<commit_msg>add comments<commit_after>/**
 * Row class.
 * @partof Editor
 */

var Model = require('tiny-model');
var Column = require('./column');
var Sortable = require('sortablejs');
var merge = require('./merge');
var currentSortable;
/**
 * Check array of column for equal size
 * @param {array} columns
 * @param {number} colNumber
 * @return {bool}
 */
var checkEqualColumns = function(columns, colNumber) {
  return columns.length < 2 ? colNumber : columns.every(function(col) {
    var size = col.model.get('size')
    return size.large == size.medium && size.medium == size.small &&
      size.small == Math.round(colNumber / columns.length);
  });
};

/**
 * Set equal size to all columns
 * @param {array} columns
 * @param {number} colNumber
 * @return {void}
 */
var justifyColumns = function(columns, colNumber) {
  columns.forEach(function(col) {
    var size = {};
    size.large = size.medium = size.small = Math.round(colNumber / columns.length);
    col.model.set({size: size});
  }, this);
};

var Row = function(parentEditor, options) {

  // Define class name
  Object.defineProperty(this, 'class', {
    value: 'Row',
    configurable: false,
    writable: false
  });

  if (parentEditor.class === 'Editor') {
    if (options && options.columns) {
      var columns = options.columns;
      delete options.columns;
    }
    this.model = new Model(merge({
      collapsed: false,
      class: '',
      id: '',
      style: ''
    }, options));
    this.parent = parentEditor;
    this.el = this.render();
    this.childrenHolder = this.el.getElementsByClassName('row-columns-holder')[0];
    this.parent.childrenHolder.appendChild(this.el);
    this.bindEvents();
    this.storage = [];
    if (columns) {
      while (columns.length) {
        this.addColumn(columns.shift());
      }
    } else {
      this.addColumn();
    }

    var sorter = this.sortColumns.bind(this);
    new Sortable(this.childrenHolder, {
      group: 'column',
      handle: '.column-handle',
      draggable: '.editor-column',
      ghostClass: 'sortable-ghost',
      onAdd: sorter,
      onRemove: sorter,
      onUpdate: sorter
    });
  } else {
    throw new Error('Parent editor should be specified');
  }
};

Row.prototype = {
  bindEvents: function() {
    this.el.addEventListener('click', function(event) {

      if (event.target.className === 'row-remove') {
        this.remove();
      } else if (event.target.className === 'column-add') {

        if (checkEqualColumns(this.storage, 12)) { //create equal columns
          this.addColumn();
          justifyColumns(this.storage, 12);
        } else { //create simple column
          this.addColumn();
{'fraction_non_alphanumeric': 0.15457115928369464, 'fraction_numerical': 0.0022620169651272385, 'mean_word_length': 2.864530225782957, 'pattern_counts': {'":': 0, '<': 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': '459860', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1589, 'n_words': 373}