autonumeric-rails 0.1.9.15 → 0.1.9.17

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
- # Autonumeric::Rails
1
+ # autonumeric-rails
2
2
 
3
- TODO: Write a gem description
3
+ Wrap up the excelent autoNumeric.js javascript library
4
+
5
+ autoNumeric is a jQuery plugin that automatically formats currency (money) and numbers as you type on form inputs.
6
+ It supports most International numeric formats and currency signs including those used in Europe, North and
7
+ South America, Asia and India (lakhs**).
8
+
9
+ autoNumeric.js github repository and documentation [https://github.com/BobKnothe/autoNumeric] (https://github.com/BobKnothe/autoNumeric)
10
+
11
+ autoNumeric.js home page and settings generator [http://www.decorplanit.com/plugin] (http://www.decorplanit.com/plugin)
12
+
13
+ The autonumeric-rails simply wrap up autoNumeric.js and in addition provides ujs flavor to autoNumeric.js
4
14
 
5
15
  ## Installation
6
16
 
@@ -12,14 +22,28 @@ And then execute:
12
22
 
13
23
  $ bundle
14
24
 
15
- Or install it yourself as:
25
+ Then add in your `javascript.js` manifest:
16
26
 
17
- $ gem install autonumeric-rails
27
+ //= require jquery
28
+ //= require autonumeric
18
29
 
19
30
  ## Usage
20
31
 
21
- TODO: Write usage instructions here
32
+ Simply add `data-autonumeric` attribute to your HTML tag to initialize autoNumeric
33
+ with its default values:
34
+
35
+ <%= form_for @model do |f| %>
36
+ <%= f.text_field :field, data: {autonumeric: true} %>
37
+ <% end %>
38
+
39
+ You can also pass autoNumeric configuration parameters directly with a Hash in your HTML tag:
22
40
 
41
+ <%= form_for @model do |f| %>
42
+ <%= f.text_field :field, data: {autonumeric: {aSign: 'USD ', mDec: 0}} %>
43
+ <% end %>
44
+
45
+ See autoNumeric pages (links above) for all details on configuration and options
46
+
23
47
  ## Contributing
24
48
 
25
49
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  module Autonumeric
2
2
  module Rails
3
- VERSION = '0.1.9.15'
3
+ VERSION = '0.1.9.17'
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.15 - 2013-08-05 GMT 6:30 PM
5
+ * @version: 1.9.17 - 2013-09-28 GMT 9:00 AM
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
@@ -93,7 +93,6 @@
93
93
  }
94
94
  });
95
95
  }
