This repository was archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckAll.js
68 lines (42 loc) · 1.42 KB
/
checkAll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(function($){
$.checkAll = function(el, options){
var base = this;
base.$el = $(el);
base.el = el;
base.group_identifier = base.$el.data('check-all');
base.$children = $('[data-check-all="' + base.group_identifier + '"').not(base.$el);
base.init = function(){
//***************
// BIND EVENTS
base.$el.on('change.checkAll', function (event) {
console.log(base.group_identifier);
selected_diff = base.$children.length - base.$children.filter(':checked').length;
if ( selected_diff > 0 ) {
base.$el.prop('checked', true);
base.$children.prop('checked', true);
} else {
base.$el.prop('checked', false);
base.$children.prop('checked', false);
}
base.$children.trigger('change');
});
base.$children.on('change.checkAll', function(event) {
selected_diff = base.$children.length - base.$children.filter(':checked').length;
base.$el.prop("indeterminate", false);
if ( selected_diff == 0 || selected_diff == base.$children.length ) {
base.$el.prop('checked', base.$children.first().prop('checked'));
} else {
base.$el.prop("indeterminate", true);
}
});
};
base.init();
};
$.checkAll.defaultOptions = {
};
$.fn.checkAll = function(options){
return this.each(function(){
(new $.checkAll(this, options));
});
};
})(jQuery);