Created
February 8, 2012 15:53
-
-
Save gbirke/1770599 to your computer and use it in GitHub Desktop.
jQuery lightweight tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#container li { | |
line-height:18px; | |
} | |
#container li ins { | |
display: inline-block; | |
width:18px; | |
height:18px; | |
text-decoration:none; | |
background-image:url('images/d.png'); // sprite image from jsTree | |
background-repeat:no-repeat; | |
background-position:0px 0px; | |
} | |
#container li ins.open { | |
background-position:-18px 0px; | |
} | |
#container li ins.empty { | |
background-image:none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery('#container li').each(function() { | |
var elem = jQuery(this), | |
has_children = elem.children('ul').length, | |
toggler = '<ins class="'+(has_children ? "closed" : "empty")+'"> </ins>' | |
; | |
elem.prepend(toggler); | |
}); | |
jQuery('#container').on('click', 'ins', function(){ | |
var ins = jQuery(this); | |
ins.toggleClass('open closed'); | |
ins.siblings('ul').toggle(); | |
}); | |
jQuery('#container li ul').hide(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment