maskmoney-rails 2.0.0.1 → 3.0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: 30c46adabdef13942fdd048722f819b3dd4f6ada
4
- data.tar.gz: 11a565ccf27c925e8631644bd7d74036969ab4f9
5
- !binary "U0hBNTEy":
6
- metadata.gz: ae9f5ce51374f5a9fbb742909b485e6ff02b1361021faba0852a7b70584e8a72a82f2f1a0df58ed956678a4d592fd5469b760ffb90d9e911628980441fb5e794
7
- data.tar.gz: aab8d9d58f35efb0148f8ea5885d5aa1177a6e005f9c1d892bd1889d76eab781188ca1ea83cc1d0c7cee6a9df2c6cb184754b72279aa35c8571ddd0b17cca26d
2
+ SHA1:
3
+ metadata.gz: acf2bf27ba89286a91d4520f5c1233ec48236088
4
+ data.tar.gz: 0d2d3fa86b98e5d81f07485895b1f4d455707664
5
+ SHA512:
6
+ metadata.gz: 131f8f20cda11d7a028573b354c750a33156a9471829b1afc5b58af408e55703281b0b9bbd9e0d3c04b9416708b42848680df379b3fbf45aeabdc99a7f9dd77a
7
+ data.tar.gz: e8cfc0e71cb0ac6821e11855d06245034504f805d814f7c8d5302341a339e54abd898a3aec5d7b1ad6edd1d6d9b5987ff56cb343b6b27465de45bc33ffddf0c1
@@ -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 = "2.0.0.1"
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
- * maskMoney plugin for jQuery
3
- * http://plentz.github.com/jquery-maskmoney/
4
- * version: 2.0.0
5
- * Licensed under the MIT license
6
- */
7
- ;(function($) {
8
- if(!$.browser){
9
- $.browser = {};
10
- $.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
11
- $.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
12
- $.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
13
- $.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
14
- }
15
-
16
- var methods = {
17
- destroy : function(){
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
- function clearDirt(){
55
- dirty = false;
56
- }
19
+ var methods = {
20
+ destroy : function () {
21
+ $(this).unbind(".maskMoney");
57
22
 
58
- function keypressEvent(e) {
59
- e = e || window.event;
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
- } else if (input.val().length >= input.attr('maxlength')) {
84
- return false;
85
- } else {
86
- preventDefault(e);
87
-
88
- var key = String.fromCharCode(k);
89
- var x = input.get(0);
90
- var selection = getInputSelection(x);
91
- var startPos = selection.start;
92
- var endPos = selection.end;
93
- x.value = x.value.substring(0, startPos) + key + x.value.substring(endPos, x.value.length);
94
- maskAndPosition(x, startPos + 1);
95
- markAsDirty();
96
- return false;
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
- function keydownEvent(e) {
101
- e = e||window.event;
102
- var k = e.which;
103
- if (k == undefined) return false; //needed to handle an IE "special" event
104
-
105
- var x = input.get(0);
106
- var selection = getInputSelection(x);
107
- var startPos = selection.start;
108
- var endPos = selection.end;
109
-
110
- if (k==8) { // backspace key
111
- preventDefault(e);
112
-
113
- if(startPos == endPos){
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
- function focusEvent(e) {
148
- var mask = getDefaultMask();
149
- if (input.val() == mask) {
150
- input.val('');
151
- } else if (input.val()=='' && settings.defaultZero) {
152
- input.val(setSymbol(mask));
153
- } else {
154
- input.val(setSymbol(input.val()));
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
- function blurEvent(e) {
164
- if ($.browser.msie) {
165
- keypressEvent(e);
166
- }
167
-
168
- if (input.val() == '' || input.val() == setSymbol(getDefaultMask()) || input.val() == settings.symbol) {
169
- if(!settings.allowZero) input.val('');
170
- else if (!settings.symbolStay) input.val(getDefaultMask());
171
- else input.val(setSymbol(getDefaultMask()));
172
- } else {
173
- if (!settings.symbolStay) input.val(input.val().replace(settings.symbol,''));
174
- else if (settings.symbolStay&&input.val()==settings.symbol) input.val(setSymbol(getDefaultMask()));
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
- function preventDefault(e) {
179
- if (e.preventDefault) { //standard browsers
180
- e.preventDefault();
181
- } else { // internet explorer
182
- e.returnValue = false
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
- function maskAndPosition(x, startPos) {
187
- var originalLen = input.val().length;
188
- input.val(maskValue(x.value));
189
- var newLen = input.val().length;
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
- function mask(){
195
- var value = input.val();
196
- input.val(maskValue(value));
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
- function maskValue(v) {
200
- v = v.replace(settings.symbol, '');
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
- var strCheck = '0123456789';
203
- var len = v.length;
204
- var a = '', t = '', neg='';
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
- if(len != 0 && v.charAt(0)=='-'){
207
- v = v.replace('-','');
208
- if(settings.allowNegative){
209
- neg = '-';
210
- }
211
- }
212
-
213
- if (len==0) {
214
- if (!settings.defaultZero) return t;
215
- t = '0.00';
216
- }
217
-
218
- for (var i = 0; i<len; i++) {
219
- if ((v.charAt(i)!='0') && (v.charAt(i)!=settings.decimal)) break;
220
- }
221
-
222
- for (; i < len; i++) {
223
- if (strCheck.indexOf(v.charAt(i))!=-1) a+= v.charAt(i);
224
- }
225
- var n = parseFloat(a);
226
-
227
- n = isNaN(n) ? 0 : n/Math.pow(10,settings.precision);
228
- t = n.toFixed(settings.precision);
229
-
230
- i = settings.precision == 0 ? 0 : 1;
231
- var p, d = (t=t.split('.'))[i].substr(0,settings.precision);
232
- for (p = (t=t[0]).length; (p-=3)>=1;) {
233
- t = t.substr(0,p)+settings.thousands+t.substr(p);
234
- }
235
-
236
- return (settings.precision>0)
237
- ? setSymbol(neg+t+settings.decimal+d+Array((settings.precision+1)-d.length).join(0))
238
- : setSymbol(neg+t);
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
- function getDefaultMask() {
242
- var n = parseFloat('0')/Math.pow(10,settings.precision);
243
- return (n.toFixed(settings.precision)).replace(new RegExp('\\.','g'),settings.decimal);
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
- function setSymbol(value){
247
- if (settings.showSymbol){
248
- var operator = '';
249
- if(value.length != 0 && value.charAt(0) == '-'){
250
- value = value.replace('-', '');
251
- operator = '-';
252
- }
341
+ function cutPasteEvent() {
342
+ setTimeout(function() {
343
+ mask();
344
+ }, 0);
345
+ }
253
346
 
254
- if(value.substr(0, settings.symbol.length) != settings.symbol){
255
- value = operator + settings.symbol + value;
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
- function changeSign(i){
262
- if (settings.allowNegative) {
263
- var vic = i.val();
264
- if (i.val()!='' && i.val().charAt(0)=='-'){
265
- return i.val().replace('-','');
266
- } else{
267
- return '-'+i.val();
268
- }
269
- } else {
270
- return i.val();
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
- function setCursorPosition(input, pos) {
275
- // I'm not sure if we need to jqueryfy input
276
- $(input).each(function(index, elem) {
277
- if (elem.setSelectionRange) {
278
- elem.focus();
279
- elem.setSelectionRange(pos, pos);
280
- } else if (elem.createTextRange) {
281
- var range = elem.createTextRange();
282
- range.collapse(true);
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
- return {
331
- start: start,
332
- end: end
333
- };
334
- } // getInputSelection
335
-
336
- if (!input.attr("readonly")){
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
- $.fn.maskMoney = function(method) {
349
- if ( methods[method] ) {
350
- return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
351
- } else if ( typeof method === 'object' || ! method ) {
352
- return methods.init.apply( this, arguments );
353
- } else {
354
- $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
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: 2.0.0.1
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: 2013-04-11 00:00:00.000000000 Z
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.0.0
47
+ rubygems_version: 2.2.0
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: jquery.maskMoney for rails.