96
-
97
96
  function convertKeyToNumber(settings, key) {
98
97
  if (typeof (settings[key]) === 'string') {
99
98
  settings[key] *= 1;
@@ -101,7 +100,7 @@
101
100
  }
102
101
  /**
103
102
  * Preparing user defined options for further usage
104
- * merge them with defaults appropriatly
103
+ * merge them with defaults appropriately
105
104
  */
106
105
  function autoCode($this, settings) {
107
106
  runCallbacks($this, settings);
@@ -231,19 +230,20 @@
231
230
  return s;
232
231
  }
233
232
  /**
234
- * function to handle numbers less than 0 that are stored in Exponential notaion ex: .0000001 stored as 1e-7
233
+ * function to handle numbers less than 0 that are stored in Exponential notation ex: .0000001 stored as 1e-7
235
234
  */
236
- function checkValue(value) {
237
- var decimal = value.indexOf('.');
235
+ function checkValue(value, settings) {
236
+ var decimal = value.indexOf('.'),
237
+ checkSmall = +value;
238
238
  if (decimal !== -1) {
239
- if (decimal === 1 && value.charAt(0) === '0') {
239
+ if (checkSmall < 0.000001 && checkSmall > -1) {
240
240
  value = +value;
241
241
  if (value < 0.000001 && value > 0) {
242
- value = (value + 1).toString();
242
+ value = (value + 10).toString();
243
243
  value = value.substring(1);
244
244
  }
245
245
  if (value < 0 && value > -1) {
246
- value = (value - 1).toString();
246
+ value = (value - 10).toString();
247
247
  value = '-' + value.substring(2);
248
248
  }
249
249
  value = value.toString();
@@ -259,7 +259,7 @@
259
259
  }
260
260
  }
261
261
  }
262
- return value.replace(/^0*(\d)/, '$1');
262
+ return (settings.lZero === 'keep') ? value : value.replace(/^0*(\d)/, '$1');
263
263
  }
264
264
  /**
265
265
  * prepare real number to be converted to our format
@@ -336,7 +336,7 @@
336
336
  ivSplit[1] = ivSplit[1].substring(0, settings.mDec);
337
337
  } /** joins the whole number with the deciaml value */
338
338
  iv = s + settings.aDec + ivSplit[1];
339
- } else { /** if whole numers only */
339
+ } else { /** if whole numbers only */
340
340
  iv = s;
341
341
  }
342
342
  if (settings.aSign) {
@@ -355,8 +355,8 @@
355
355
  /**
356
356
  * round number after setting by pasting or $().autoNumericSet()
357
357
  * private function for round the number
358
- * please note this handled as text - Javascript math function can return inaccurate values
359
- * also this offers multiple rounding metods that are not easily accomplished in javascript
358
+ * please note this handled as text - JavaScript math function can return inaccurate values
359
+ * also this offers multiple rounding methods that are not easily accomplished in JavaScript
360
360
  */
361
361
  function autoRound(iv, settings) { /** value to string */
362
362
  iv = (iv === '') ? '0' : iv.toString();
@@ -427,7 +427,7 @@
427
427
  } /** Reconstruct the string, converting any 10's to 0's */
428
428
  ivArray = ivArray.slice(0, rLength + 1);
429
429
  ivRounded = truncateZeros(ivArray.join('')); /** return rounded value */
430
- return nSign + ivRounded;
430
+ return (+ivRounded === 0) ? ivRounded : nSign + ivRounded;
431
431
  }
432
432
  /**
433
433
  * Holder object for field properties
@@ -447,7 +447,7 @@
447
447
  this.ctrlKey = e.ctrlKey;
448
448
  this.cmdKey = e.metaKey;
449
449
  this.shiftKey = e.shiftKey;
450
- this.selection = getElementSelection(this.that); /** keypress event overwrites meaningfull value of e.keyCode */
450
+ this.selection = getElementSelection(this.that); /** keypress event overwrites meaningful value of e.keyCode */
451
451
  if (e.type === 'keydown' || e.type === 'keyup') {
452
452
  this.kdCode = e.keyCode;
453
453
  }
@@ -549,7 +549,7 @@
549
549
  },
550
550
  /**
551
551
  * expands selection to cover whole sign
552
- * prevents partial deletion/copying/overwritting of a sign
552
+ * prevents partial deletion/copying/overwriting of a sign
553
553
  */
