limitcheckbox 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +75 -0
- data/lib/limitcheckbox.rb +8 -0
- data/lib/limitcheckbox.rb~ +7 -0
- data/lib/limitcheckbox/version.rb +3 -0
- data/vendor/assets/javascripts/limitcheckbox-min.js +1 -0
- data/vendor/assets/javascripts/limitcheckbox.js +28 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a67b344549c1164fcb33534131839c4f633b9f3
|
4
|
+
data.tar.gz: a28dc4a9ce7131d97927cd5a9fa245bce526923d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43a9ac76f638e65abc75d87043c7a9c76a680a27b033df47ba788a16e8f8ba982fcd6fe8650a57569e73ba68e4377a26f081d9ae52bee227f49f9f00ed83a288
|
7
|
+
data.tar.gz: 0bc66d6e9dbbf0073dd2b8326a62f1890f4d70324c044237e3edc268cce2871804d5210c63d41cafd91ecb5e36d30f1a0683ec8bff91136ac638097745f8250a
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
limitcheckbox.js
|
2
|
+
===========
|
3
|
+
|
4
|
+
## Welcome
|
5
|
+
|
6
|
+
This is a jQuery plugin that offers an easy way to setup a limit to a checkbox collection. If you have 5 checkboxes and you want to limit the selection to 3 and leave the other ones disabled, this plugin is going to work for you.
|
7
|
+
|
8
|
+
## Gem Install
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'limitcheckbox'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install limitcheckbox
|
21
|
+
|
22
|
+
Then include **limitcheckbox.js** in your javascript file
|
23
|
+
|
24
|
+
//= require limitcheckbox
|
25
|
+
|
26
|
+
Or include the minified version
|
27
|
+
|
28
|
+
//= require limitcheckbox-min
|
29
|
+
|
30
|
+
|
31
|
+
## Manual Install
|
32
|
+
|
33
|
+
Make sure to include jQuery in your page.
|
34
|
+
|
35
|
+
```html
|
36
|
+
<script src="jquery.min.js"></script>
|
37
|
+
```
|
38
|
+
|
39
|
+
And then include **limitcheckbox.js**. There unminified version it's located at the `src` folder. The minified version its located at the `build` folder.
|
40
|
+
|
41
|
+
```html
|
42
|
+
<script src="js/limitcheckbox-min.js"></script>
|
43
|
+
```
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
5 checkboxes and I want to set a limit of 3.
|
48
|
+
|
49
|
+
```html
|
50
|
+
<div id="checkboxes">
|
51
|
+
<input type="checkbox" /> <!-- 1 -->
|
52
|
+
<input type="checkbox" /> <!-- 2 -->
|
53
|
+
<input type="checkbox" /> <!-- 3 -->
|
54
|
+
<input type="checkbox" /> <!-- 4 -->
|
55
|
+
<input type="checkbox" /> <!-- 5 -->
|
56
|
+
</div>
|
57
|
+
```
|
58
|
+
```javascript
|
59
|
+
$('#checkboxes').limitCheckbox(3);
|
60
|
+
```
|
61
|
+
|
62
|
+
### Callback
|
63
|
+
```javascript
|
64
|
+
$('#checkboxes').limitCheckbox(3, {
|
65
|
+
callback: function() {
|
66
|
+
// Options
|
67
|
+
}
|
68
|
+
);
|
69
|
+
```
|
70
|
+
|
71
|
+
Notice that **limitcheckbox.js** will check the checkboxes from your main element when called in order to disable if they're already *checked*.
|
72
|
+
|
73
|
+
## Demo
|
74
|
+
|
75
|
+
[Click here](http://jsfiddle.net/kinduff/wBZk9/).
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(a){a.fn.limitCheckbox=function(d,c){var b=this.find("input[type=checkbox]");var d=d||b.size()-1,e=a.extend({callback:function(){}},c);b.click(function(){checked=b.filter(":checked").size();if(!a(this).is(":checked")){if(checked<d){b.not(this).removeAttr("disabled")}}else{if(checked==d){b.not(":checked").not(this).attr("disabled","disabled");if(c){c.callback()}}}});checked=b.filter(":checked").size();if(checked==d){b.not(":checked").attr("disabled","disabled")}}}(jQuery));
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* limitCheckbox v0.1 http://kinduff.github.io/limitCheckbox
|
3
|
+
* author: @kinduff
|
4
|
+
*/
|
5
|
+
(function ($) {
|
6
|
+
$.fn.limitCheckbox = function (num, options) {
|
7
|
+
var selector = this.find('input[type=checkbox]');
|
8
|
+
var num = num || selector.size() - 1,
|
9
|
+
settings = $.extend({
|
10
|
+
callback: function() {}
|
11
|
+
}, options);
|
12
|
+
selector.click(function () {
|
13
|
+
checked = selector.filter(':checked').size()
|
14
|
+
if (!$(this).is(':checked')) {
|
15
|
+
if (checked < num) {
|
16
|
+
selector.not(this).removeAttr("disabled");
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
if (checked == num) {
|
20
|
+
selector.not(':checked').not(this).attr("disabled", "disabled");
|
21
|
+
if (options) options.callback();
|
22
|
+
}
|
23
|
+
}
|
24
|
+
});
|
25
|
+
checked = selector.filter(':checked').size();
|
26
|
+
if (checked == num) selector.not(':checked').attr("disabled", "disabled")
|
27
|
+
};
|
28
|
+
}(jQuery));
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: limitcheckbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kinduff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- abarcadabra@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- lib/limitcheckbox.rb
|
64
|
+
- lib/limitcheckbox.rb~
|
65
|
+
- lib/limitcheckbox/version.rb
|
66
|
+
- vendor/assets/javascripts/limitcheckbox-min.js
|
67
|
+
- vendor/assets/javascripts/limitcheckbox.js
|
68
|
+
homepage: https://github.com/kinduff/limitcheckbox/
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Adds jQuery plugin to limit checkbox selection easy.
|
92
|
+
test_files: []
|