jquery.treeview.edit.js 1.5 KB

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