Sha256: 10c0e31a21e7800fda423e2151f8a638b6a2f04263bacbe1bf6c91577e442f35

Contents?: true

Size: 1.01 KB

Versions: 22

Compression:

Stored size: 1.01 KB

Contents

// pluralize(12, 'коров', 'корова', 'коровы')
function pluralize(num, zero, one, two) {
  num = Math.abs(num);
  if ( (num >= 5) && (num <= 20) ) return zero;
  num = num % 10;
  if ( num == 1 ) return one;
  if ( (num >= 2) && (num <= 4) ) return two;
  return zero;
}

function limitField(field_selector, limit, info_selector) {
  var jInfo = $(info_selector);
  var jField = $(field_selector);
  var text_buffer = jField.val();
  jField.bind('keyup change', function () {
    var text = jField.val();
    var text_length = text.length;
    if (text_length > limit) {
      jInfo.html('<span style="color: red;">Не может быть длиннее ' + limit + ' символов!</span>');
      jField.val(text_buffer);
      return false;
    } else {
      text_buffer = text;
      var rest = limit - text_length;
      jInfo.html('Остал' + pluralize(rest, 'ось', 'ся', 'ось') + ' ' + rest + ' символ' + pluralize(rest, 'ов', '', 'а') + '.');
      return true;
    }
  } ).change();
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ultimate-base-0.7.2 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.6.2 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.6.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.5.0.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.4.1.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.4.0.1 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.4.0.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.5.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.4.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.3.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.2.1 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.2 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.1.1 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.1 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.0 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.3.0.alpha app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.2.4 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.2.3.2 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.2.3 app/assets/javascripts/ultimate/experimental/_inflections/plur.js
ultimate-base-0.2.2 app/assets/javascripts/ultimate/experimental/_inflections/plur.js