maskmoney-rails 2.0.0.1 → 3.0.2.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.
- checksums.yaml +6 -6
- data/maskmoney-rails.gemspec +1 -1
- data/vendor/assets/javascripts/maskmoney.js +389 -337
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: acf2bf27ba89286a91d4520f5c1233ec48236088
|
4
|
+
data.tar.gz: 0d2d3fa86b98e5d81f07485895b1f4d455707664
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 131f8f20cda11d7a028573b354c750a33156a9471829b1afc5b58af408e55703281b0b9bbd9e0d3c04b9416708b42848680df379b3fbf45aeabdc99a7f9dd77a
|
7
|
+
data.tar.gz: e8cfc0e71cb0ac6821e11855d06245034504f805d814f7c8d5302341a339e54abd898a3aec5d7b1ad6edd1d6d9b5987ff56cb343b6b27465de45bc33ffddf0c1
|
data/maskmoney-rails.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "maskmoney-rails"
|
7
|
-
gem.version = "
|
7
|
+
gem.version = "3.0.2.0"
|
8
8
|
gem.authors = ["Carlos Alexandro Becker"]
|
9
9
|
gem.email = ["caarlos0@gmail.com"]
|
10
10
|
gem.description = %q{jquery.maskMoney for rails.}
|
@@ -1,357 +1,409 @@
|
|
1
1
|
/*
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
var input = $(this);
|
19
|
-
input.unbind('.maskMoney');
|
20
|
-
|
21
|
-
if ($.browser.msie) {
|
22
|
-
this.onpaste = null;
|
23
|
-
} else if ($.browser.mozilla) {
|
24
|
-
this.removeEventListener('input', blurEvent, false);
|
25
|
-
}
|
26
|
-
return this;
|
27
|
-
},
|
28
|
-
|
29
|
-
mask : function(){
|
30
|
-
return this.trigger('mask');
|
31
|
-
},
|
32
|
-
|
33
|
-
init : function(settings) {
|
34
|
-
settings = $.extend({
|
35
|
-
symbol: 'US$',
|
36
|
-
showSymbol: false,
|
37
|
-
symbolStay: false,
|
38
|
-
thousands: ',',
|
39
|
-
decimal: '.',
|
40
|
-
precision: 2,
|
41
|
-
defaultZero: true,
|
42
|
-
allowZero: false,
|
43
|
-
allowNegative: false
|
44
|
-
}, settings);
|
45
|
-
|
46
|
-
return this.each(function() {
|
47
|
-
var input = $(this);
|
48
|
-
var dirty = false;
|
49
|
-
|
50
|
-
function markAsDirty() {
|
51
|
-
dirty = true;
|
52
|
-
}
|
2
|
+
* jquery-maskmoney - v3.0.2
|
3
|
+
* jQuery plugin to mask data entry in the input text in the form of money (currency)
|
4
|
+
* https://github.com/plentz/jquery-maskmoney
|
5
|
+
*
|
6
|
+
* Made by Diego Plentz
|
7
|
+
* Under MIT License (https://raw.github.com/plentz/jquery-maskmoney/master/LICENSE)
|
8
|
+
*/
|
9
|
+
(function ($) {
|
10
|
+
"use strict";
|
11
|
+
if (!$.browser) {
|
12
|
+
$.browser = {};
|
13
|
+
$.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
|
14
|
+
$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
|
15
|
+
$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
|
16
|
+
$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
|
17
|
+
}
|
53
18
|
|
54
|
-
|
55
|
-
|
56
|
-
|
19
|
+
var methods = {
|
20
|
+
destroy : function () {
|
21
|
+
$(this).unbind(".maskMoney");
|
57
22
|
|
58
|
-
|
59
|
-
|
60
|
-
var k = e.which;
|
61
|
-
if (k == undefined) return false; //needed to handle an IE "special" event
|
62
|
-
if (k < 48 || k > 57) { // any key except the numbers 0-9
|
63
|
-
if (k == 45) { // -(minus) key
|
64
|
-
markAsDirty();
|
65
|
-
input.val(changeSign(input));
|
66
|
-
return false;
|
67
|
-
} else if (k == 43) { // +(plus) key
|
68
|
-
markAsDirty();
|
69
|
-
input.val(input.val().replace('-',''));
|
70
|
-
return false;
|
71
|
-
} else if (k == 13 || k == 9) { // enter key or tab key
|
72
|
-
if(dirty){
|
73
|
-
clearDirt();
|
74
|
-
$(this).change();
|
75
|
-
}
|
76
|
-
return true;
|
77
|
-
} else if ($.browser.mozilla && (k == 37 || k == 39)) { // needed for left arrow key or right arrow key with firefox
|
78
|
-
return true;
|
79
|
-
} else { // any other key with keycode less than 48 and greater than 57
|
80
|
-
preventDefault(e);
|
81
|
-
return true;
|
23
|
+
if ($.browser.msie) {
|
24
|
+
this.onpaste = null;
|
82
25
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
26
|
+
return this;
|
27
|
+
},
|
28
|
+
|
29
|
+
mask : function (value) {
|
30
|
+
return this.each(function () {
|
31
|
+
var $this = $(this),
|
32
|
+
decimalSize;
|
33
|
+
if (typeof value === "number") {
|
34
|
+
$this.trigger("mask");
|
35
|
+
decimalSize = $($this.val().split(/\D/)).last()[0].length;
|
36
|
+
value = value.toFixed(decimalSize);
|
37
|
+
$this.val(value);
|
38
|
+
}
|
39
|
+
return $this.trigger("mask");
|
40
|
+
});
|
41
|
+
},
|
42
|
+
|
43
|
+
unmasked : function () {
|
44
|
+
return this.map(function () {
|
45
|
+
var value = ($(this).val() || "0"),
|
46
|
+
isNegative = value.indexOf("-") !== -1,
|
47
|
+
decimalPart;
|
48
|
+
// get the last position of the array that is a number(coercion makes "" to be evaluated as false)
|
49
|
+
$(value.split(/\D/).reverse()).each(function (index, element) {
|
50
|
+
if(element) {
|
51
|
+
decimalPart = element;
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
});
|
55
|
+
value = value.replace(/\D/g, "");
|
56
|
+
value = value.replace(new RegExp(decimalPart + "$"), "." + decimalPart);
|
57
|
+
if (isNegative) {
|
58
|
+
value = "-" + value;
|
59
|
+
}
|
60
|
+
return parseFloat(value);
|
61
|
+
});
|
62
|
+
},
|
63
|
+
|
64
|
+
init : function (settings) {
|
65
|
+
settings = $.extend({
|
66
|
+
prefix: "",
|
67
|
+
suffix: "",
|
68
|
+
affixesStay: true,
|
69
|
+
thousands: ",",
|
70
|
+
decimal: ".",
|
71
|
+
precision: 2,
|
72
|
+
allowZero: false,
|
73
|
+
allowNegative: false
|
74
|
+
}, settings);
|
75
|
+
|
76
|
+
return this.each(function () {
|
77
|
+
var $input = $(this),
|
78
|
+
onFocusValue;
|
79
|
+
|
80
|
+
// data-* api
|
81
|
+
settings = $.extend(settings, $input.data());
|
82
|
+
|
83
|
+
function getInputSelection() {
|
84
|
+
var el = $input.get(0),
|
85
|
+
start = 0,
|
86
|
+
end = 0,
|
87
|
+
normalizedValue,
|
88
|
+
range,
|
89
|
+
textInputRange,
|
90
|
+
len,
|
91
|
+
endRange;
|
92
|
+
|
93
|
+
if (typeof el.selectionStart === "number" && typeof el.selectionEnd === "number") {
|
94
|
+
start = el.selectionStart;
|
95
|
+
end = el.selectionEnd;
|
96
|
+
} else {
|
97
|
+
range = document.selection.createRange();
|
98
|
+
|
99
|
+
if (range && range.parentElement() === el) {
|
100
|
+
len = el.value.length;
|
101
|
+
normalizedValue = el.value.replace(/\r\n/g, "\n");
|
102
|
+
|
103
|
+
// Create a working TextRange that lives only in the input
|
104
|
+
textInputRange = el.createTextRange();
|
105
|
+
textInputRange.moveToBookmark(range.getBookmark());
|
106
|
+
|
107
|
+
// Check if the start and end of the selection are at the very end
|
108
|
+
// of the input, since moveStart/moveEnd doesn't return what we want
|
109
|
+
// in those cases
|
110
|
+
endRange = el.createTextRange();
|
111
|
+
endRange.collapse(false);
|
112
|
+
|
113
|
+
if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
|
114
|
+
start = end = len;
|
115
|
+
} else {
|
116
|
+
start = -textInputRange.moveStart("character", -len);
|
117
|
+
start += normalizedValue.slice(0, start).split("\n").length - 1;
|
118
|
+
|
119
|
+
if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
|
120
|
+
end = len;
|
121
|
+
} else {
|
122
|
+
end = -textInputRange.moveEnd("character", -len);
|
123
|
+
end += normalizedValue.slice(0, end).split("\n").length - 1;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
return {
|
130
|
+
start: start,
|
131
|
+
end: end
|
132
|
+
};
|
133
|
+
} // getInputSelection
|
134
|
+
|
135
|
+
function canInputMoreNumbers() {
|
136
|
+
var haventReachedMaxLength = !($input.val().length >= $input.attr("maxlength") && $input.attr("maxlength") >= 0),
|
137
|
+
selection = getInputSelection(),
|
138
|
+
start = selection.start,
|
139
|
+
end = selection.end,
|
140
|
+
haveNumberSelected = (selection.start !== selection.end && $input.val().substring(start, end).match(/\d/)) ? true : false,
|
141
|
+
startWithZero = ($input.val().substring(0, 1) === "0");
|
142
|
+
return haventReachedMaxLength || haveNumberSelected || startWithZero;
|
143
|
+
}
|
99
144
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
// Remove single character
|
115
|
-
x.value = x.value.substring(0, startPos - 1) + x.value.substring(endPos, x.value.length);
|
116
|
-
startPos = startPos - 1;
|
117
|
-
} else {
|
118
|
-
// Remove multiple characters
|
119
|
-
x.value = x.value.substring(0, startPos) + x.value.substring(endPos, x.value.length);
|
120
|
-
}
|
121
|
-
maskAndPosition(x, startPos);
|
122
|
-
markAsDirty();
|
123
|
-
return false;
|
124
|
-
} else if (k==9) { // tab key
|
125
|
-
if(dirty) {
|
126
|
-
$(this).change();
|
127
|
-
clearDirt();
|
128
|
-
}
|
129
|
-
return true;
|
130
|
-
} else if ( k==46 || k==63272 ) { // delete key (with special case for safari)
|
131
|
-
preventDefault(e);
|
132
|
-
if(x.selectionStart == x.selectionEnd){
|
133
|
-
// Remove single character
|
134
|
-
x.value = x.value.substring(0, startPos) + x.value.substring(endPos + 1, x.value.length);
|
135
|
-
} else {
|
136
|
-
//Remove multiple characters
|
137
|
-
x.value = x.value.substring(0, startPos) + x.value.substring(endPos, x.value.length);
|
138
|
-
}
|
139
|
-
maskAndPosition(x, startPos);
|
140
|
-
markAsDirty();
|
141
|
-
return false;
|
142
|
-
} else { // any other key
|
143
|
-
return true;
|
144
|
-
}
|
145
|
-
}
|
145
|
+
function setCursorPosition(pos) {
|
146
|
+
$input.each(function (index, elem) {
|
147
|
+
if (elem.setSelectionRange) {
|
148
|
+
elem.focus();
|
149
|
+
elem.setSelectionRange(pos, pos);
|
150
|
+
} else if (elem.createTextRange) {
|
151
|
+
var range = elem.createTextRange();
|
152
|
+
range.collapse(true);
|
153
|
+
range.moveEnd("character", pos);
|
154
|
+
range.moveStart("character", pos);
|
155
|
+
range.select();
|
156
|
+
}
|
157
|
+
});
|
158
|
+
}
|
146
159
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
}
|
156
|
-
if (this.createTextRange) {
|
157
|
-
var textRange = this.createTextRange();
|
158
|
-
textRange.collapse(false); // set the cursor at the end of the input
|
159
|
-
textRange.select();
|
160
|
-
}
|
161
|
-
}
|
160
|
+
function setSymbol(value) {
|
161
|
+
var operator = "";
|
162
|
+
if (value.indexOf("-") > -1) {
|
163
|
+
value = value.replace("-", "");
|
164
|
+
operator = "-";
|
165
|
+
}
|
166
|
+
return operator + settings.prefix + value + settings.suffix;
|
167
|
+
}
|
162
168
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
169
|
+
function maskValue(value) {
|
170
|
+
var negative = (value.indexOf("-") > -1 && settings.allowNegative) ? "-" : "",
|
171
|
+
onlyNumbers = value.replace(/[^0-9]/g, ""),
|
172
|
+
integerPart = onlyNumbers.slice(0, onlyNumbers.length - settings.precision),
|
173
|
+
newValue,
|
174
|
+
decimalPart,
|
175
|
+
leadingZeros;
|
176
|
+
|
177
|
+
// remove initial zeros
|
178
|
+
integerPart = integerPart.replace(/^0*/g, "");
|
179
|
+
// put settings.thousands every 3 chars
|
180
|
+
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, settings.thousands);
|
181
|
+
if (integerPart === "") {
|
182
|
+
integerPart = "0";
|
183
|
+
}
|
184
|
+
newValue = negative + integerPart;
|
185
|
+
|
186
|
+
if (settings.precision > 0) {
|
187
|
+
decimalPart = onlyNumbers.slice(onlyNumbers.length - settings.precision);
|
188
|
+
leadingZeros = new Array((settings.precision + 1) - decimalPart.length).join(0);
|
189
|
+
newValue += settings.decimal + leadingZeros + decimalPart;
|
190
|
+
}
|
191
|
+
return setSymbol(newValue);
|
192
|
+
}
|
177
193
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
194
|
+
function maskAndPosition(startPos) {
|
195
|
+
var originalLen = $input.val().length,
|
196
|
+
newLen;
|
197
|
+
$input.val(maskValue($input.val()));
|
198
|
+
newLen = $input.val().length;
|
199
|
+
startPos = startPos - (originalLen - newLen);
|
200
|
+
setCursorPosition(startPos);
|
201
|
+
}
|
185
202
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
startPos = startPos - (originalLen - newLen);
|
191
|
-
setCursorPosition(input, startPos);
|
192
|
-
}
|
203
|
+
function mask() {
|
204
|
+
var value = $input.val();
|
205
|
+
$input.val(maskValue(value));
|
206
|
+
}
|
193
207
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
208
|
+
function changeSign() {
|
209
|
+
var inputValue = $input.val();
|
210
|
+
if (settings.allowNegative) {
|
211
|
+
if (inputValue !== "" && inputValue.charAt(0) === "-") {
|
212
|
+
return inputValue.replace("-", "");
|
213
|
+
} else {
|
214
|
+
return "-" + inputValue;
|
215
|
+
}
|
216
|
+
} else {
|
217
|
+
return inputValue;
|
218
|
+
}
|
219
|
+
}
|
198
220
|
|
199
|
-
|
200
|
-
|
221
|
+
function preventDefault(e) {
|
222
|
+
if (e.preventDefault) { //standard browsers
|
223
|
+
e.preventDefault();
|
224
|
+
} else { // old internet explorer
|
225
|
+
e.returnValue = false;
|
226
|
+
}
|
227
|
+
}
|
201
228
|
|
202
|
-
|
203
|
-
|
204
|
-
|
229
|
+
function keypressEvent(e) {
|
230
|
+
e = e || window.event;
|
231
|
+
var key = e.which || e.charCode || e.keyCode,
|
232
|
+
keyPressedChar,
|
233
|
+
selection,
|
234
|
+
startPos,
|
235
|
+
endPos,
|
236
|
+
value;
|
237
|
+
//added to handle an IE "special" event
|
238
|
+
if (key === undefined) {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
|
242
|
+
// any key except the numbers 0-9
|
243
|
+
if (key < 48 || key > 57) {
|
244
|
+
// -(minus) key
|
245
|
+
if (key === 45) {
|
246
|
+
$input.val(changeSign());
|
247
|
+
return false;
|
248
|
+
// +(plus) key
|
249
|
+
} else if (key === 43) {
|
250
|
+
$input.val($input.val().replace("-", ""));
|
251
|
+
return false;
|
252
|
+
// enter key or tab key
|
253
|
+
} else if (key === 13 || key === 9) {
|
254
|
+
return true;
|
255
|
+
} else if ($.browser.mozilla && (key === 37 || key === 39) && e.charCode === 0) {
|
256
|
+
// needed for left arrow key or right arrow key with firefox
|
257
|
+
// the charCode part is to avoid allowing "%"(e.charCode 0, e.keyCode 37)
|
258
|
+
return true;
|
259
|
+
} else { // any other key with keycode less than 48 and greater than 57
|
260
|
+
preventDefault(e);
|
261
|
+
return true;
|
262
|
+
}
|
263
|
+
} else if (!canInputMoreNumbers()) {
|
264
|
+
return false;
|
265
|
+
} else {
|
266
|
+
preventDefault(e);
|
267
|
+
|
268
|
+
keyPressedChar = String.fromCharCode(key);
|
269
|
+
selection = getInputSelection();
|
270
|
+
startPos = selection.start;
|
271
|
+
endPos = selection.end;
|
272
|
+
value = $input.val();
|
273
|
+
$input.val(value.substring(0, startPos) + keyPressedChar + value.substring(endPos, value.length));
|
274
|
+
maskAndPosition(startPos + 1);
|
275
|
+
return false;
|
276
|
+
}
|
277
|
+
}
|
205
278
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
279
|
+
function keydownEvent(e) {
|
280
|
+
e = e || window.event;
|
281
|
+
var key = e.which || e.charCode || e.keyCode,
|
282
|
+
selection,
|
283
|
+
startPos,
|
284
|
+
endPos,
|
285
|
+
value,
|
286
|
+
lastNumber;
|
287
|
+
//needed to handle an IE "special" event
|
288
|
+
if (key === undefined) {
|
289
|
+
return false;
|
290
|
+
}
|
291
|
+
|
292
|
+
selection = getInputSelection();
|
293
|
+
startPos = selection.start;
|
294
|
+
endPos = selection.end;
|
295
|
+
|
296
|
+
if (key === 8 || key === 46 || key === 63272) { // backspace or delete key (with special case for safari)
|
297
|
+
preventDefault(e);
|
298
|
+
|
299
|
+
value = $input.val();
|
300
|
+
// not a selection
|
301
|
+
if (startPos === endPos) {
|
302
|
+
// backspace
|
303
|
+
if (key === 8) {
|
304
|
+
if (settings.suffix === "") {
|
305
|
+
startPos -= 1;
|
306
|
+
} else {
|
307
|
+
// needed to find the position of the last number to be erased
|
308
|
+
lastNumber = value.split("").reverse().join("").search(/\d/);
|
309
|
+
startPos = value.length - lastNumber - 1;
|
310
|
+
endPos = startPos + 1;
|
311
|
+
}
|
312
|
+
//delete
|
313
|
+
} else {
|
314
|
+
endPos += 1;
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
$input.val(value.substring(0, startPos) + value.substring(endPos, value.length));
|
319
|
+
|
320
|
+
maskAndPosition(startPos);
|
321
|
+
return false;
|
322
|
+
} else if (key === 9) { // tab key
|
323
|
+
return true;
|
324
|
+
} else { // any other key
|
325
|
+
return true;
|
326
|
+
}
|
327
|
+
}
|
240
328
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
329
|
+
function focusEvent() {
|
330
|
+
onFocusValue = $input.val();
|
331
|
+
mask();
|
332
|
+
var input = $input.get(0),
|
333
|
+
textRange;
|
334
|
+
if (input.createTextRange) {
|
335
|
+
textRange = input.createTextRange();
|
336
|
+
textRange.collapse(false); // set the cursor at the end of the input
|
337
|
+
textRange.select();
|
338
|
+
}
|
339
|
+
}
|
245
340
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
operator = '-';
|
252
|
-
}
|
341
|
+
function cutPasteEvent() {
|
342
|
+
setTimeout(function() {
|
343
|
+
mask();
|
344
|
+
}, 0);
|
345
|
+
}
|
253
346
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
return value;
|
259
|
-
}
|
347
|
+
function getDefaultMask() {
|
348
|
+
var n = parseFloat("0") / Math.pow(10, settings.precision);
|
349
|
+
return (n.toFixed(settings.precision)).replace(new RegExp("\\.", "g"), settings.decimal);
|
350
|
+
}
|
260
351
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
352
|
+
function blurEvent(e) {
|
353
|
+
if ($.browser.msie) {
|
354
|
+
keypressEvent(e);
|
355
|
+
}
|
356
|
+
|
357
|
+
if ($input.val() === "" || $input.val() === setSymbol(getDefaultMask())) {
|
358
|
+
if (!settings.allowZero) {
|
359
|
+
$input.val("");
|
360
|
+
} else if (!settings.affixesStay) {
|
361
|
+
$input.val(getDefaultMask());
|
362
|
+
} else {
|
363
|
+
$input.val(setSymbol(getDefaultMask()));
|
364
|
+
}
|
365
|
+
} else {
|
366
|
+
if (!settings.affixesStay) {
|
367
|
+
var newValue = $input.val().replace(settings.prefix, "").replace(settings.suffix, "");
|
368
|
+
$input.val(newValue);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
if ($input.val() !== onFocusValue) {
|
372
|
+
$input.change();
|
373
|
+
}
|
374
|
+
}
|
273
375
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
range.moveEnd('character', pos);
|
284
|
-
range.moveStart('character', pos);
|
285
|
-
range.select();
|
286
|
-
}
|
287
|
-
});
|
288
|
-
return this;
|
289
|
-
};
|
290
|
-
|
291
|
-
function getInputSelection(el) {
|
292
|
-
var start = 0, end = 0, normalizedValue, range, textInputRange, len, endRange;
|
293
|
-
|
294
|
-
if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
|
295
|
-
start = el.selectionStart;
|
296
|
-
end = el.selectionEnd;
|
297
|
-
} else {
|
298
|
-
range = document.selection.createRange();
|
299
|
-
|
300
|
-
if (range && range.parentElement() == el) {
|
301
|
-
len = el.value.length;
|
302
|
-
normalizedValue = el.value.replace(/\r\n/g, "\n");
|
303
|
-
|
304
|
-
// Create a working TextRange that lives only in the input
|
305
|
-
textInputRange = el.createTextRange();
|
306
|
-
textInputRange.moveToBookmark(range.getBookmark());
|
307
|
-
|
308
|
-
// Check if the start and end of the selection are at the very end
|
309
|
-
// of the input, since moveStart/moveEnd doesn't return what we want
|
310
|
-
// in those cases
|
311
|
-
endRange = el.createTextRange();
|
312
|
-
endRange.collapse(false);
|
313
|
-
|
314
|
-
if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
|
315
|
-
start = end = len;
|
316
|
-
} else {
|
317
|
-
start = -textInputRange.moveStart("character", -len);
|
318
|
-
start += normalizedValue.slice(0, start).split("\n").length - 1;
|
319
|
-
|
320
|
-
if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
|
321
|
-
end = len;
|
322
|
-
} else {
|
323
|
-
end = -textInputRange.moveEnd("character", -len);
|
324
|
-
end += normalizedValue.slice(0, end).split("\n").length - 1;
|
376
|
+
function clickEvent() {
|
377
|
+
var input = $input.get(0),
|
378
|
+
length;
|
379
|
+
if (input.setSelectionRange) {
|
380
|
+
length = $input.val().length;
|
381
|
+
input.setSelectionRange(length, length);
|
382
|
+
} else {
|
383
|
+
$input.val($input.val());
|
384
|
+
}
|
325
385
|
}
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
input.unbind('.maskMoney');
|
338
|
-
input.bind('keypress.maskMoney', keypressEvent);
|
339
|
-
input.bind('keydown.maskMoney', keydownEvent);
|
340
|
-
input.bind('blur.maskMoney', blurEvent);
|
341
|
-
input.bind('focus.maskMoney', focusEvent);
|
342
|
-
input.bind('mask.maskMoney', mask);
|
386
|
+
|
387
|
+
$input.unbind(".maskMoney");
|
388
|
+
$input.bind("keypress.maskMoney", keypressEvent);
|
389
|
+
$input.bind("keydown.maskMoney", keydownEvent);
|
390
|
+
$input.bind("blur.maskMoney", blurEvent);
|
391
|
+
$input.bind("focus.maskMoney", focusEvent);
|
392
|
+
$input.bind("click.maskMoney", clickEvent);
|
393
|
+
$input.bind("cut.maskMoney", cutPasteEvent);
|
394
|
+
$input.bind("paste.maskMoney", cutPasteEvent);
|
395
|
+
$input.bind("mask.maskMoney", mask);
|
396
|
+
});
|
343
397
|
}
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
};
|
357
|
-
})(jQuery);
|
398
|
+
};
|
399
|
+
|
400
|
+
$.fn.maskMoney = function (method) {
|
401
|
+
if (methods[method]) {
|
402
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
403
|
+
} else if (typeof method === "object" || ! method) {
|
404
|
+
return methods.init.apply(this, arguments);
|
405
|
+
} else {
|
406
|
+
$.error("Method " + method + " does not exist on jQuery.maskMoney");
|
407
|
+
}
|
408
|
+
};
|
409
|
+
})(window.jQuery || window.Zepto);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maskmoney-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Alexandro Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: jquery.maskMoney for rails.
|
14
14
|
email:
|
@@ -17,7 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
21
21
|
- Gemfile
|
22
22
|
- LICENSE.txt
|
23
23
|
- README.md
|
@@ -34,17 +34,17 @@ require_paths:
|
|
34
34
|
- lib
|
35
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.
|
47
|
+
rubygems_version: 2.2.0
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: jquery.maskMoney for rails.
|