iugu-ux 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module IuguUX
2
- VERSION = "1.0.11"
2
+ VERSION = "1.0.12"
3
3
  end
@@ -34,6 +34,13 @@ class IuguUI.Money
34
34
 
35
35
  $(@).data "iux.initialized", true
36
36
 
37
+ maskOptions: ->
38
+ if i18n.locale.toLowerCase() == "pt-br"
39
+ {prefix: 'R$', thousands:'.', decimal: ","}
40
+ else
41
+ {prefix: '$', thousands:',', decimal: "."}
42
+
43
+
37
44
  constructor: ( options ) ->
38
45
  @initialize( options )
39
46
 
@@ -54,19 +61,21 @@ class IuguUI.Money
54
61
  class: @input_element.attr "class"
55
62
  )
56
63
 
64
+ @decorator.maskMoney(@maskOptions())
65
+
57
66
  @decorator.insertAfter( @el )
58
67
 
59
68
  that = @
60
69
 
61
70
  @decorator.bind "focus", ->
62
- $(this).val( IuguUI.Money.fromCentsToMoney( that.input_element.val() ) )
71
+ $(this).maskMoney('mask')
63
72
 
64
73
  @decorator.bind "blur", ->
65
- that.input_element.val( IuguUI.Money.fromMoneyToCents( $(this).val() ) )
66
- that.input_element.trigger "change"
67
- $(this).val( IuguUI.Money.fromCentsToMoney( that.input_element.val() ) )
74
+ that.input_element.val($(this).val().replace(/[^0-9]/g, ''))
75
+ that.input_element.trigger('change')
68
76
 
69
- @decorator.val( IuguUI.Money.fromCentsToMoney( that.input_element.val() ) )
77
+ @decorator.val( that.input_element.val() )
78
+ @decorator.maskMoney('mask')
70
79
 
71
80
  @input_element.hide()
72
81
 
@@ -13,6 +13,7 @@
13
13
  //= require ./vendor/jquery.iframe-transport.js
14
14
  //= require ./vendor/jquery.base64.js
15
15
  //= require ./vendor/jquery.fileupload.js
16
+ //= require ./vendor/jquery.maskMoney.js
16
17
  //= require ./vendor/underscore.js
17
18
  //= require ./vendor/backbone.js
18
19
  //= require ./vendor/backbone.associations-min.js
@@ -0,0 +1,409 @@
1
+ /*
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
+ }
18
+
19
+ var methods = {
20
+ destroy : function () {
21
+ $(this).unbind(".maskMoney");
22
+
23
+ if ($.browser.msie) {
24
+ this.onpaste = null;
25
+ }
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
+ }
144
+
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
+ }
159
+
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
+ }
168
+
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
+ }
193
+
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
+ }
202
+
203
+ function mask() {
204
+ var value = $input.val();
205
+ $input.val(maskValue(value));
206
+ }
207
+
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
+ }
220
+
221
+ function preventDefault(e) {
222
+ if (e.preventDefault) { //standard browsers
223
+ e.preventDefault();
224
+ } else { // old internet explorer
225
+ e.returnValue = false;
226
+ }
227
+ }
228
+
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
+ }
278
+
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
+ }
328
+
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
+ }
340
+
341
+ function cutPasteEvent() {
342
+ setTimeout(function() {
343
+ mask();
344
+ }, 0);
345
+ }
346
+
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
+ }
351
+
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
+ }
375
+
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
+ }
385
+ }
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
+ });
397
+ }
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iugu-ux
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
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-02 00:00:00.000000000 Z
12
+ date: 2014-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-script
@@ -304,6 +304,7 @@ files:
304
304
  - vendor/assets/javascripts/vendor/jquery.fileupload.js
305
305
  - vendor/assets/javascripts/vendor/jquery.iframe-transport.js
306
306
  - vendor/assets/javascripts/vendor/jquery.js
307
+ - vendor/assets/javascripts/vendor/jquery.maskMoney.js
307
308
  - vendor/assets/javascripts/vendor/jquery.ui.js
308
309
  - vendor/assets/javascripts/vendor/jquery.ui.js.backup
309
310
  - vendor/assets/javascripts/vendor/jquery.ui.touch-punch.js
@@ -866,7 +867,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
866
867
  version: '0'
867
868
  segments:
868
869
  - 0
869
- hash: 2717946326491822921
870
+ hash: 1565930212086078967
870
871
  required_rubygems_version: !ruby/object:Gem::Requirement
871
872
  none: false
872
873
  requirements:
@@ -875,7 +876,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
875
876
  version: '0'
876
877
  segments:
877
878
  - 0
878
- hash: 2717946326491822921
879
+ hash: 1565930212086078967
879
880
  requirements: []
880
881
  rubyforge_project: iugu-ux
881
882
  rubygems_version: 1.8.24