eac_rails_utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +18 -0
  3. data/lib/assets/javascripts/currency_field.js +21 -0
  4. data/lib/assets/javascripts/eac_rails_utils.js +6 -0
  5. data/lib/assets/javascripts/input_searchable.js +78 -0
  6. data/lib/assets/javascripts/jMenu.jquery.min.js +12 -0
  7. data/lib/assets/javascripts/jquery.maskMoney.js +409 -0
  8. data/lib/assets/stylesheets/autocomplete.scss +33 -0
  9. data/lib/assets/stylesheets/bootstrap3-dropdown.scss +47 -0
  10. data/lib/assets/stylesheets/eac_rails_utils.scss +44 -0
  11. data/lib/assets/stylesheets/jmenu.scss +78 -0
  12. data/lib/eac/common_form_helper.rb +37 -0
  13. data/lib/eac/common_form_helper/form_builder.rb +88 -0
  14. data/lib/eac/common_form_helper/form_builder/association_select_field.rb +40 -0
  15. data/lib/eac/common_form_helper/form_builder/common_text_fields.rb +18 -0
  16. data/lib/eac/common_form_helper/form_builder/currency_field.rb +39 -0
  17. data/lib/eac/common_form_helper/form_builder/date_field.rb +20 -0
  18. data/lib/eac/common_form_helper/form_builder/fields_for.rb +44 -0
  19. data/lib/eac/common_form_helper/form_builder/radio_select_field.rb +44 -0
  20. data/lib/eac/common_form_helper/form_builder/searchable_association_field.rb +77 -0
  21. data/lib/eac/cpf_validator.rb +60 -0
  22. data/lib/eac/formatter_helper.rb +27 -0
  23. data/lib/eac/htmlbeautifier.rb +25 -0
  24. data/lib/eac/menus_helper.rb +17 -0
  25. data/lib/eac/menus_helper/bootstrap_gui_builder.rb +90 -0
  26. data/lib/eac/menus_helper/data_builder.rb +57 -0
  27. data/lib/eac/menus_helper/gui_builder.rb +51 -0
  28. data/lib/eac/model.rb +87 -0
  29. data/lib/eac/simple_cache.rb +29 -0
  30. data/lib/eac/source_target_fixtures.rb +51 -0
  31. data/lib/eac_rails_utils.rb +29 -0
  32. data/lib/eac_rails_utils/patches/model_attribute_required.rb +31 -0
  33. data/lib/eac_rails_utils/rails/engine.rb +5 -0
  34. data/lib/eac_rails_utils/version.rb +3 -0
  35. data/test/dummy/Rakefile +6 -0
  36. data/test/dummy/app/models/job.rb +4 -0
  37. data/test/dummy/app/models/user.rb +7 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/config/application.rb +12 -0
  40. data/test/dummy/config/boot.rb +4 -0
  41. data/test/dummy/config/database.yml +5 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/test.rb +42 -0
  44. data/test/dummy/config/routes.rb +8 -0
  45. data/test/dummy/config/secrets.yml +22 -0
  46. data/test/dummy/db/migrate/20160415125333_create_users.rb +9 -0
  47. data/test/dummy/db/migrate/20160415143123_create_jobs.rb +7 -0
  48. data/test/dummy/db/migrate/20160415143229_add_job_to_users.rb +5 -0
  49. data/test/dummy/db/schema.rb +25 -0
  50. data/test/lib/eac/common_form_helper_test.rb +31 -0
  51. data/test/lib/eac/cpf_validator_test.rb +33 -0
  52. data/test/lib/eac/formatter_helper_test.rb +19 -0
  53. data/test/lib/eac/model_test.rb +76 -0
  54. data/test/lib/eac/simple_cache_test.rb +56 -0
  55. data/test/lib/eac_rails_utils/patches/model_attribute_required_test.rb +39 -0
  56. data/test/test_helper.rb +11 -0
  57. metadata +189 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83531ca45814c757bf6ecb89e2142cc1db74fc8a
