autonumeric-rails 1.9.18.1 → 1.9.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.log
4
+ *.sqlite3
3
5
  .bundle
4
6
  .config
5
7
  .yardoc
@@ -16,5 +18,5 @@ test/tmp
16
18
  test/version_tmp
17
19
  tmp
18
20
  .idea
19
- vendor/assets/javascripts/autonumeric_ujs.js.coffee
20
- spec/dummy/log/*.log
21
+ .ruby-version
22
+ vendor/assets/javascripts/autonumeric_ujs.js.coffee
@@ -1,5 +1,5 @@
1
1
  module Autonumeric
2
2
  module Rails
3
- VERSION = '1.9.18.1'
3
+ VERSION = '1.9.19.0'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@
2
2
  * autoNumeric.js
3
3
  * @author: Bob Knothe
4
4
  * @author: Sokolov Yura aka funny_falcon
5
- * @version: 1.9.18 - 2013-12-03 GMT 9:00 PM
5
+ * @version: 1.9.19 - 2014-03-23 GMT 2:00 PM
6
6
  *
7
7
  * Created by Robert J. Knothe on 2010-10-25. Please report any bugs to https://github.com/BobKnothe/autoNumeric
8
8
  * Created by Sokolov Yura on 2010-11-07
@@ -361,12 +361,15 @@
361
361
  function autoRound(iv, settings) { /** value to string */
362
362
  iv = (iv === '') ? '0' : iv.toString();
363
363
  convertKeyToNumber(settings, 'mDec'); /** set mDec to number needed when mDec set by 'update method */
364
+ if (settings.mRound === 'CHF') {
365
+ iv = (Math.round(iv * 20) / 20).toString();
366
+ }
364
367
  var ivRounded = '',
365
368
  i = 0,
366
369
  nSign = '',
367
370
  rDec = (typeof (settings.aPad) === 'boolean' || settings.aPad === null) ? (settings.aPad ? settings.mDec : 0) : +settings.aPad;
368
371
  var truncateZeros = function (ivRounded) { /** truncate not needed zeros */
369
- var regex = rDec === 0 ? (/(\.[1-9]*)0*$/) : rDec === 1 ? (/(\.\d[1-9]*)0*$/) : new RegExp('(\\.\\d{' + rDec + '}[1-9]*)0*$');
372
+ var regex = (rDec === 0) ? (/(\.(?:\d*[1-9])?)0*$/) : rDec === 1 ? (/(\.\d(?:\d*[1-9])?)0*$/) : new RegExp('(\\.\\d{' + rDec + '}(?:\\d*[1-9])?)0*$');
370
373
  ivRounded = ivRounded.replace(regex, '$1'); /** If there are no decimal places, we don't need a decimal point at the end */
371
374
  if (rDec === 0) {
372
375
  ivRounded = ivRounded.replace(/\.$/, '');
@@ -374,20 +377,20 @@
374
377
  return ivRounded;
375
378
  };
376
379
  if (iv.charAt(0) === '-') { /** Checks if the iv (input Value)is a negative value */
377
- nSign = '-'; /** removes the negative sign will be added back later if required */
378
- iv = iv.replace('-', '');
379
- } /** prepend a zero if first character is not a digit (then it is likely to be a dot)*/
380
- if (!iv.match(/^\d/)) {
381
- iv = '0' + iv;
382
- } /** determines if the value is zero - if zero no negative sign */
383
- if (nSign === '-' && +iv === 0) {
384
- nSign = '';
380
+ nSign = '-';
381
+ iv = iv.replace('-', ''); /** removes the negative sign will be added back later if required */
382
+ }
383
+ if (!iv.match(/^\d/)) { /** append a zero if first character is not a digit (then it is likely to be a dot)*/
384
+ iv = '0' + iv;
385
+ }
386
+ if (nSign === '-' && +iv === 0) { /** determines if the value is zero - if zero no negative sign */
387
+ nSign = '';
385
388
  }
386
389
  if ((+iv > 0 && settings.lZero !== 'keep') || (iv.length > 0 && settings.lZero === 'allow')) { /** trims leading zero's if needed */
387
390
  iv = iv.replace(/^0*(\d)/, '$1');
388
391
  }
389
392
  var dPos = iv.lastIndexOf('.'), /** virtual decimal position */
390
- vdPos = dPos === -1 ? iv.length - 1 : dPos, /** checks decimal places to determine if rounding is required */
393
+ vdPos = (dPos === -1) ? iv.length - 1 : dPos, /** checks decimal places to determine if rounding is required */
391
394
  cDec = (iv.length - 1) - vdPos; /** check if no rounding is required */
392
395
  if (cDec <= settings.mDec) {
393
396
  ivRounded = iv; /** check if we need to pad with zeros */
@@ -395,8 +398,9 @@
395
398
  if (dPos === -1) {
396
399
  ivRounded += '.';
397
400
  }
401
+ var zeros = '000000';
398
402
  while (cDec < rDec) {
399
- var zeros = '000000'.substring(0, rDec - cDec);
403
+ zeros = zeros.substring(0, rDec - cDec);
400
404
  ivRounded += zeros;
401
405
  cDec += zeros.length;
402
406
  }
@@ -405,17 +409,51 @@
405
409
  } else if (cDec === 0 && rDec === 0) {
406
410
  ivRounded = ivRounded.replace(/\.$/, '');
407
411
  }
408
- return nSign + ivRounded;
412
+ if (settings.mRound !== 'CHF') {
413
+ return (+ivRounded === 0) ? ivRounded : nSign + ivRounded;
414
+ }
415
+ if (settings.mRound === 'CHF') {
416
+ dPos = ivRounded.lastIndexOf('.');
417
+ iv = ivRounded;
418
+ }
419
+
409
420
  } /** rounded length of the string after rounding */
