author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 18 May 2015 16:36:26 +0200 | |
changeset 10438 | f27a489994e8 |
parent 10100 | 6718c03f8938 |
permissions | -rw-r--r-- |
10100
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
/* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
* Treeview 1.5pre - jQuery plugin to hide and show branches of a tree |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 |
* http://bassistance.de/jquery-plugins/jquery-plugin-treeview/ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
* http://docs.jquery.com/Plugins/Treeview |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 |
* |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
* Copyright 2010 Jörn Zaefferer |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
8 |
* Released under the MIT license: |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 |
* http://www.opensource.org/licenses/mit-license.php |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
*/ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
;(function($) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
// TODO rewrite as a widget, removing all the extra plugins |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
$.extend($.fn, { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
swapClass: function(c1, c2) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 |
var c1Elements = this.filter('.' + c1); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 |
this.filter('.' + c2).removeClass(c2).addClass(c1); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 |
c1Elements.removeClass(c1).addClass(c2); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
return this; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
replaceClass: function(c1, c2) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
return this.filter('.' + c1).removeClass(c1).addClass(c2).end(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
hoverClass: function(className) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
className = className || "hover"; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
return this.hover(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
$(this).addClass(className); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
29 |
}, function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
30 |
$(this).removeClass(className); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 |
heightToggle: function(animated, callback) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
34 |
animated ? |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
35 |
this.animate({ height: "toggle" }, animated, callback) : |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 |
this.each(function(){ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 |
jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ](); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 |
if(callback) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 |
callback.apply(this, arguments); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 |
heightHide: function(animated, callback) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 |
if (animated) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
44 |
this.animate({ height: "hide" }, animated, callback); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
45 |
} else { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
46 |
this.hide(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
47 |
if (callback) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
48 |
this.each(callback); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
49 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
50 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
51 |
prepareBranches: function(settings) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
52 |
if (!settings.prerendered) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
53 |
// mark last tree items |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
54 |
this.filter(":last-child:not(ul)").addClass(CLASSES.last); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
55 |
// collapse whole tree, or only those marked as closed, anyway except those marked as open |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
56 |
this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
57 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 |
// return all items with sublists |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 |
return this.filter(":has(>ul)"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
applyClasses: function(settings, toggler) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
62 |
// TODO use event delegation |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
63 |
this.filter(":has(>ul):not(:has(>a))").find(">span").unbind("click.treeview").bind("click.treeview", function(event) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
64 |
// don't handle click events on children, eg. checkboxes |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
65 |
if ( this == event.target ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
66 |
toggler.apply($(this).next()); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
67 |
}).add( $("a", this) ).hoverClass(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
68 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
69 |
if (!settings.prerendered) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
70 |
// handle closed ones first |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
71 |
this.filter(":has(>ul:hidden)") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
72 |
.addClass(CLASSES.expandable) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
73 |
.replaceClass(CLASSES.last, CLASSES.lastExpandable); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
74 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
75 |
// handle open ones |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
76 |
this.not(":has(>ul:hidden)") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
77 |
.addClass(CLASSES.collapsable) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
78 |
.replaceClass(CLASSES.last, CLASSES.lastCollapsable); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
79 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
80 |
// create hitarea if not present |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
81 |
var hitarea = this.find("div." + CLASSES.hitarea); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
82 |
if (!hitarea.length) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
83 |
hitarea = this.prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
84 |
hitarea.removeClass().addClass(CLASSES.hitarea).each(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
85 |
var classes = ""; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
86 |
$.each($(this).parent().attr("class").split(" "), function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
87 |
classes += this + "-hitarea "; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
88 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
89 |
$(this).addClass( classes ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
90 |
}) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
91 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
92 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
93 |
// apply event to hitarea |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
94 |
this.find("div." + CLASSES.hitarea).click( toggler ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
95 |
}, |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
96 |
treeview: function(settings) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
97 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
98 |
settings = $.extend({ |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
99 |
cookieId: "treeview" |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
100 |
}, settings); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
101 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
102 |
if ( settings.toggle ) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
103 |
var callback = settings.toggle; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
104 |
settings.toggle = function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
105 |
return callback.apply($(this).parent()[0], arguments); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
106 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
107 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
108 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
109 |
// factory for treecontroller |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
110 |
function treeController(tree, control) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
111 |
// factory for click handlers |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
112 |
function handler(filter) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
113 |
return function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
114 |
// reuse toggle event handler, applying the elements to toggle |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
115 |
// start searching for all hitareas |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
116 |
toggler.apply( $("div." + CLASSES.hitarea, tree).filter(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
117 |
// for plain toggle, no filter is provided, otherwise we need to check the parent element |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
118 |
return filter ? $(this).parent("." + filter).length : true; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
119 |
}) ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
120 |
return false; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
121 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
122 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
123 |
// click on first element to collapse tree |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
124 |
$("a:eq(0)", control).click( handler(CLASSES.collapsable) ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
125 |
// click on second to expand tree |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
126 |
$("a:eq(1)", control).click( handler(CLASSES.expandable) ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
127 |
// click on third to toggle tree |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
128 |
$("a:eq(2)", control).click( handler() ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
129 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
130 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
131 |
// handle toggle event |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
132 |
function toggler() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
133 |
$(this) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
134 |
.parent() |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
135 |
// swap classes for hitarea |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
136 |
.find(">.hitarea") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
137 |
.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
138 |
.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
139 |
.end() |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
140 |
// swap classes for parent li |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
141 |
.swapClass( CLASSES.collapsable, CLASSES.expandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
142 |
.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
143 |
// find child lists |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
144 |
.find( ">ul" ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
145 |
// toggle them |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
146 |
.heightToggle( settings.animated, settings.toggle ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
147 |
if ( settings.unique ) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
148 |
$(this).parent() |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
149 |
.siblings() |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
150 |
// swap classes for hitarea |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
151 |
.find(">.hitarea") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
152 |
.replaceClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
153 |
.replaceClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
154 |
.end() |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
155 |
.replaceClass( CLASSES.collapsable, CLASSES.expandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
156 |
.replaceClass( CLASSES.lastCollapsable, CLASSES.lastExpandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
157 |
.find( ">ul" ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
158 |
.heightHide( settings.animated, settings.toggle ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
159 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
160 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
161 |
this.data("toggler", toggler); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
162 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
163 |
function serialize() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
164 |
function binary(arg) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
165 |
return arg ? 1 : 0; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
166 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
167 |
var data = []; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
168 |
branches.each(function(i, e) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
169 |
data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
170 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
171 |
$.cookie(settings.cookieId, data.join(""), settings.cookieOptions ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
172 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
173 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
174 |
function deserialize() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
175 |
var stored = $.cookie(settings.cookieId); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
176 |
if ( stored ) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
177 |
var data = stored.split(""); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
178 |
branches.each(function(i, e) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
179 |
$(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide" ](); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
180 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
181 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
182 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
183 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
184 |
// add treeview class to activate styles |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
185 |
this.addClass("treeview"); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
186 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
187 |
// prepare branches and find all tree items with child lists |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
188 |
var branches = this.find("li").prepareBranches(settings); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
189 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
190 |
switch(settings.persist) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
191 |
case "cookie": |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
192 |
var toggleCallback = settings.toggle; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
193 |
settings.toggle = function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
194 |
serialize(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
195 |
if (toggleCallback) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
196 |
toggleCallback.apply(this, arguments); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
197 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
198 |
}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
199 |
deserialize(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
200 |
break; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
201 |
case "location": |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
202 |
var current = this.find("a").filter(function() { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
203 |
return location.href.toLowerCase().indexOf(this.href.toLowerCase()) == 0; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
204 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
205 |
if ( current.length ) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
206 |
// TODO update the open/closed classes |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
207 |
var items = current.addClass("selected").parents("ul, li").add( current.next() ).show(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
208 |
if (settings.prerendered) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
209 |
// if prerendered is on, replicate the basic class swapping |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
210 |
items.filter("li") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
211 |
.swapClass( CLASSES.collapsable, CLASSES.expandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
212 |
.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
213 |
.find(">.hitarea") |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
214 |
.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea ) |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
215 |
.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea ); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
216 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
217 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
218 |
break; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
219 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
220 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
221 |
branches.applyClasses(settings, toggler); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
222 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
223 |
// if control option is set, create the treecontroller and show it |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
224 |
if ( settings.control ) { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
225 |
treeController(this, settings.control); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
226 |
$(settings.control).show(); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
227 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
228 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
229 |
return this; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
230 |
} |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
231 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
232 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
233 |
// classes used by the plugin |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
234 |
// need to be styled via external stylesheet, see first example |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
235 |
$.treeview = {}; |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
236 |
var CLASSES = ($.treeview.classes = { |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
237 |
open: "open", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
238 |
closed: "closed", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
239 |
expandable: "expandable", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
240 |
expandableHitarea: "expandable-hitarea", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
241 |
lastExpandableHitarea: "lastExpandable-hitarea", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
242 |
collapsable: "collapsable", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
243 |
collapsableHitarea: "collapsable-hitarea", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
244 |
lastCollapsableHitarea: "lastCollapsable-hitarea", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
245 |
lastCollapsable: "lastCollapsable", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
246 |
lastExpandable: "lastExpandable", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
247 |
last: "last", |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
248 |
hitarea: "hitarea" |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
249 |
}); |
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
250 |
|
6718c03f8938
[web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
251 |
})(jQuery); |