ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

jquery.tree.checkbox.js
Go to the documentation of this file.
1 (function ($) {
2 $.extend($.tree.plugins, {
3 "checkbox" : {
4 defaults : {
5 three_state : true
6 },
7 get_checked : function (t) {
8 if(!t) t = $.tree.focused();
9 return t.container.find("a.checked").parent();
10 },
11 get_undeterminded : function (t) {
12 if(!t) t = $.tree.focused();
13 return t.container.find("a.undetermined").parent();
14 },
15 get_unchecked : function (t) {
16 if(!t) t = $.tree.focused();
17 return t.container.find("a:not(.checked, .undetermined)").parent();
18 },
19
20 check : function (n) {
21 if(!n) return false;
22 var t = $.tree.reference(n);
23 n = t.get_node(n);
24 if(n.children("a").hasClass("checked")) return true;
25
26 var opts = $.extend(true, {}, $.tree.plugins.checkbox.defaults, t.settings.plugins.checkbox);
27 if(opts.three_state) {
28 n.find("li").andSelf().children("a").removeClass("unchecked undetermined").addClass("checked");
29 n.parents("li").each(function () {
30 if($(this).children("ul").find("a:not(.checked):eq(0)").size() > 0) {
31 $(this).parents("li").andSelf().children("a").removeClass("unchecked checked").addClass("undetermined");
32 return false;
33 }
34 else $(this).children("a").removeClass("unchecked undetermined").addClass("checked");
35 });
36 }
37 else n.children("a").removeClass("unchecked").addClass("checked");
38 return true;
39 },
40 uncheck : function (n) {
41 if(!n) return false;
42 var t = $.tree.reference(n);
43 n = t.get_node(n);
44 if(n.children("a").hasClass("unchecked")) return true;
45
46 var opts = $.extend(true, {}, $.tree.plugins.checkbox.defaults, t.settings.plugins.checkbox);
47 if(opts.three_state) {
48 n.find("li").andSelf().children("a").removeClass("checked undetermined").addClass("unchecked");
49 n.parents("li").each(function () {
50 if($(this).find("a.checked, a.undetermined").size() - 1 > 0) {
51 $(this).parents("li").andSelf().children("a").removeClass("unchecked checked").addClass("undetermined");
52 return false;
53 }
54 else $(this).children("a").removeClass("checked undetermined").addClass("unchecked");
55 });
56 }
57 else n.children("a").removeClass("checked").addClass("unchecked");
58 return true;
59 },
60 toggle : function (n) {
61 if(!n) return false;
62 var t = $.tree.reference(n);
63 n = t.get_node(n);
64 if(n.children("a").hasClass("checked")) $.tree.plugins.checkbox.uncheck(n);
65 else $.tree.plugins.checkbox.check(n);
66 },
67
68 callbacks : {
69 onchange : function(n, t) {
70 $.tree.plugins.checkbox.toggle(n);
71 }
72 }
73 }
74 });
75 })(jQuery);