cocoon_limiter 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -5
- data/lib/cocoon_limiter/version.rb +1 -1
- data/vendor/assets/javascripts/cocoon_limiter.js +11 -8
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CocoonLimiter
|
2
2
|
|
3
|
-
Makes it possible to limit the amount of added by cocoon
|
3
|
+
Makes it possible to limit the amount of items added by cocoon.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -50,14 +50,20 @@ after insert or remove items).
|
|
50
50
|
You can decide what the tag will be updated when you change the number
|
51
51
|
of items in the list.
|
52
52
|
|
53
|
-
Just
|
53
|
+
Just add your self '''update_counter''' method.
|
54
54
|
|
55
55
|
``` javascript
|
56
|
-
$('.choose_file').
|
57
|
-
|
58
|
-
|
56
|
+
$('.choose_file').cocoon_limiter({
|
57
|
+
update_counter: function(e, count, cocoon){
|
58
|
+
$('#any_other_widget').text(count);
|
59
|
+
}
|
60
|
+
});
|
59
61
|
```
|
60
62
|
|
63
|
+
## More examples and demos
|
64
|
+
|
65
|
+
[Here](http://cocoon-limiter.herokuapp.com "Cocoon Limiter demo") you can learn more. Soon.
|
66
|
+
|
61
67
|
## Contributing
|
62
68
|
|
63
69
|
1. Fork it
|
@@ -7,7 +7,8 @@
|
|
7
7
|
count: 5,
|
8
8
|
cocoon_counter_name: "cocoon_counter",
|
9
9
|
counter: "[data-counter]",
|
10
|
-
increment_link: ".add_fields"
|
10
|
+
increment_link: ".add_fields",
|
11
|
+
update_counter: null
|
11
12
|
};
|
12
13
|
|
13
14
|
// The actual plugin constructor
|
@@ -54,20 +55,22 @@
|
|
54
55
|
var parent = this.reference;
|
55
56
|
parent.items.push(task);
|
56
57
|
parent.set_visibility();
|
57
|
-
$( this ).trigger('cocoon:changed', [parent.items.length]);
|
58
|
+
$( this ).trigger('cocoon:changed', [parent.items.length, parent]);
|
58
59
|
},
|
59
60
|
decrement_event: function(e, task){
|
60
61
|
var parent = this.reference;
|
61
62
|
parent.items.splice($.inArray(task, parent.items), 1);
|
62
|
-
$( this ).trigger('cocoon:changed', [parent.items.length]);
|
63
|
+
$( this ).trigger('cocoon:changed', [parent.items.length, parent]);
|
63
64
|
parent.set_visibility();
|
64
65
|
}
|
65
66
|
};
|
66
67
|
|
67
|
-
this.update_counter
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
if (!this.options.update_counter) {
|
69
|
+
this.update_counter = function(e, count, reference){
|
70
|
+
var left_count = (this.reference.options.count - count)
|
71
|
+
$( this.reference.counter_widget ).text(left_count);
|
72
|
+
};
|
73
|
+
} else { this.update_counter = this.options.update_counter }
|
71
74
|
|
72
75
|
this.bind_events = function(){
|
73
76
|
$( this.element ).bind('cocoon:after-insert', this.cocoon_events.increment_event)
|
@@ -100,7 +103,7 @@
|
|
100
103
|
this.calc_existing_elements();
|
101
104
|
|
102
105
|
// First
|
103
|
-
$( this.element ).trigger('cocoon:changed', [this.items.length]);
|
106
|
+
$( this.element ).trigger('cocoon:changed', [this.items.length, this]);
|
104
107
|
};
|
105
108
|
|
106
109
|
// A really lightweight plugin wrapper around the constructor,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoon_limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
segments:
|
67
67
|
- 0
|
68
|
-
hash:
|
68
|
+
hash: 821077363
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
segments:
|
76
76
|
- 0
|
77
|
-
hash:
|
77
|
+
hash: 821077363
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project: cocoon_limiter
|
80
80
|
rubygems_version: 1.8.24
|