romo 0.19.10 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,5 @@
1
- $.fn.romoCurrencyTextInput = function() {
2
- return $.map(this, function(element) {
3
- return new RomoCurrencyTextInput(element);
4
- });
5
- }
6
-
7
- var RomoCurrencyTextInput = function(element) {
8
- this.elem = $(element);
1
+ var RomoCurrencyTextInput = RomoComponent(function(elem) {
2
+ this.elem = elem;
9
3
  this.hiddenInputElem = undefined;
10
4
 
11
5
  this.defaultIndicatorPosition = 'left';
@@ -15,108 +9,117 @@ var RomoCurrencyTextInput = function(element) {
15
9
  this.defaultFormatNumDecimalPlaces = 2;
16
10
 
17
11
  this.doInit();
18
- this.doBindElem();
12
+ this._bindElem();
19
13
 
20
- this.elem.trigger('romoCurrencyTextInput:ready', [this]);
21
- }
14
+ Romo.trigger(this.elem, 'romoCurrencyTextInput:ready', [this]);
15
+ });
22
16
 
23
- RomoCurrencyTextInput.prototype.doInit = function() {
24
- // override as needed
17
+ RomoCurrencyTextInput.prototype.doSetValue = function(value) {
18
+ this.elem.value = value;
19
+ this._refreshInputValue();
25
20
  }
26
21
 
27
- RomoCurrencyTextInput.prototype.doBindElem = function() {
28
- this.doBindIndicatorTextInput();
22
+ // private
23
+
24
+ RomoCurrencyTextInput.prototype._bindElem = function() {
25
+ this._bindIndicatorTextInput();
29
26
 
30
27
  this.hiddenInputElem = this._getHiddenInputElem();
31
- this.elem.before(this.hiddenInputElem);
32
- this.elem.attr('name', this._getNewInputName());
28
+ Romo.before(this.elem, this.hiddenInputElem);
29
+ Romo.setAttr(this.elem, 'name', this._getNewInputName());
33
30
 
34
- this.elem.on('change', $.proxy(function(e) {
35
- this.doUpdateInputValue();
31
+ Romo.on(this.elem, 'change', Romo.proxy(function(e) {
32
+ this._refreshInputValue();
36
33
  }, this));
37
- this.elem.on('romoCurrencyTextInput:triggerUpdateInputValue', $.proxy(function(e) {
38
- this.doUpdateInputValue();
34
+ Romo.on(this.elem, 'romoOnkey:trigger', Romo.proxy(function(e, triggerEvent, romoOnkey) {
35
+ this._refreshInputValue(true);
36
+ }, this));
37
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerUpdateInputValue', Romo.proxy(function(e) {
38
+ this._refreshInputValue();
39
39
  }, this));
40
40
 
41
- this.doUpdateInputValue();
42
- }
43
-
44
- RomoCurrencyTextInput.prototype.doUpdateInputValue = function() {
45
- var unFormattedValue = this._unFormatCurrencyValue(this.elem.val());
46
- this.hiddenInputElem.val(unFormattedValue);
47
- if (this.elem.data('romo-currency-text-input-format-for-currency') !== false) {
48
- this.elem.val(this._formatCurrencyValue(unFormattedValue));
49
- } else {
50
- this.elem.val(unFormattedValue);
51
- }
52
- }
41
+ new RomoOnkey(this.elem)
53
42
 
54
- RomoCurrencyTextInput.prototype.doSetValue = function(value) {
55
- this.elem.val(value);
56
- this.doUpdateInputValue();
43
+ this._refreshInputValue();
57
44
  }
58
45
 
59
- RomoCurrencyTextInput.prototype.doBindIndicatorTextInput = function() {
60
- this.elem.attr(
61
- 'data-romo-indicator-text-input-indicator-position',
62
- this.elem.data('romo-currency-text-input-indicator-position') || this.defaultIndicatorPosition
46
+ RomoCurrencyTextInput.prototype._bindIndicatorTextInput = function() {
47
+ Romo.setData(
48
+ this.elem,
49
+ 'romo-indicator-text-input-indicator-position',
50
+ Romo.data(this.elem, 'romo-currency-text-input-indicator-position') || this.defaultIndicatorPosition
63
51
  );
64
52
 
65
- if (this.elem.data('romo-currency-text-input-indicator') !== undefined) {
66
- this.elem.attr(
67
- 'data-romo-indicator-text-input-indicator',
68
- this.elem.data('romo-currency-text-input-indicator')
53
+ if (Romo.data(this.elem, 'romo-currency-text-input-indicator') !== undefined) {
54
+ Romo.setData(
55
+ this.elem,
56
+ 'romo-indicator-text-input-indicator',
57
+ Romo.data(this.elem, 'romo-currency-text-input-indicator')
69
58
  );
70
59
  }
71
- if (this.elem.data('romo-currency-text-input-indicator-width-px') !== undefined) {
72
- this.elem.attr(
73
- 'data-romo-indicator-text-input-indicator-width-px',
74
- this.elem.data('romo-currency-text-input-indicator-width-px')
60
+ if (Romo.data(this.elem, 'romo-currency-text-input-indicator-width-px') !== undefined) {
61
+ Romo.setData(
62
+ this.elem,
63
+ 'romo-indicator-text-input-indicator-width-px',
64
+ Romo.data(this.elem, 'romo-currency-text-input-indicator-width-px')
75
65
  );
76
66
  }
77
- if (this.elem.data('romo-currency-text-input-indicator-padding-px') !== undefined) {
78
- this.elem.attr(
79
- 'data-romo-indicator-text-input-indicator-padding-px',
80
- this.elem.data('romo-currency-text-input-indicator-padding-px')
67
+ if (Romo.data(this.elem, 'romo-currency-text-input-indicator-padding-px') !== undefined) {
68
+ Romo.setData(
69
+ this.elem,
70
+ 'romo-indicator-text-input-indicator-padding-px',
71
+ Romo.data(this.elem, 'romo-currency-text-input-indicator-padding-px')
81
72
  );
82
73
  }
83
- if (this.elem.data('romo-currency-text-input-elem-display') !== undefined) {
84
- this.elem.attr(
85
- 'data-romo-indicator-text-input-elem-display',
86
- this.elem.data('romo-currency-text-input-elem-display')
74
+ if (Romo.data(this.elem, 'romo-currency-text-input-elem-display') !== undefined) {
75
+ Romo.setData(
76
+ this.elem,
77
+ 'romo-indicator-text-input-elem-display',
78
+ Romo.data(this.elem, 'romo-currency-text-input-elem-display')
87
79
  );
88
80
  }
89
- if (this.elem.data('romo-currency-text-input-btn-group') !== undefined) {
90
- this.elem.attr(
91
- 'data-romo-indicator-text-input-btn-group',
92
- this.elem.data('romo-currency-text-input-btn-group')
81
+ if (Romo.data(this.elem, 'romo-currency-text-input-btn-group') !== undefined) {
82
+ Romo.setData(
83
+ this.elem,
84
+ 'romo-indicator-text-input-btn-group',
85
+ Romo.data(this.elem, 'romo-currency-text-input-btn-group')
93
86
  );
94
87
  }
95
88
 
96
- this.elem.on('indicatorTextInput:indicatorClick', $.proxy(function(e) {
97
- this.elem.trigger('romoCurrencyTextInput:indicatorClick', []);
89
+ Romo.on(this.elem, 'romoIndicatorTextInput:indicatorClick', Romo.proxy(function(e) {
90
+ Romo.trigger(this.elem, 'romoCurrencyTextInput:indicatorClick', []);
98
91
  }, this));
99
92
 
100
- this.elem.on('romoCurrencyTextInput:triggerPlaceIndicator', $.proxy(function(e) {
101
- this.elem.trigger('indicatorTextInput:triggerPlaceIndicator', []);
93
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerPlaceIndicator', Romo.proxy(function(e) {
94
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerPlaceIndicator', []);
102
95
  }, this));
103
- this.elem.on('romoCurrencyTextInput:triggerEnable', $.proxy(function(e) {
104
- this.elem.trigger('indicatorTextInput:triggerEnable', []);
96
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerEnable', Romo.proxy(function(e) {
97
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerEnable', []);
105
98
  }, this));
106
- this.elem.on('romoCurrencyTextInput:triggerDisable', $.proxy(function(e) {
107
- this.elem.trigger('indicatorTextInput:triggerDisable', []);
99
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerDisable', Romo.proxy(function(e) {
100
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerDisable', []);
108
101
  }, this));
109
- this.elem.on('romoCurrencyTextInput:triggerShow', $.proxy(function(e) {
110
- this.elem.trigger('indicatorTextInput:triggerShow', []);
102
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerShow', Romo.proxy(function(e) {
103
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerShow', []);
111
104
  }, this));
112
- this.elem.on('romoCurrencyTextInput:triggerHide', $.proxy(function(e) {
113
- this.elem.trigger('indicatorTextInput:triggerHide', []);
105
+ Romo.on(this.elem, 'romoCurrencyTextInput:triggerHide', Romo.proxy(function(e) {
106
+ Romo.trigger(this.elem, 'romoIndicatorTextInput:triggerHide', []);
114
107
  }, this));
115
108
 
116
- this.elem.romoIndicatorTextInput();
109
+ new RomoIndicatorTextInput(this.elem);
117
110
  }
118
111
 
119
- // private
112
+ RomoCurrencyTextInput.prototype._refreshInputValue = function(skipRefreshElemValue) {
113
+ var unFormattedValue = this._unFormatCurrencyValue(this.elem.value);
114
+ this.hiddenInputElem.value = unFormattedValue;
115
+ if (!skipRefreshElemValue) {
116
+ if (Romo.data(this.elem, 'romo-currency-text-input-format-for-currency') !== false) {
117
+ this.elem.value = this._formatCurrencyValue(unFormattedValue);
118
+ } else {
119
+ this.elem.value = unFormattedValue;
120
+ }
121
+ }
122
+ }
120
123
 
121
124
  RomoCurrencyTextInput.prototype._formatCurrencyValue = function(sanitizedValue) {
122
125
  return RomoCurrency.format(sanitizedValue, {
@@ -134,35 +137,42 @@ RomoCurrencyTextInput.prototype._unFormatCurrencyValue = function(inputValue) {
134
137
 
135
138
  RomoCurrencyTextInput.prototype._getFormatThousandsDelim = function() {
136
139
  return (
137
- this.elem.data('romo-currency-text-input-format-thousands-delim') ||
140
+ Romo.data(this.elem, 'romo-currency-text-input-format-thousands-delim') ||
138
141
  this.defaultFormatThousandsDelim
139
142
  );
140
143
  }
141
144
 
142
145
  RomoCurrencyTextInput.prototype._getFormatDecimalDelim = function() {
143
146
  return (
144
- this.elem.data('romo-currency-text-input-format-decimal-delim') ||
147
+ Romo.data(this.elem, 'romo-currency-text-input-format-decimal-delim') ||
145
148
  this.defaultFormatDecimalDelim
146
149
  );
147
150
  }
148
151
 
149
152
  RomoCurrencyTextInput.prototype._getFormatNumDecimalPlaces = function() {
150
- var places = this.elem.data('romo-currency-text-input-format-num-decimal-places');
153
+ var places = Romo.data(this.elem, 'romo-currency-text-input-format-num-decimal-places');
151
154
  return !isNaN(places = Math.abs(places)) ? places : this.defaultFormatNumDecimalPlaces;
152
155
  }
153
156
 
154
157
  RomoCurrencyTextInput.prototype._getHiddenInputElem = function() {
155
- return $('<input type="hidden" name="'+this.elem.attr('name')+'" value="'+this.elem.val()+'">');;
158
+ return Romo.elems(
159
+ '<input type="hidden" ' +
160
+ 'name="'+Romo.attr(this.elem, 'name')+'" ' +
161
+ 'value="'+this.elem.value+'"' +
162
+ '>'
163
+ )[0];
156
164
  }
157
165
 
158
166
  RomoCurrencyTextInput.prototype._getNewInputName = function() {
159
167
  return (
160
- this.elem.attr('name')+
168
+ Romo.attr(this.elem, 'name')+
161
169
  '-'+
162
- (this.elem.data('romo-currency-text-input-name-suffix') || this.defaultInputNameSuffix)
170
+ (Romo.data(this.elem, 'romo-currency-text-input-name-suffix') || this.defaultInputNameSuffix)
163
171
  );
164
172
  }
165
173
 
166
- Romo.onInitUI(function(e) {
167
- Romo.initUIElems(e, '[data-romo-currency-text-input-auto="true"]').romoCurrencyTextInput();
168
- });
174
+ // event functions
175
+
176
+ // init
177
+
178
+ Romo.addElemsInitSelector('[data-romo-currency-text-input-auto="true"]', RomoCurrencyTextInput);
@@ -161,7 +161,7 @@ RomoDate.Parser.prototype.date = function() {
161
161
  if (dateValues.length === 0) {
162
162
  return undefined;
163
163
  }
164
- var year = parseInt(dateValues[0]);
164
+ var year = parseInt(dateValues[0], 10);
165
165
  if (year < 0) {
166
166
  return undefined;
167
167
  }
@@ -176,12 +176,12 @@ RomoDate.Parser.prototype.date = function() {
176
176
  }
177
177
  }
178
178
 
179
- var month = parseInt(dateValues[1]) - 1;
179
+ var month = parseInt(dateValues[1], 10) - 1;
180
180
  if (month < 0 || month > 11) {
181
181
  return undefined;
182
182
  }
183
183
 
184
- var day = parseInt(dateValues[2]);
184
+ var day = parseInt(dateValues[2], 10);
185
185
  var date = RomoDate.for(year, month, day);
186
186
  if (date.getMonth() !== month) {
187
187
  return undefined;