410
- var rLength = dPos + settings.mDec, /** test round */
411
- tRound = +iv.charAt(rLength + 1),
421
+ var rLength = dPos + settings.mDec,
422
+ tRound = +iv.charAt(rLength + 1),
412
423
  ivArray = iv.substring(0, rLength + 1).split(''),
413
- odd = (iv.charAt(rLength) === '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2);
414
- if ((tRound > 4 && settings.mRound === 'S') || (tRound > 4 && settings.mRound === 'A' && nSign === '') || (tRound > 5 && settings.mRound === 'A' && nSign === '-') || (tRound > 5 && settings.mRound === 's') || (tRound > 5 && settings.mRound === 'a' && nSign === '') || (tRound > 4 && settings.mRound === 'a' && nSign === '-') || (tRound > 5 && settings.mRound === 'B') || (tRound === 5 && settings.mRound === 'B' && odd === 1) || (tRound > 0 && settings.mRound === 'C' && nSign === '') || (tRound > 0 && settings.mRound === 'F' && nSign === '-') || (tRound > 0 && settings.mRound === 'U')) {
415
- /** Round up the last digit if required, and continue until no more 9's are found */
416
- for (i = (ivArray.length - 1); i >= 0; i -= 1) {
424
+ odd = (iv.charAt(rLength) === '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2),
425
+ onePass = true;
426
+ odd = (odd === 0 && (iv.substring(rLength + 2, iv.length) > 0)) ? 1 : 0;
427
+ if ((tRound > 4 && settings.mRound === 'S') || /** Round half up symmetric */
428
+ (tRound > 4 && settings.mRound === 'A' && nSign === '') || /** Round half up asymmetric positive values */
429
+ (tRound > 5 && settings.mRound === 'A' && nSign === '-') || /** Round half up asymmetric negative values */
430
+ (tRound > 5 && settings.mRound === 's') || /** Round half down symmetric */
431
+ (tRound > 5 && settings.mRound === 'a' && nSign === '') || /** Round half down asymmetric positive values */
432
+ (tRound > 4 && settings.mRound === 'a' && nSign === '-') || /** Round half down asymmetric negative values */
433
+ (tRound > 5 && settings.mRound === 'B') || /** Round half even "Banker's Rounding" */
434
+ (tRound === 5 && settings.mRound === 'B' && odd === 1) || /** Round half even "Banker's Rounding" */
435
+ (tRound > 0 && settings.mRound === 'C' && nSign === '') || /** Round to ceiling toward positive infinite */
436
+ (tRound > 0 && settings.mRound === 'F' && nSign === '-') || /** Round to floor toward negative infinite */
437
+ (tRound > 0 && settings.mRound === 'U') ||
438
+ (settings.mRound === 'CHF')) { /** round up away from zero */
439
+ for (i = (ivArray.length - 1); i >= 0; i -= 1) { /** Round up the last digit if required, and continue until no more 9's are found */
417
440
  if (ivArray[i] !== '.') {
418
- ivArray[i] = +ivArray[i] + 1;
441
+ if (settings.mRound === 'CHF' && ivArray[i] <= 2 && onePass) {
442
+ ivArray[i] = 0;
443
+ onePass = false;
444
+ break;
445
+ }
446
+ if (settings.mRound === 'CHF' && ivArray[i] <= 7 && onePass) {
447
+ ivArray[i] = 5;
448
+ onePass = false;
449
+ break;
450
+ }
451
+ if (settings.mRound === 'CHF' && onePass) {
452
+ ivArray[i] = 10;
453
+ onePass = false;
454
+ } else {
455
+ ivArray[i] = +ivArray[i] + 1;
456
+ }
419
457
  if (ivArray[i] < 10) {
420
458
  break;
421
459
  }
@@ -424,8 +462,8 @@
424
462
  }
425
463
  }
426
464
  }
427
- } /** Reconstruct the string, converting any 10's to 0's */
428
- ivArray = ivArray.slice(0, rLength + 1);
465
+ }
466
+ ivArray = ivArray.slice(0, rLength + 1); /** Reconstruct the string, converting any 10's to 0's */
429
467
  ivRounded = truncateZeros(ivArray.join('')); /** return rounded value */
430
468
  return (+ivRounded === 0) ? ivRounded : nSign + ivRounded;
431
469
  }
@@ -923,7 +961,7 @@
923
961
  return this;
924
962
  }
