-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
This really ins't an issue but I wanted to contribute. I found your code but needed to do expand and collapse all. I ended up writing these two functions:
function toggleSingleElement(el){
var children = $(el).parent('li.parent_li').find(' > ul > li');
if (children.is(":visible")) {
children.hide('fast');
$(el).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
} else {
children.show('fast');
$(el).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
}
}
function globalToggle(element, selector){
var addClass;
var removeClass;
var title;
if($(element).find(' > i').hasClass('icon-minus-sign')){
addClass = 'icon-plus-sign';
removeClass = 'icon-minus-sign';
title = 'Expand this branch';
}else{
addClass = 'icon-minus-sign';
removeClass = 'icon-plus-sign';
title = 'Collapse this branch';
}
$(element).attr('title', title).find(' > i').addClass(addClass).removeClass(removeClass);
$(selector).each(function (index, value) {
console.log('span' + index + ':' + $(this).attr('id'));
toggleSingleElement(this);
});
}Then I added the following to my document ready:
$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
$('.tree li.parent_li > span').on('click', function (e) {
toggleSingleElement(this);
e.stopPropagation();
});
$('.app-toggle').on('click', function (e) {
globalToggle(this ,'.app-element');
e.stopPropagation();
});
$('.device-toggle').on('click', function (e) {
globalToggle(this ,'.device-element');
e.stopPropagation();
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels