1 | /* https://github.com/jzaefferer/jquery-treeview/blob/1.4.2/jquery.treeview.edit.js */ |
---|---|
2 | /* License: MIT. */ |
3 | (function($) { |
4 | var CLASSES = $.treeview.classes; |
5 | var proxied = $.fn.treeview; |
6 | $.fn.treeview = function(settings) { |
7 | settings = $.extend({}, settings); |
8 | if (settings.add) { |
9 | return this.trigger("add", [settings.add]); |
10 | } |
11 | if (settings.remove) { |
12 | return this.trigger("remove", [settings.remove]); |
13 | } |
14 | return proxied.apply(this, arguments).bind("add", function(event, branches) { |
15 | $(branches).prev() |
16 | .removeClass(CLASSES.last) |
17 | .removeClass(CLASSES.lastCollapsable) |
18 | .removeClass(CLASSES.lastExpandable) |
19 | .find(">.hitarea") |
20 | .removeClass(CLASSES.lastCollapsableHitarea) |
21 | .removeClass(CLASSES.lastExpandableHitarea); |
22 | $(branches).find("li").andSelf().prepareBranches(settings).applyClasses(settings, $(this).data("toggler")); |
23 | }).bind("remove", function(event, branches) { |
24 | var prev = $(branches).prev(); |
25 | var parent = $(branches).parent(); |
26 | $(branches).remove(); |
27 | prev.filter(":last-child").addClass(CLASSES.last) |
28 | .filter("." + CLASSES.expandable).replaceClass(CLASSES.last, CLASSES.lastExpandable).end() |
29 | .find(">.hitarea").replaceClass(CLASSES.expandableHitarea, CLASSES.lastExpandableHitarea).end() |
30 | .filter("." + CLASSES.collapsable).replaceClass(CLASSES.last, CLASSES.lastCollapsable).end() |
31 | .find(">.hitarea").replaceClass(CLASSES.collapsableHitarea, CLASSES.lastCollapsableHitarea); |
32 | if (parent.is(":not(:has(>))") && parent[0] != this) { |
33 | parent.parent().removeClass(CLASSES.collapsable).removeClass(CLASSES.expandable) |
34 | parent.siblings(".hitarea").andSelf().remove(); |
35 | } |
36 | }); |
37 | }; |
38 | |
39 | })(jQuery); |
40 |
Members