Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 15th, 2012  |  syntax: JavaScript  |  size: 1.35 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. BoxControl      = (function() {
  2.  
  3.         var filterBoxes = $(".filter-box", filter),
  4.                 loopBoxes = function(func) {
  5.  
  6.                         filterBoxes.each(function(i) {
  7.  
  8.                                 var box                 = $(this),
  9.                                         props           = box.find(".properties .property");
  10.  
  11.                                 func(box, props);
  12.  
  13.                         });
  14.         };
  15.  
  16.         return {
  17.                 /*
  18.                 *       Check each propertyType if all or none is properties is selected
  19.                 *       if any of them is true we set an "all selected" state.
  20.                 */
  21.                 renderAllSelected: function() {
  22.  
  23.                         loopBoxes(function (box, props) {
  24.  
  25.                                 var     clazz           = "all-selected",
  26.  
  27.                                         allSelected = props.filter(".selected, .dimmed").length === props.length,
  28.                                         noneSelected= props.not(".selected").length === props.length;
  29.  
  30.                                 if (allSelected || noneSelected) {
  31.                                         box.addClass(clazz);
  32.                                 } else {
  33.                                         box.removeClass(clazz);
  34.                                 }
  35.                         });
  36.  
  37.                 },
  38.  
  39.                 /*
  40.                 * Toggle boxes on init if they have selected properties
  41.                 * Toggle boxes if all properties are dimmed
  42.                 */
  43.                 toggleBoxes: function(init) {
  44.  
  45.                         loopBoxes(function (box, props) {
  46.  
  47.                                 // On init, toggle boxes that have selected properies
  48.                                 if (props.filter(".selected").length != 0 && init) {
  49.                                         box.find(".toggle-heading").click();
  50.                                 }
  51.  
  52.                                 // if all properties is dimmed, toggle the box
  53.                                 if (props.length === props.filter(".dimmed").length) {
  54.                                         box.slideUp();
  55.                                 } else {
  56.                                         box.slideDown();
  57.                                 }
  58.  
  59.                         });
  60.                 }
  61.         };
  62.  
  63. }()),