554
554
  expandSelectionOnSign: function (setReal) {
555
555
  var sign_position = this.signPosition(),
@@ -673,7 +673,7 @@
673
673
  cCode = String.fromCharCode(this.which),
674
674
  parts = this.getBeforeAfterStriped(),
675
675
  left = parts[0],
676
- right = parts[1]; /** start rules when the decimal charactor key is pressed */
676
+ right = parts[1]; /** start rules when the decimal character key is pressed */
677
677
  /** always use numeric pad dot to insert decimal separator */
678
678
  if (cCode === settingsClone.aDec || (settingsClone.altDec && cCode === settingsClone.altDec) || ((cCode === '.' || cCode === ',') && this.kdCode === 110)) { /** do not allow decimal character if no decimal part allowed */
679
679
  if (!settingsClone.mDec || !settingsClone.aDec) {
@@ -698,7 +698,7 @@
698
698
  if (cCode === '-' || cCode === '+') { /** prevent minus if not allowed */
699
699
  if (!settingsClone.aNeg) {
700
700
  return true;
701
- } /** carret is always after minus */
701
+ } /** caret is always after minus */
702
702
  if (left === '' && right.indexOf(settingsClone.aNeg) > -1) {
703
703
  left = settingsClone.aNeg;
704
704
  right = right.substring(1, right.length);
@@ -807,7 +807,7 @@
807
807
  var $this = $(this),
808
808
  settings = $this.data('autoNumeric'), /** attempt to grab 'autoNumeric' settings, if they don't exist returns "undefined". */
809
809
  tagData = $this.data(); /** attempt to grab HTML5 data, if they don't exist we'll get "undefined".*/
810
- if (typeof settings !== 'object') { /** If we could't grab settings, create them from defaults and passed options. */
810
+ if (typeof settings !== 'object') { /** If we couldn't grab settings, create them from defaults and passed options. */
811
811
  var defaults = {
812
812
  /** allowed numeric values
813
813
  * please do not modify
@@ -857,7 +857,7 @@
857
857
  * value must be smaller than vMax
858
858
  */
859
859
  vMin: '0.00',
860
- /** max number of decimal places = used to overide deciaml places set by the vMin & vMax values
860
+ /** max number of decimal places = used to override decimal places set by the vMin & vMax values
861
861
  * value must be enclosed in quotes example mDec: '3',
862
862
  * This can also set the value via a call back function mDec: 'css:#
863
863
  */
@@ -869,7 +869,7 @@
869
869
  * mRound: 'a', Round-Half-Down Asymmetric (lower case a)
870
870
  * mRound: 'B', Round-Half-Even "Bankers Rounding"
871
871
  * mRound: 'U', Round Up "Round-Away-From-Zero"
872
- * mRound: 'D', Round Down "Round-Toward-Zero" - same as trancate
872
+ * mRound: 'D', Round Down "Round-Toward-Zero" - same as truncate
873
873
  * mRound: 'C', Round to Ceiling "Toward Positive Infinity"
874
874
  * mRound: 'F', Round to Floor "Toward Negative Infinity"
875
875
  */
@@ -899,7 +899,7 @@
899
899
  */
900
900
  lZero: 'allow',
901
901
  /** determine if the default value will be formatted on page ready.
902
- * true = atomatically formats the default value on page ready
902
+ * true = automatically formats the default value on page ready
903
903
  * false = will not format the default value
904
904
  */
905
905
  aForm: true,
@@ -908,7 +908,7 @@
908
908
  };
909
909
  settings = $.extend({}, defaults, tagData, options); /** Merge defaults, tagData and options */
910
910
  if (settings.aDec === settings.aSep) {
911
- $.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand seperater aSep: '" + settings.aSep + "' are the same character");
911
+ $.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand separator aSep: '" + settings.aSep + "' are the same character");
912
912
  return this;
913
913
  }
914
914
  $this.data('autoNumeric', settings); /** Save our new settings */
@@ -946,7 +946,7 @@
946
946
  $this.on('keydown.autoNumeric', function (e) {
947
947
  holder = getHolder($this);
948
948
  if (holder.settings.aDec === holder.settings.aSep) {
949
- $.error("autoNumeric will not function properly when the decimal character aDec: '" + holder.settings.aDec + "' and thousand seperater aSep: '" + holder.settings.aSep + "' are the same character");
949
+ $.error("autoNumeric will not function properly when the decimal character aDec: '" + holder.settings.aDec + "' and thousand separator aSep: '" + holder.settings.aSep + "' are the same character");
950
950
  return this;
951
951
  }
952
952
  if (holder.that.readOnly) {
@@ -991,7 +991,6 @@
991
991
  return false;
992
992
  }
993
993
  holder.formatted = false;
994
-
995
994
  });
996
995
  $this.on('keyup.autoNumeric', function (e) {
997
996
  var holder = getHolder($this);
@@ -1096,7 +1095,7 @@
1096
1095
  settings = $.extend(settings, options);
1097
1096
  getHolder($this, settings, true);
1098
1097
  if (settings.aDec === settings.aSep) {
1099
- $.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand seperater aSep: '" + settings.aSep + "' are the same character");
1098
+ $.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand separator aSep: '" + settings.aSep + "' are the same character");
1100
1099
  return this;
1101
1100
  }
1102
1101
  $this.data('autoNumeric', settings);
@@ -1106,7 +1105,7 @@
1106
1105
  return;
1107
1106
  });
1108
1107
  },
1109
- /** returns a formated strings for "input:text" fields Uses jQuery's .val() method*/
1108
+ /** returns a formatted strings for "input:text" fields Uses jQuery's .val() method*/
1110
1109
  set: function (valueIn) {
1111
1110
  return $(this).each(function () {
1112
1111
  var $this = autoGet($(this)),
@@ -1117,7 +1116,7 @@
1117
1116
  $.error("You must initialize autoNumeric('init', {options}) prior to calling the 'set' method");
1118
1117
  return this;
1119
1118
  }
1120
- /** allows locale decimal seperator to be a comma */
1119
+ /** allows locale decimal separator to be a comma */
1121
1120
  if (testValue === $this.attr('value')) {
1122
1121
  value = value.replace(',', '.');
1123
1122
  }
@@ -1129,7 +1128,7 @@
1129
1128
  if (!$.isNumeric(+value)) {
1130
1129
  return '';
1131
1130
  }
1132
- value = checkValue(value);
1131
+ value = checkValue(value, settings);
1133
1132
  settings.oEvent = 'set';
1134
1133
  settings.lastSetValue = value; /** saves the unrounded value from the set method - $('selector').data('autoNumeric').lastSetValue; - helpful when you need to change the rounding accuracy*/
1135
1134
  value.toString();
@@ -1151,7 +1150,7 @@
1151
1150
  return false;
1152
1151
  });
1153
1152
  },
1154
- /** method to get the unformated value from a specific input field, returns a numeric value */
1153
+ /** method to get the unformatted value from a specific input field, returns a numeric value */
1155
1154
  get: function () {
1156
1155
  var $this = autoGet($(this)),
1157
1156
  settings = $this.data('autoNumeric');
@@ -1186,10 +1185,10 @@
1186
1185
  if (settings.lZero === 'keep') {
1187
1186
  return getValue;
1188
1187
  }
1189
- getValue = checkValue(getValue);
1188
+ getValue = checkValue(getValue, settings);
1190
1189
  return getValue; /** returned Numeric String */
1191
1190
  },
1192
- /** method to get the unformated value from multiple fields */
1191
+ /** method to get the unformatted value from multiple fields */
1193
1192
  getString: function () {
1194
1193
  var isAutoNumeric = false,
1195
1194
  $this = autoGet($(this)),
@@ -1213,7 +1212,7 @@
1213
1212
  $.error("You must initialize autoNumeric('init', {options}) prior to calling the 'getString' method");
1214
1213
  return this;
1215
1214
  },
1216
- /** method to get the unformated value from multiple fields */
1215
+ /** method to get the unformatted value from multiple fields */
1217
1216
  getArray: function () {
1218
1217
  var isAutoNumeric = false,
1219
1218
  $this = autoGet($(this)),
@@ -1,2 +1,2 @@
1
- //= require autoNumeric-1.9.15.js
1
+ //= require autoNumeric-1.9.17.js
2
2
  //= require autonumeric_ujs.js
@@ -36,18 +36,18 @@
36
36
  jQuery(function() {
37
37
  var auto_numeric_init, update_numeric_value;
38
38
  update_numeric_value = function(input) {
39
- return input.next().val(input.autoNumeric('get'));
39
+ input.next().val(input.autoNumeric('get'));
40
40
  };
41
41
  auto_numeric_init = function(input) {
42
42
  var hidden;
43
43
  hidden = $('<input>').attr('type', 'hidden').attr('id', input.attr('id') + '_val').attr('name', input.attr('name'));
44
44
  hidden.insertAfter(input);
45
45
  input.autoNumeric('init', $.parseJSON(input.attr('data-autonumeric')));
46
- return input.on('keyup', function() {
47
- return update_numeric_value(input);
46
+ input.on('keyup', function() {
47
+ update_numeric_value(input);
48
48
  });
49
49
  };
50
- return $('input[data-autonumeric]').each(function() {
51
- return auto_numeric_init($(this));
50
+ $('input[data-autonumeric]').each(function() {
51
+ auto_numeric_init($(this));
52
52
  });
53
53
  });
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: 0.1.9.15
4
+ version: 0.1.9.17
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: 2013-08-17 00:00:00.000000000 Z
12
+ date: 2013-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
@@ -77,7 +77,7 @@ files:
77
77
  - lib/autonumeric/rails.rb
78
78
  - lib/autonumeric/rails/engine.rb
79
79
  - lib/autonumeric/rails/version.rb
80
- - vendor/assets/javascripts/autoNumeric-1.9.15.js
80
+ - vendor/assets/javascripts/autoNumeric-1.9.17.js
81
81
  - vendor/assets/javascripts/autonumeric.js
82
82
  - vendor/assets/javascripts/autonumeric_ujs.js
83
83
  homepage: https://github.com/randoum/autonumeric-rails