masked_input-rails 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.
@@ -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 masked_input_plugin_rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rafael Macedo
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,29 @@
1
+ # MaskedInputRails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'masked_input-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install masked_input-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require "masked_input-rails/rails"
@@ -0,0 +1,7 @@
1
+ require 'masked_input/rails/engine'
2
+
3
+ module MaskedInput
4
+ module Rails
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module MaskedInput
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module MaskedInput
2
+ module Rails
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 2
6
+ PATCH = 0
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/masked_input/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rafael Macedo"]
6
+ gem.email = ["macedo.rafaelfernandes@gmail.com"]
7
+ gem.description = "Easy way to use input masked plugin on rails"
8
+ gem.summary = gem.description
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "masked_input-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MaskedInput::Rails::Version::STRING
17
+
18
+ gem.add_dependency "railties", "~> 3.1"
19
+ end
@@ -0,0 +1,258 @@
1
+ /*
2
+ Masked Input plugin for jQuery
3
+ Copyright (c) 2007-2011 Josh Bush (digitalbush.com)
4
+ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
5
+ Version: 1.3
6
+ */
7
+ (function($) {
8
+ var pasteEventName = ($.browser.msie ? 'paste' : 'input') + ".mask";
9
+ var iPhone = (window.orientation != undefined);
10
+
11
+ $.mask = {
12
+ //Predefined character definitions
13
+ definitions: {
14
+ '9': "[0-9]",
15
+ 'a': "[A-Za-z]",
16
+ '*': "[A-Za-z0-9]"
17
+ },
18
+ dataName:"rawMaskFn"
19
+ };
20
+
21
+ $.fn.extend({
22
+ //Helper Function for Caret positioning
23
+ caret: function(begin, end) {
24
+ if (this.length == 0) return;
25
+ if (typeof begin == 'number') {
26
+ end = (typeof end == 'number') ? end : begin;
27
+ return this.each(function() {
28
+ if (this.setSelectionRange) {
29
+ this.setSelectionRange(begin, end);
30
+ } else if (this.createTextRange) {
31
+ var range = this.createTextRange();
32
+ range.collapse(true);
33
+ range.moveEnd('character', end);
34
+ range.moveStart('character', begin);
35
+ range.select();
36
+ }
37
+ });
38
+ } else {
39
+ if (this[0].setSelectionRange) {
40
+ begin = this[0].selectionStart;
41
+ end = this[0].selectionEnd;
42
+ } else if (document.selection && document.selection.createRange) {
43
+ var range = document.selection.createRange();
44
+ begin = 0 - range.duplicate().moveStart('character', -100000);
45
+ end = begin + range.text.length;
46
+ }
47
+ return { begin: begin, end: end };
48
+ }
49
+ },
50
+ unmask: function() { return this.trigger("unmask"); },
51
+ mask: function(mask, settings) {
52
+ if (!mask && this.length > 0) {
53
+ var input = $(this[0]);
54
+ return input.data($.mask.dataName)();
55
+ }
56
+ settings = $.extend({
57
+ placeholder: "_",
58
+ completed: null
59
+ }, settings);
60
+
61
+ var defs = $.mask.definitions;
62
+ var tests = [];
63
+ var partialPosition = mask.length;
64
+ var firstNonMaskPos = null;
65
+ var len = mask.length;
66
+
67
+ $.each(mask.split(""), function(i, c) {
68
+ if (c == '?') {
69
+ len--;
70
+ partialPosition = i;
71
+ } else if (defs[c]) {
72
+ tests.push(new RegExp(defs[c]));
73
+ if(firstNonMaskPos==null)
74
+ firstNonMaskPos = tests.length - 1;
75
+ } else {
76
+ tests.push(null);
77
+ }
78
+ });
79
+
80
+ return this.trigger("unmask").each(function() {
81
+ var input = $(this);
82
+ var buffer = $.map(mask.split(""), function(c, i) { if (c != '?') return defs[c] ? settings.placeholder : c });
83
+ var focusText = input.val();
84
+
85
+ function seekNext(pos) {
86
+ while (++pos <= len && !tests[pos]);
87
+ return pos;
88
+ };
89
+ function seekPrev(pos) {
90
+ while (--pos >= 0 && !tests[pos]);
91
+ return pos;
92
+ };
93
+
94
+ function shiftL(begin,end) {
95
+ if(begin<0)
96
+ return;
97
+ for (var i = begin,j = seekNext(end); i < len; i++) {
98
+ if (tests[i]) {
99
+ if (j < len && tests[i].test(buffer[j])) {
100
+ buffer[i] = buffer[j];
101
+ buffer[j] = settings.placeholder;
102
+ } else
103
+ break;
104
+ j = seekNext(j);
105
+ }
106
+ }
107
+ writeBuffer();
108
+ input.caret(Math.max(firstNonMaskPos, begin));
109
+ };
110
+
111
+ function shiftR(pos) {
112
+ for (var i = pos, c = settings.placeholder; i < len; i++) {
113
+ if (tests[i]) {
114
+ var j = seekNext(i);
115
+ var t = buffer[i];
116
+ buffer[i] = c;
117
+ if (j < len && tests[j].test(t))
118
+ c = t;
119
+ else
120
+ break;
121
+ }
122
+ }
123
+ };
124
+
125
+ function keydownEvent(e) {
126
+ var k=e.which;
127
+
128
+ //backspace, delete, and escape get special treatment
129
+ if(k == 8 || k == 46 || (iPhone && k == 127)){
130
+ var pos = input.caret(),
131
+ begin = pos.begin,
132
+ end = pos.end;
133
+
134
+ if(end-begin==0){
135
+ begin=k!=46?seekPrev(begin):(end=seekNext(begin-1));
136
+ end=k==46?seekNext(end):end;
137
+ }
138
+ clearBuffer(begin, end);
139
+ shiftL(begin,end-1);
140
+
141
+ return false;
142
+ } else if (k == 27) {//escape
143
+ input.val(focusText);
144
+ input.caret(0, checkVal());
145
+ return false;
146
+ }
147
+ };
148
+
149
+ function keypressEvent(e) {
150
+ var k = e.which,
151
+ pos = input.caret();
152
+ if (e.ctrlKey || e.altKey || e.metaKey || k<32) {//Ignore
153
+ return true;
154
+ } else if (k) {
155
+ if(pos.end-pos.begin!=0){
156
+ clearBuffer(pos.begin, pos.end);
157
+ shiftL(pos.begin, pos.end-1);
158
+ }
159
+
160
+ var p = seekNext(pos.begin - 1);
161
+ if (p < len) {
162
+ var c = String.fromCharCode(k);
163
+ if (tests[p].test(c)) {
164
+ shiftR(p);
165
+ buffer[p] = c;
166
+ writeBuffer();
167
+ var next = seekNext(p);
168
+ input.caret(next);
169
+ if (settings.completed && next >= len)
170
+ settings.completed.call(input);
171
+ }
172
+ }
173
+ return false;
174
+ }
175
+ };
176
+
177
+ function clearBuffer(start, end) {
178
+ for (var i = start; i < end && i < len; i++) {
179
+ if (tests[i])
180
+ buffer[i] = settings.placeholder;
181
+ }
182
+ };
183
+
184
+ function writeBuffer() { return input.val(buffer.join('')).val(); };
185
+
186
+ function checkVal(allow) {
187
+ //try to place characters where they belong
188
+ var test = input.val();
189
+ var lastMatch = -1;
190
+ for (var i = 0, pos = 0; i < len; i++) {
191
+ if (tests[i]) {
192
+ buffer[i] = settings.placeholder;
193
+ while (pos++ < test.length) {
194
+ var c = test.charAt(pos - 1);
195
+ if (tests[i].test(c)) {
196
+ buffer[i] = c;
197
+ lastMatch = i;
198
+ break;
199
+ }
200
+ }
201
+ if (pos > test.length)
202
+ break;
203
+ } else if (buffer[i] == test.charAt(pos) && i!=partialPosition) {
204
+ pos++;
205
+ lastMatch = i;
206
+ }
207
+ }
208
+ if (!allow && lastMatch + 1 < partialPosition) {
209
+ input.val("");
210
+ clearBuffer(0, len);
211
+ } else if (allow || lastMatch + 1 >= partialPosition) {
212
+ writeBuffer();
213
+ if (!allow) input.val(input.val().substring(0, lastMatch + 1));
214
+ }
215
+ return (partialPosition ? i : firstNonMaskPos);
216
+ };
217
+
218
+ input.data($.mask.dataName,function(){
219
+ return $.map(buffer, function(c, i) {
220
+ return tests[i]&&c!=settings.placeholder ? c : null;
221
+ }).join('');
222
+ })
223
+
224
+ if (!input.attr("readonly"))
225
+ input
226
+ .one("unmask", function() {
227
+ input
228
+ .unbind(".mask")
229
+ .removeData($.mask.dataName);
230
+ })
231
+ .bind("focus.mask", function() {
232
+ focusText = input.val();
233
+ var pos = checkVal();
234
+ writeBuffer();
235
+ var moveCaret=function(){
236
+ if (pos == mask.length)
237
+ input.caret(0, pos);
238
+ else
239
+ input.caret(pos);
240
+ };
241
+ ($.browser.msie ? moveCaret:function(){setTimeout(moveCaret,0)})();
242
+ })
243
+ .bind("blur.mask", function() {
244
+ checkVal();
245
+ if (input.val() != focusText)
246
+ input.change();
247
+ })
248
+ .bind("keydown.mask", keydownEvent)
249
+ .bind("keypress.mask", keypressEvent)
250
+ .bind(pasteEventName, function() {
251
+ setTimeout(function() { input.caret(checkVal(true)); }, 0);
252
+ });
253
+
254
+ checkVal(); //Perform initial check for existing values
255
+ });
256
+ }
257
+ });
258
+ })(jQuery);
@@ -0,0 +1,7 @@
1
+ /*
2
+ Masked Input plugin for jQuery
3
+ Copyright (c) 2007-2011 Josh Bush (digitalbush.com)
4
+ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
5
+ Version: 1.3
6
+ */
7
+ (function(a){var b=(a.browser.msie?"paste":"input")+".mask",c=window.orientation!=undefined;a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},dataName:"rawMaskFn"},a.fn.extend({caret:function(a,b){if(this.length!=0){if(typeof a=="number"){b=typeof b=="number"?b:a;return this.each(function(){if(this.setSelectionRange)this.setSelectionRange(a,b);else if(this.createTextRange){var c=this.createTextRange();c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select()}})}if(this[0].setSelectionRange)a=this[0].selectionStart,b=this[0].selectionEnd;else if(document.selection&&document.selection.createRange){var c=document.selection.createRange();a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length}return{begin:a,end:b}}},unmask:function(){return this.trigger("unmask")},mask:function(d,e){if(!d&&this.length>0){var f=a(this[0]);return f.data(a.mask.dataName)()}e=a.extend({placeholder:"_",completed:null},e);var g=a.mask.definitions,h=[],i=d.length,j=null,k=d.length;a.each(d.split(""),function(a,b){b=="?"?(k--,i=a):g[b]?(h.push(new RegExp(g[b])),j==null&&(j=h.length-1)):h.push(null)});return this.trigger("unmask").each(function(){function v(a){var b=f.val(),c=-1;for(var d=0,g=0;d<k;d++)if(h[d]){l[d]=e.placeholder;while(g++<b.length){var m=b.charAt(g-1);if(h[d].test(m)){l[d]=m,c=d;break}}if(g>b.length)break}else l[d]==b.charAt(g)&&d!=i&&(g++,c=d);if(!a&&c+1<i)f.val(""),t(0,k);else if(a||c+1>=i)u(),a||f.val(f.val().substring(0,c+1));return i?d:j}function u(){return f.val(l.join("")).val()}function t(a,b){for(var c=a;c<b&&c<k;c++)h[c]&&(l[c]=e.placeholder)}function s(a){var b=a.which,c=f.caret();if(a.ctrlKey||a.altKey||a.metaKey||b<32)return!0;if(b){c.end-c.begin!=0&&(t(c.begin,c.end),p(c.begin,c.end-1));var d=n(c.begin-1);if(d<k){var g=String.fromCharCode(b);if(h[d].test(g)){q(d),l[d]=g,u();var i=n(d);f.caret(i),e.completed&&i>=k&&e.completed.call(f)}}return!1}}function r(a){var b=a.which;if(b==8||b==46||c&&b==127){var d=f.caret(),e=d.begin,g=d.end;g-e==0&&(e=b!=46?o(e):g=n(e-1),g=b==46?n(g):g),t(e,g),p(e,g-1);return!1}if(b==27){f.val(m),f.caret(0,v());return!1}}function q(a){for(var b=a,c=e.placeholder;b<k;b++)if(h[b]){var d=n(b),f=l[b];l[b]=c;if(d<k&&h[d].test(f))c=f;else break}}function p(a,b){if(!(a<0)){for(var c=a,d=n(b);c<k;c++)if(h[c]){if(d<k&&h[c].test(l[d]))l[c]=l[d],l[d]=e.placeholder;else break;d=n(d)}u(),f.caret(Math.max(j,a))}}function o(a){while(--a>=0&&!h[a]);return a}function n(a){while(++a<=k&&!h[a]);return a}var f=a(this),l=a.map(d.split(""),function(a,b){if(a!="?")return g[a]?e.placeholder:a}),m=f.val();f.data(a.mask.dataName,function(){return a.map(l,function(a,b){return h[b]&&a!=e.placeholder?a:null}).join("")}),f.attr("readonly")||f.one("unmask",function(){f.unbind(".mask").removeData(a.mask.dataName)}).bind("focus.mask",function(){m=f.val();var b=v();u();var c=function(){b==d.length?f.caret(0,b):f.caret(b)};(a.browser.msie?c:function(){setTimeout(c,0)})()}).bind("blur.mask",function(){v(),f.val()!=m&&f.change()}).bind("keydown.mask",r).bind("keypress.mask",s).bind(b,function(){setTimeout(function(){f.caret(v(!0))},0)}),v()})}})})(jQuery)
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: masked_input-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rafael Macedo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: Easy way to use input masked plugin on rails
31
+ email:
32
+ - macedo.rafaelfernandes@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/masked_input-rails.rb
43
+ - lib/masked_input/rails.rb
44
+ - lib/masked_input/rails/engine.rb
45
+ - lib/masked_input/rails/version.rb
46
+ - masked_input-rails.gemspec
47
+ - vendor/assets/javascripts/jquery.maskedinput-1.3.js
48
+ - vendor/assets/javascripts/jquery.maskedinput-1.3.min.js
49
+ homepage: ''
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.21
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Easy way to use input masked plugin on rails
73
+ test_files: []