cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h1>Isotope combination filters with checkboxes 2</h1>

<div id="options">
  <div class="option-set" data-group="brand">
    <input type="checkbox" value=".brand1" id="brand1" /><label for="brand1">brand1</label>
    <input type="checkbox" value=".brand2" id="brand2" /><label for="brand2">brand2</label>
    <input type="checkbox" value=".brand3" id="brand3" /><label for="brand3">brand3</label>
    <input type="checkbox" value=".brand4" id="brand4" /><label for="brand4">brand4</label>
  </div>
  <div class="option-set" data-group="type">
    <input type="checkbox" value=".alpha" id="alpha" /><label for="alpha">alpha</label>
    <input type="checkbox" value=".beta" id="beta" /><label for="type2">beta</label>
    <input type="checkbox" value=".gamma" id="gamma" /><label for="type3">gamma</label>
    <input type="checkbox" value=".delta" id="delta" /><label for="type4">delta</label>
  </div>
  <div class="option-set" data-group="color">
    <input type="checkbox" value=".red" id="red" /><label for="red">red</label>
    <input type="checkbox" value=".blue" id="blue" /><label for="blue">blue</label>
    <input type="checkbox" value=".green" id="green" /><label for="green">green</label>
    <input type="checkbox" value=".yellow" id="yellow" /><label for="yellow">yellow</label>
  </div>
  <div class="option-set" data-group="size">
    <input type="checkbox" value=".size8" id="size8" /><label for="size8">size8</label>
    <input type="checkbox" value=".size9" id="size9" /><label for="size9">size9</label>
    <input type="checkbox" value=".size10" id="size10" /><label for="size10">size10</label>
    <input type="checkbox" value=".size11" id="size11" /><label for="size11">size11</label>
  </div>
</div>

<p id="filter-display"></p>

<div id="container"></div>
            
          
!
            
              body {
  font-family: sans-serif;
}

.item {
  width: 80px;
  height: 80px;
  padding: 5px;
  margin: 5px;
  color: white;
  float: left;
}

p {
  margin: 0;
}

#filter-display {
  font-size: 18px;
  padding: 0.5em;
  border: 1px solid #CCC;
  color: blue;
}

.red { background: red; }
.blue { background: blue; }
.green { background: green; }
.yellow { background: yellow; color: black; }

            
          
!
            
              /*jshint browser:true, undef: true, unused: true, jquery: true */

// store filter per group
var filters = {};

// only used to dynamically generate items
var data = {
  brands: [ 'brand1', 'brand2', 'brand3', 'brand4' ],
  productTypes: [ 'alpha', 'beta', 'gamma', 'delta' ],
  colors: [ 'red', 'blue', 'green', 'yellow' ],
  sizes: [ 'size8', 'size9', 'size10', 'size11' ],
};

var $container = $('#container');

createContent();

var $filterDisplay = $('#filter-display');

$container.isotope();
// do stuff when checkbox change
$('#options').on( 'change', function( event ) {
  var checkbox = event.target;
  var $checkbox = $( checkbox );
  var group = $checkbox.parents('.option-set').attr('data-group');
  // create array for filter group, if not there yet
  var filterGroup = filters[ group ];
  if ( !filterGroup ) {
    filterGroup = filters[ group ] = [];
  }
  // add/remove filter
  if ( checkbox.checked ) {
    // add filter
    filterGroup.push( checkbox.value );
  } else {
    // remove filter
    var index = filterGroup.indexOf( checkbox.value );
    filterGroup.splice( index, 1 );
  }
  
  var comboFilter = getComboFilter();
  $container.isotope({ filter: comboFilter });
  $filterDisplay.text( comboFilter );
});



function getComboFilter() {
  var combo = [];
  for ( var prop in filters ) {
    var group = filters[ prop ];
    if ( !group.length ) {
      // no filters in group, carry on
      continue;
    }
    // add first group
    if ( !combo.length ) {
      combo = group.slice(0);
      continue;
    }
    // add additional groups
    var nextCombo = [];
    // split group into combo: [ A, B ] & [ 1, 2 ] => [ A1, A2, B1, B2 ]
    for ( var i=0; i < combo.length; i++ ) {
      for ( var j=0; j < group.length; j++ ) {
        var item = combo[i] + group[j];
        nextCombo.push( item );
      }
    }
    combo = nextCombo;
  }
  var comboFilter = combo.join(', ');
  return comboFilter;
}


// helper made to make items
function createContent() {
  var brand, productType, color, size;
  var items = '';
  // dynamically create content
  for (var i=0, len1 = data.brands.length; i < len1; i++) {
    brand = data.brands[i];
    for (var j=0, len2 = data.productTypes.length; j < len2; j++) {
      productType = data.productTypes[j];
        for (var l=0, len3 = data.colors.length; l < len3; l++) {
        color = data.colors[l];
        for (var k=0, len4 = data.sizes.length; k < len4; k++) {
          size = data.sizes[k];
          var itemHtml = '<div class="item ' + brand + ' ' +
            productType + ' ' + color + ' ' + size + '">' +
            '<p>' + brand + '</p>' +
            '<p>' + productType + '</p>' +
            '<p>' + size + '</p>' +
            '</div>';
            items += itemHtml;
        }
      }
    }
  }

  $container.append( items );
}

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console