I have Isotope running smoothly but it seems to reset variable-sizes class values in an unpredictable way - at least as far as I understand how it works.
My basic structure: A row of buttons at page top, A-Z class=letter. Each button loads a new set of divs.
$(".letter").click(function() {
if ($('.'+letX+'').length > 0 ) { // divs already loaded
var newItems = $('.'+letX+''); // letX grabbed from div ID, a, b, etc.
$(this).find('#container').after(newItems); // loads fine, should hold width2 height2 set on very first load
}
else {
var stringData = $.ajax({ url: 'digz/index/'+$(this).attr("id")+'.txt', async: false }).responseText;
var $newItems = $(stringData);
$('#container').isotope( 'insert', $newItems );
$('.element').each(function(index) {
$(this).find('.titlePE').before('<p class="number">' + index + '</p>'); // add numbers for variable-sizes
});
variableSizes(); // new divs so set random width2 height2
}
});
I set a function for variableSizes to help me be a little more clear. Declared befor the above..
function variableSizes() {
$container.find('.element').each(function(){ // add randomish size classes
var $this = $(this), number = parseInt( $this.find('.number').text(), 10 );
//$this.removeClass('width2').removeClass('height2');
//$('.element').removeClass('width2').removeClass('height2');
// if ( !($this).hasClass('sized') ) {
if ( number % 7 % 2 === 1 ) { $this.addClass('width2'); } // $('div .nameP').html('wide');
if ( number % 3 === 0 ) { $this.addClass('height2'); }
// $this.addClass('sized'); // }
});
}
This is the standard Isotope routine.
My rems are attempted fixes. Oh, I see I left out the code for if($(this).hasClass('sized')) test
But what happens is that I click the variable-sizes button (which adds a pre-class to the already set (random) width2 height2. I then click g = nice layout. Then h = nice, then d, nice, then g again = crap. It mostly sets at width2 height2 or some at just height2.
I am missing a piece of the process here.
How to get the repeat click g - or d or... to maintain the randomly set width2 height2's? It doesn't even have to be predictable as, lets face it this is just bling, but it should hold some kind of 'nice.'
Any suggests?