
Untitled
By: a guest on
Jun 15th, 2012 | syntax:
JavaScript | size: 1.35 KB | hits: 22 | expires: Never
BoxControl = (function() {
var filterBoxes = $(".filter-box", filter),
loopBoxes = function(func) {
filterBoxes.each(function(i) {
var box = $(this),
props = box.find(".properties .property");
func(box, props);
});
};
return {
/*
* Check each propertyType if all or none is properties is selected
* if any of them is true we set an "all selected" state.
*/
renderAllSelected: function() {
loopBoxes(function (box, props) {
var clazz = "all-selected",
allSelected = props.filter(".selected, .dimmed").length === props.length,
noneSelected= props.not(".selected").length === props.length;
if (allSelected || noneSelected) {
box.addClass(clazz);
} else {
box.removeClass(clazz);
}
});
},
/*
* Toggle boxes on init if they have selected properties
* Toggle boxes if all properties are dimmed
*/
toggleBoxes: function(init) {
loopBoxes(function (box, props) {
// On init, toggle boxes that have selected properies
if (props.filter(".selected").length != 0 && init) {
box.find(".toggle-heading").click();
}
// if all properties is dimmed, toggle the box
if (props.length === props.filter(".dimmed").length) {
box.slideUp();
} else {
box.slideDown();
}
});
}
};
}()),