DrewDahlman / Mason

Mason.js for creating a perfect grid with jQuery.
http://masonjs.com/
MIT License
1.22k stars 183 forks source link

TypeError: settings.sizes[s] is undefined #14

Closed CR34L closed 11 years ago

CR34L commented 11 years ago

Hi there,

just created mason instance with following parameters:

$("#mason-grid").mason({ itemSelector: ".mason-box", ratio: 1.1, sizes: [ [1, 1] ], promoted: [ [1, 3, 'wide'], [3, 1, 'tower'], [2, 3, 'big'], [1, 1, 'default'] ], filler: { itemSelector: '.filler', filler_class: 'custom_filler' }....

ok...if I give some promoted classes I get this error:

TypeError: settings.sizes[s] is undefined error source line: var h = settings.sizes[s][1];

//creality

DrewDahlman commented 11 years ago

hmm strange... My first thought is remove the "default" out of your promoted. Also do you have a jsfiddle?

StefanSchwartze commented 11 years ago

I had the same issue and fixed it. The problem was in mason.js at line 170. You first have to call index zero, so like this: var h = settings.sizes[s-1][1]; Because when you have a size of 2, you first call index 0 then index 1. Your previous solution called first index 1 then 2, which is undefined.

DrewDahlman commented 11 years ago

@StefanSchwartze wanna do a pull request with your fix?

StefanSchwartze commented 11 years ago

Just did it.

DrewDahlman commented 11 years ago

awesome. merged and set!

appleparan commented 11 years ago

I got same error. I used merged version and it didn't solve my problem. The difference is i'm not using promoted option.

DrewDahlman commented 11 years ago

Interesting - I am wondering if this all comes down to combo between promoted and non promoted. I am going to run some tests.

@appleparan - when you see this error does it completely break your grid? what happens? would you mind posting a fiddle?

CR34L commented 11 years ago

Error still there. The problem is the hardcoded index on lines 170: var h = settings.sizes[s - 1][1]; var w = settings.sizes[s - 1][0];

sometimes s is 0. so the index is out of bounds. I have a dirty workaround for that: if (s <= 0) { s = 1; } so everything is working fine.

to answer your question: yes - the layout brakes.

mrwokkel commented 11 years ago

I fixed it by doing this: Line 118: ran = ((settings.sizes.length - 1) - 1) + i; replaced with: ran = (settings.sizes.length - settings.promoted.length) + i; (you can check it by putting this line after 118) console.log(settings.sizes[ran], settings.promoted[i][2]);

Restored line 170 and 171 to var h = settings.sizes[s][1]; var w = settings.sizes[s][0];

I try to make a pull request