maskmoney-rails 2.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in maskedinput-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Carlos Alexandro Becker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Maskedinput::Rails
2
+
3
+ Gemified assets for [plentz's jquery.maskMoney plugin](http://plentz.github.io/jquery-maskmoney/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'maskmoney-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install maskmoney-rails
18
+
19
+ ## Usage
20
+
21
+ Add to your `application.js`:
22
+
23
+ require maskmoney
24
+
25
+ And use it as the plugin documentation describes.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ module MaskMoney
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "maskmoney-rails"
7
+ gem.version = "2.0.0.1"
8
+ gem.authors = ["Carlos Alexandro Becker"]
9
+ gem.email = ["caarlos0@gmail.com"]
10
+ gem.description = %q{jquery.maskMoney for rails.}
11
+ gem.summary = %q{jquery.maskMoney for rails.}
12
+ gem.homepage = "http://carlosbecker.com"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,357 @@
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
+ }
53
+
54
+ function clearDirt(){
55
+ dirty = false;
56
+ }
57
+
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;
82
+ }
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
+ }
99
+
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
+ }
146
+
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
+ }
162
+
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
+ }
177
+
178
+ function preventDefault(e) {
179
+ if (e.preventDefault) { //standard browsers
180
+ e.preventDefault();
181
+ } else { // internet explorer
182
+ e.returnValue = false
183
+ }
184
+ }
185
+
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
+ }
193
+
194
+ function mask(){
195
+ var value = input.val();
196
+ input.val(maskValue(value));
197
+ }
198
+
199
+ function maskValue(v) {
200
+ v = v.replace(settings.symbol, '');
201
+
202
+ var strCheck = '0123456789';
203
+ var len = v.length;
204
+ var a = '', t = '', neg='';
205
+
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
+ }
240
+
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
+ }
245
+
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
+ }
253
+
254
+ if(value.substr(0, settings.symbol.length) != settings.symbol){
255
+ value = operator + settings.symbol + value;
256
+ }
257
+ }
258
+ return value;
259
+ }
260
+
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
+ }
273
+
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;
325
+ }
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);
343
+ }
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);
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maskmoney-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Alexandro Becker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: jquery.maskMoney for rails.
14
+ email:
15
+ - caarlos0@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/maskmoney-rails.rb
26
+ - maskmoney-rails.gemspec
27
+ - vendor/assets/javascripts/maskmoney.js
28
+ homepage: http://carlosbecker.com
29
+ licenses: []
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.0.0
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: jquery.maskMoney for rails.
51
+ test_files: []