jquery_numeric_inputs_rails 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b63fd56a9b63cb8f4af503f22e1709a135d0aa8
4
+ data.tar.gz: d592fed6c6fffe4cba1bc785ef70d250388b9e53
5
+ SHA512:
6
+ metadata.gz: d8a1a04ddcd47d67164f3d857662a08d26c04dffbbd43b657ad876cad5035b407efabc291a225c0cd64385db82abd7cd68ab76fe4573a93912e7764453644928
7
+ data.tar.gz: e2bff5c8b044e6ca26195e09b8e9722bcc2572c22e2532ea0bb842815b22ab0cc98cdb894cf3e9599d05d6b0d1219b1189229a56e43370236fbd832d6224ffe9
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery_numeric_inputs_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Marc Pursals
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # JqueryNumericInputsRails
2
+
3
+ This gem is a gemify of the Manuel van Rijn jquery_numeric_inputs pluging. It allows us to set inputs in our forms as only numeric. This gem works with Rails 3, not tested on Rails 4.
4
+
5
+ For more information please check out https://github.com/manuelvanrijn/jquery-numeric_input
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'jquery_numeric_inputs_rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jquery_numeric_inputs_rails
20
+
21
+ ## Usage
22
+
23
+ First of all include this to your Application.js
24
+
25
+ //=require jquery_numeric_inputs_rails
26
+
27
+ (If you are using the power of Asset Pipeline you don't need to)
28
+
29
+ Have fun.
30
+
31
+ More info on: https://github.com/manuelvanrijn/jquery-numeric_input
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/jquery_numeric_inputs_rails/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,133 @@
1
+ /*
2
+ * jQuery Numeric Input - v0.1.3 - 2013-08-27
3
+ * https://github.com/manuelvanrijn/jquery-numeric_input
4
+ * Copyright (c) 2013 Manuel van Rijn
5
+ * Licensed MIT, GPL
6
+ */
7
+
8
+ ;(function( $, window, document, undefined ) {
9
+
10
+ var NumericInput = function( elem, options ) {
11
+ this.elem = elem;
12
+ this.$elem = $(elem);
13
+ this.options = options;
14
+ };
15
+
16
+ NumericInput.prototype = {
17
+
18
+ init: function() {
19
+ // set instance variable
20
+ var _instance = this;
21
+
22
+ _instance.options = $.extend({}, $.fn.numeric_input.defaults, _instance.options);
23
+
24
+ // bind the keypress event
25
+ _instance.$elem.keypress(function( e ) {
26
+ if( _instance.preventDefaultForKeyCode(e.which) === true) {
27
+ e.preventDefault();
28
+ }
29
+ var newValue = _instance.getNewValueForKeyCode( e.which, _instance.$elem.val() );
30
+ if( newValue !== false) {
31
+ _instance.$elem.val( newValue );
32
+ }
33
+ });
34
+
35
+ if( _instance.options.parseOnBlur === true ) {
36
+ // bind the blur event to (re)parse value
37
+ _instance.$elem.blur(function( e ) {
38
+ var parsedValue = _instance.parseValue( _instance.$elem.val() );
39
+ _instance.$elem.val( parsedValue );
40
+ });
41
+ }
42
+
43
+ // initial parse values
44
+ if( _instance.options.initialParse === true ) {
45
+ var parsedValue = _instance.parseValue( _instance.$elem.val() );
46
+ _instance.$elem.val( parsedValue );
47
+ }
48
+
49
+ return _instance;
50
+ },
51
+
52
+ preventDefaultForKeyCode: function( keyCode ) {
53
+ // numeric
54
+ if( keyCode >= 48 && keyCode <= 57) {
55
+ return false;
56
+ }
57
+ // special key's
58
+ switch ( keyCode ) {
59
+ case 0 : // browser specific special key
60
+ case 8 : // backspace
61
+ case 9 : // tab
62
+ case 35 : // end
63
+ case 36 : // home
64
+ case 37 : // left
65
+ case 39 : // right
66
+ case 144 : // num lock
67
+ return false;
68
+ default:
69
+ return true;
70
+ }
71
+ },
72
+
73
+ getNewValueForKeyCode: function( keyCode, currentValue ) {
74
+ // if a comma or a dot is pressed...
75
+ if( keyCode === 44 || keyCode === 46 || keyCode === 188 || keyCode === 190 ) {
76
+ // and we do not have a options.decimal present...
77
+ if( currentValue.indexOf( this.options.decimal ) === -1 ) {
78
+ // append leading zero if currentValue is empty and leadingZeroCheck is active
79
+ if( $.trim(currentValue) === '' && this.options.leadingZeroCheck ) {
80
+ currentValue = '0';
81
+ }
82
+ // append the options.decimal instead of the dot or comma
83
+ return currentValue + this.options.decimal;
84
+ }
85
+ }
86
+ // prepend the minus
87
+ if( keyCode === 45 && this.options.allowNegative ) {
88
+ if( currentValue.charAt(0) !== '-' ) {
89
+ return '-' + currentValue;
90
+ }
91
+ }
92
+ return false;
93
+ },
94
+
95
+ parseValue: function( value ) {
96
+ var minusWasStripped = false;
97
+ var result = value.replace(/[A-Za-z$]/g, '');
98
+ // strip minus and prepend later
99
+ if( result.indexOf('-') !== -1 ) {
100
+ result = result.replace( '-', '' );
101
+ minusWasStripped = true;
102
+ }
103
+ if ( result.indexOf('.') !== -1 || result.indexOf(',') !== -1 ) {
104
+ result = result.replace( '.', this.options.decimal );
105
+ result = result.replace( ',', this.options.decimal );
106
+ }
107
+ if ( result.indexOf( this.options.decimal ) === 0 ) {
108
+ result = '0' + result;
109
+ }
110
+ if ( minusWasStripped === true && this.options.allowNegative === true) {
111
+ result = '-' + result;
112
+ }
113
+ return result;
114
+ }
115
+ };
116
+
117
+ $.fn.numeric_input = function ( options ) {
118
+ return this.each(function () {
119
+ if ( !$.data(this, 'numeric_input') ) {
120
+ $.data( this, 'numeric_input', new NumericInput(this, options).init() );
121
+ }
122
+ });
123
+ };
124
+
125
+ $.fn.numeric_input.defaults = {
126
+ decimal: ',',
127
+ leadingZeroCheck: true,
128
+ initialParse: true,
129
+ parseOnBlur: true,
130
+ allowNegative: false
131
+ };
132
+
133
+ }( jQuery, window, document ));
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery_numeric_inputs_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery_numeric_inputs_rails"
8
+ spec.version = JqueryNumericInputsRails::VERSION
9
+ spec.authors = ["Marc Pursals"]
10
+ spec.email = ["marc@marcpursals.com"]
11
+ spec.summary = %q{This is a gemify of the Manuel van Rijn jqyery plugin that allows us to control inputs to be only numeric}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "railties", "~> 3.1"
25
+ end
@@ -0,0 +1,8 @@
1
+ require "jquery_numeric_inputs_rails/version"
2
+
3
+ module JqueryNumericInputsRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryNumericInputsRails
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_numeric_inputs_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Marc Pursals
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: ''
56
+ email:
57
+ - marc@marcpursals.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - app/assets/javascripts/jquery_numeric_inputs_rails.js
68
+ - jquery_numeric_inputs_rails.gemspec
69
+ - lib/jquery_numeric_inputs_rails.rb
70
+ - lib/jquery_numeric_inputs_rails/version.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: This is a gemify of the Manuel van Rijn jqyery plugin that allows us to control
95
+ inputs to be only numeric
96
+ test_files: []