Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions multipleFilterMasonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$.fn.multipleFilterMasonry = function(options){
var cache=[];
var filters = [];
// layoutComplete is true for the first filter change
var layoutComplete = true;

if(options.selectorType === 'list') {
$(options.filtersGroupSelector).children().each(function() {
Expand All @@ -15,7 +17,11 @@
$container.find(options.itemSelector).each(function(){
cache.push($(this));
});
$container.masonry(options);
$container
.masonry(options)
.on("layoutComplete", function () {
layoutComplete = true;
});
};

//filter items in cache
Expand Down Expand Up @@ -52,34 +58,42 @@
var proc = function($container){
$(options.filtersGroupSelector).find('input[type=checkbox]').each(function(){
$(this).change(function(){
var selector = [];
$(options.filtersGroupSelector).find('input[type=checkbox]').each( function() {
if ( $(this).is(':checked') ) {
selector.push( '.' + $(this).val() );
if (layoutComplete) {
layoutComplete = false;

var selector = [];
$(options.filtersGroupSelector).find('input[type=checkbox]').each( function() {
if ( $(this).is(':checked') ) {
selector.push( '.' + $(this).val() );
}
});
var items = cache;
if (selector.length > 0) {
items = filterItems(selector);
}
});
var items = cache;
if (selector.length > 0) {
items = filterItems(selector);
reload($container,items);
}
reload($container,items);
});
});
};

var procUL = function($container){
$(options.filtersGroupSelector).children().each(function(){
$(this).click(function(){
$(options.filtersGroupSelector).children().removeClass('selected');
window.location.hash = $(this).data('filter');
var selector = [];
selector.push( '.' + $(this).data('filter') );
$(this).addClass('selected');
var items = cache;
if (selector.length > 0) {
items = filterItems(selector);
if (layoutComplete) {
layoutComplete = false;

$(options.filtersGroupSelector).children().removeClass('selected');
window.location.hash = $(this).data('filter');
var selector = [];
selector.push('.' + $(this).data('filter'));
$(this).addClass('selected');
var items = cache;
if (selector.length > 0) {
items = filterItems(selector);
}
reload($container, items);
}
reload($container,items);
});
});

Expand Down