4
+ data.tar.gz: 39a55f7c96408f0a0b74a8623007d00758c50874
5
+ SHA512:
6
+ metadata.gz: f127ef8d3d6616c4031a9e7afe1b27b260f2ef84eafe76d00eaef38382ef864b73b6aeb6ca9ff80648700a64ff946b6ff38c36012b189b7e1239e6dd11fccbd9
7
+ data.tar.gz: 8b408f5083e55480c1febb2b6377dc36d24964749cb4b2d05ac878f8c13babd7c341f078d2792e1f961549575f8b449874941821e622d0cfb3a99bad148a3db8
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ require 'rake/testtask'
10
+
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+ task default: :test
@@ -0,0 +1,21 @@
1
+ function CurrencyField(hidden_id, visible_id, options) {
2
+ this.hidden_id = hidden_id;
3
+ this.visible_id = visible_id;
4
+ this.options = options;
5
+ var THIS = this;
6
+ $(document).ready(function () {
7
+ THIS.visibleInput().maskMoney(THIS.options);
8
+ THIS.visibleInput().maskMoney('mask', parseFloat(THIS.hiddenInput().val()));
9
+ THIS.visibleInput().change(function () {
10
+ THIS.hiddenInput().val(THIS.visibleInput().maskMoney('unmasked')[0]);
11
+ })
12
+ });
13
+ }
14
+
15
+ CurrencyField.prototype.hiddenInput = function () {
16
+ return $('#' + this.hidden_id);
17
+ }
18
+
19
+ CurrencyField.prototype.visibleInput = function () {
20
+ return $('#' + this.visible_id);
21
+ }
@@ -0,0 +1,6 @@
1
+ //= require jMenu.jquery.min
2
+ //= require bootstrap-sprockets
3
+ //= require input_searchable
4
+ //= require jquery.maskMoney
5
+ //= require currency_field
6
+ //= require nested_form_fields
@@ -0,0 +1,78 @@
1
+ InputSearchable = function (options) {
2
+ var THIS = this;
3
+ this._options = options;
4
+ this._selectedItem = null;
5
+ this._lastSelectedItem = null;
6
+
7
+ $(document).ready(function () {
8
+ THIS._visibleInput().attr('owner', THIS);
9
+
10
+ THIS._visibleInput().autocomplete({
11
+ source: THIS._option('url'),
12
+ delay: 0,
13
+ select: function (event, ui) {
14
+ THIS._setValue(ui.item);
15
+ },
16
+ autoFocus: true
17
+ });
18
+ THIS._visibleInput().on('input', function (event) {
19
+ THIS._checkTextChanged(event);
20
+ });
21
+ THIS._setValue({id: THIS._option('initial_id'), label: THIS._option('initial_label')});
22
+ });
23
+ };
24
+
25
+ InputSearchable.prototype._option = function (key) {
26
+ if (this._options[key] === undefined) {
27
+ throw 'Opção não encontrada: ' + key;
28
+ }
29
+ return this._options[key];
30
+ };
31
+
32
+ InputSearchable.prototype._hiddenInput = function () {
33
+ return this._byId(this._option('hidden_input_id'));
34
+ };
35
+
36
+ InputSearchable.prototype._visibleInput = function () {
37
+ return this._byId(this._option('visible_input_id'));
38
+ };
39
+
40
+ InputSearchable.prototype._byId = function (id) {
41
+ var name = "#" + id;
42
+ if ($(name).length === 0) {
43
+ console.log(name + ' nao existe');
44
+ }
45
+ return $(name);
46
+ };
47
+
48
+ InputSearchable.prototype._applyColor = function () {
49
+ var color = this._hiddenInput().val() ? '#CFC' : '#FCC';
50
+ this._visibleInput().css('background-color', color);
51
+ };
52
+
53
+ InputSearchable.prototype._checkTextChanged = function (event) {
54
+ if (this._selectedItem) {
55
+ if (this._selectedItem.label != this._visibleInput().val()) {
56
+ this._setValue(null);
57
+ }
58
+ }
59
+ if (this._lastSelectedItem) {
60
+ if (this._lastSelectedItem.label == this._visibleInput().val()) {
61
+ this._setValue(this._lastSelectedItem);
62
+ }
63
+ }
64
+ };
65
+
66
+ InputSearchable.prototype._setValue = function (item) {
67
+ if (item) {
68
+ this._hiddenInput().val(item.id);
69
+ this._visibleInput().val(item.label);
70
+ this._selectedItem = item;
71
+ this._lastSelectedItem = this._selectedItem;
72
+ }
73
+ else {
74
+ this._hiddenInput().val(null);
75
+ this._selectedItem = null;
76
+ }
77
+ this._applyColor();
78
+ };
@@ -0,0 +1,12 @@
1
+ /************************************************************************
2
+ *************************************************************************
3
+ @Name : jMenu - jQuery Plugin
4
+ @Revison : 2.0
5
+ @Date : 08/2013
6
+ @Author : ALPIXEL - (www.myjqueryplugins.com - www.alpixel.fr)
7
+ @Support : FF, IE7, IE8, MAC Firefox, MAC Safari
8
+ @License : Open Source - MIT License : http://www.opensource.org/licenses/mit-license.php
9
+
10
+ **************************************************************************
11
+ *************************************************************************/
12
+ (function(e){e.jMenu={defaults:{ulWidth:"auto",absoluteTop:33,absoluteLeft:0,TimeBeforeOpening:100,TimeBeforeClosing:100,animatedText:true,paddingLeft:7,openClick:false,effects:{effectSpeedOpen:150,effectSpeedClose:150,effectTypeOpen:"slide",effectTypeClose:"slide",effectOpen:"swing",effectClose:"swing"}},init:function(t){opts=e.extend({},e.jMenu.defaults,t);if(opts.ulWidth=="auto")$width=e(".fNiv").outerWidth(false);else $width=opts.ulWidth;e(".jMenu li").each(function(){var t=e(this).find("a:first"),n=e(this).find("ul");if(e.jMenu._IsParent(t)){t.addClass("isParent");var r=t.next(),i=t.position();if(e(this).hasClass("jmenu-level-0"))r.css({top:i.top+opts.absoluteTop,left:i.left+opts.absoluteLeft,width:$width});else r.css({top:i.top,left:i.left+$width,width:$width});if(!opts.openClick)e(this).bind({mouseenter:function(){if(e(this).hasClass("jmenu-level-0")){i=e(this).position();r.css({left:i.left+opts.absoluteLeft,top:i.top+opts.absoluteTop})}e.jMenu._show(r)},mouseleave:function(){e.jMenu._closeList(r)}});else e(this).bind({click:function(t){t.preventDefault();e.jMenu._show(r)},mouseleave:function(){e.jMenu._closeList(r)}})}})},_show:function(e){switch(opts.effects.effectTypeOpen){case"slide":e.stop(true,true).delay(opts.TimeBeforeOpening).slideDown(opts.effects.effectSpeedOpen,opts.effects.effectOpen);break;case"fade":e.stop(true,true).delay(opts.TimeBeforeOpening).fadeIn(opts.effects.effectSpeedOpen,opts.effects.effectOpen);break;default:e.stop(true,true).delay(opts.TimeBeforeOpening).show()}},_closeList:function(e){switch(opts.effects.effectTypeClose){case"slide":e.stop(true,true).delay(opts.TimeBeforeClosing).slideUp(opts.effects.effectSpeedClose,opts.effects.effectClose);break;case"fade":e.stop(true,true).delay(opts.TimeBeforeClosing).fadeOut(opts.effects.effectSpeedClose,opts.effects.effectClose);break;default:e.delay(opts.TimeBeforeClosing).hide()}},_animateText:function(t){var n=parseInt(t.css("padding-left"));t.hover(function(){e(this).stop(true,false).animate({paddingLeft:n+opts.paddingLeft},100)},function(){e(this).stop(true,false).animate({paddingLeft:n},100)})},_IsParent:function(e){if(e.next().is("ul"))return true;else return false},_isReadable:function(){if(e(".jmenu-level-0").length>0)return true;else return false},_error:function(){alert("jMenu plugin can't be initialized. Please, check you have the '.jmenu-level-0' class on your first level <li> elements.")}};jQuery.fn.jMenu=function(t){e(this).addClass("jMenu");e(this).children("li").addClass("jmenu-level-0").children("a").addClass("fNiv");if(e.jMenu._isReadable()){e.jMenu.init(t)}else{e.jMenu._error()}}})(jQuery)
@@ -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);