925
963
  if (settings.runOnce === false && settings.aForm) {/** routine to format default value on page load */
926
- if ($this.is('input[type=text], input[type=hidden], input:not([type])')) {
964
+ if ($this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])')) {
927
965
  var setValue = true;
928
966
  if ($this[0].value === '' && settings.wEmpty === 'empty') {
929
967
  $this[0].value = '';
@@ -942,7 +980,7 @@
942
980
  }
943
981
  }
944
982
  settings.runOnce = true;
945
- if ($this.is('input[type=text], input[type=hidden], input:not([type])')) { /**added hidden type */
983
+ if ($this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])')) { /**added hidden type */
946
984
  $this.on('keydown.autoNumeric', function (e) {
947
985
  holder = getHolder($this);
948
986
  if (holder.settings.aDec === holder.settings.aSep) {
@@ -1140,7 +1178,7 @@
1140
1178
  value = autoRound('', settings);
1141
1179
  }
1142
1180
  value = autoGroup(value, settings);
1143
- if ($this.is('input[type=text], input[type=hidden], input:not([type])')) { /**added hidden type */
1181
+ if ($this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])')) { /**added hidden type */
1144
1182
  return $this.val(value);
1145
1183
  }
1146
1184
  if ($.inArray($this.prop('tagName'), settings.tagList) !== -1) {
@@ -1161,7 +1199,7 @@
1161
1199
  settings.oEvent = 'get';
1162
1200
  var getValue = '';
1163
1201
  /** determine the element type then use .eq(0) selector to grab the value of the first element in selector */
1164
- if ($this.is('input[type=text], input[type=hidden], input:not([type])')) { /**added hidden type */
1202
+ if ($this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])')) { /**added hidden type */
1165
1203
  getValue = $this.eq(0).val();
1166
1204
  } else if ($.inArray($this.prop('tagName'), settings.tagList) !== -1) {
1167
1205
  getValue = $this.eq(0).text();
@@ -1,2 +1,2 @@
1
- //= require autoNumeric-1.9.18.js
1
+ //= require autoNumeric-1.9.19.js
2
2
  //= require autonumeric_ujs.js
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autonumeric-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.18.1
4
+ version: 1.9.19.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-24 00:00:00.000000000 Z
12
+ date: 2014-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
@@ -246,21 +246,17 @@ files:
246
246
  - spec/dummy/config/initializers/wrap_parameters.rb
247
247
  - spec/dummy/config/locales/en.yml
248
248
  - spec/dummy/config/routes.rb
249
- - spec/dummy/db/development.sqlite3
250
249
  - spec/dummy/db/migrate/20131227002328_create_records.rb
251
250
  - spec/dummy/db/schema.rb
252
- - spec/dummy/db/test.sqlite3
253
251
  - spec/dummy/lib/assets/.keep
254
252
  - spec/dummy/log/.keep
255
- - spec/dummy/log/development.log
256
- - spec/dummy/log/test.log
257
253
  - spec/dummy/public/404.html
258
254
  - spec/dummy/public/422.html
259
255
  - spec/dummy/public/500.html
260
256
  - spec/dummy/public/favicon.ico
261
257
  - spec/spec_helper.rb
262
258
  - spec/support/general.rb
263
- - vendor/assets/javascripts/autoNumeric-1.9.18.js
259
+ - vendor/assets/javascripts/autoNumeric-1.9.19.js
264
260
  - vendor/assets/javascripts/autonumeric.js
265
261
  - vendor/assets/javascripts/autonumeric_ujs.js
266
262
  homepage: https://github.com/randoum/autonumeric-rails
Binary file