Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

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

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

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

<div id="container"></div>
              
            
!

CSS

              
                body {
  font-family: sans-serif;
}

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

label { margin-right: 5px; }

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; }

              
            
!

JS

              
                /*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

Console