<commit_before>var Scat= {};

function play(type) {
  var sounds = {
    'yes' : 'Pop',
    'no' : 'Basso',
    'maybe' : 'Bottle',
  };
  if (window.fluid) {
    window.fluid.playSound(sounds[type]);
  }
}

$.getFocusedElement = function() {
  var elem = document.activeElement;
  return $( elem && ( elem.type || elem.href ) ? elem : [] );
};

// http://stackoverflow.com/a/3109234
function round_to_even(num, decimalPlaces) {
  var d = decimalPlaces || 0;
  var m = Math.pow(10, d);
  var n = d ? num * m : num;
  var i = Math.floor(n), f = n - i;
  var r = (f == 0.5) ? ((i % 2 == 0) ? i : i + 1) : Math.round(n);
  return d ? r / m : r;
}

// format number as $3.00 or ($3.00)
function amount(amount) {
  if (typeof(amount) == 'undefined' || amount == null) {
    return '';
  }
  if (typeof(amount) == 'string') {
    amount= parseFloat(amount);
  }
  if (amount < 0.0) {
    return '($' + Math.abs(amount).toFixed(2) + ')';
  } else {
    return '$' + amount.toFixed(2);
  }
}
Scat.amount= amount;

// display an error message
function displayError(data) {
  if (typeof data != "object") {
    data= { error: data };
  }

  // SimpleModal
  if (typeof $.modal != "undefined") {
    if (!$('#simplemodal-overlay').length) {
      $.modal(data.error);
      return;
    }
  }
  // Bootstrap modal
  else if (!$('body').hasClass('modal-open')) {
    var modal= $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">Error</h4></div><div class="modal-body"></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div></div>');

    $('.modal-body', modal).text(data.error);

    modal.on('hidden.bs.modal', function() {
      $(this).remove();
    });

    modal.appendTo($('body')).modal();

    return;
  }

  // play("no");

  alert(data.error);
}

$(function() {
  $(document).keydown(function(ev) {
    if (ev.keyCode == 16 || ev.keyCode == 17
        || ev.keyCode == 18 || ev.keyCode == 91
        || ev.metaKey || ev.altKey || ev.ctrlKey) {
      return true;
    }
    var el = $.getFocusedElement();
    if (!el.length) {
      var inp= $('.autofocus', this);
      if (ev.keyCode != 13) {
        inp.val('');
      }
      inp.focus();
    }
  });
});

// http://blog.fawnanddoug.com/2012/05/inline-editor-custom-binding-for.html
ko.bindingHandlers.jeditable = {
  init: function(element, valueAccessor, allBindingsAccessor) {
    // get the options that were passed in
    var options = allBindingsAccessor().jeditableOptions || {};
          
    // "submit" should be the default onblur action like regular ko controls
    if (!options.onblur) {
      options.onblur = 'submit';
    }

    // allow the editable function to be set as an option
    if (!options.onupdate) {
      options.onupdate= function(value, params) {<commit_msg>Short-circuit auto-focus when modal is present<commit_after>var Scat= {};

function play(type) {
  var sounds = {
    'yes' : 'Pop',
    'no' : 'Basso',
    'maybe' : 'Bottle',
  };
  if (window.fluid) {
    window.fluid.playSound(sounds[type]);
  }
}

$.getFocusedElement = function() {
  var elem = document.activeElement;
  return $( elem && ( elem.type || elem.href ) ? elem : [] );
};

// http://stackoverflow.com/a/3109234
function round_to_even(num, decimalPlaces) {
  var d = decimalPlaces || 0;
  var m = Math.pow(10, d);
  var n = d ? num * m : num;
  var i = Math.floor(n), f = n - i;
  var r = (f == 0.5) ? ((i % 2 == 0) ? i : i + 1) : Math.round(n);
  return d ? r / m : r;
}

// format number as $3.00 or ($3.00)
function amount(amount) {
  if (typeof(amount) == 'undefined' || amount == null) {
    return '';
  }
  if (typeof(amount) == 'string') {
    amount= parseFloat(amount);
  }
  if (amount < 0.0) {
    return '($' + Math.abs(amount).toFixed(2) + ')';
  } else {
    return '$' + amount.toFixed(2);
  }
}
Scat.amount= amount;

// display an error message
function displayError(data) {
  if (typeof data != "object") {
    data= { error: data };
  }

  // SimpleModal
  if (typeof $.modal != "undefined") {
    if (!$('#simplemodal-overlay').length) {
      $.modal(data.error);
      return;
    }
  }
  // Bootstrap modal
  else if (!$('body').hasClass('modal-open')) {
    var modal= $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">Error</h4></div><div class="modal-body"></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div></div>');

    $('.modal-body', modal).text(data.error);

    modal.on('hidden.bs.modal', function() {
      $(this).remove();
    });

    modal.appendTo($('body')).modal();

    return;
  }

  // play("no");

  alert(data.error);
}

$(function() {
  $(document).keydown(function(ev) {
    if (ev.keyCode == 16 || ev.keyCode == 17
        || ev.keyCode == 18 || ev.keyCode == 91
        || ev.metaKey || ev.altKey || ev.ctrlKey) {
      return true;
    }
    var el = $.getFocusedElement();
    if (!el.length &&
        !$('#simplemodal-overlay').length && !$('.modal-backdrop').length) {
      var inp= $('.autofocus', this);
      if (ev.keyCode != 13) {
        inp.val('');
      }
      inp.focus();
    }
  });
});

// http://blog.fawnanddoug.com/2012/05/inline-editor-custom-binding-for.html
ko.bindingHandlers.jeditable = {
  init: function(element, valueAccessor, allBindingsAccessor) {
    // get the options that were passed in
    var options = allBindingsAccessor().jeditableOptions || {};
          
    // "submit" should be the default onblur action like regular ko controls
    if (!options.onblur) {
      options.onblur = 'submit';
    }

    // allow the editable function to be set as an option
    if (!options.onupdate) {
      options.onupdate= function(value, params) {
{'fraction_non_alphanumeric': 0.19940769990128332, 'fraction_numerical': 0.014149391247120764, 'mean_word_length': 2.94996751137102, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 37, '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': '441545', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2081, 'n_words': 457}