Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

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

Closed
CR34L opened this issue Aug 4, 2013 · 9 comments
Closed

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

CR34L opened this issue Aug 4, 2013 · 9 comments

Comments

@CR34L
Copy link

CR34L commented Aug 4, 2013

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
Copy link
Owner

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

@StefanSchwartze
Copy link
Contributor

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
Copy link
Owner

@StefanSchwartze wanna do a pull request with your fix?

@StefanSchwartze
Copy link
Contributor

Just did it.

@DrewDahlman
Copy link
Owner

awesome. merged and set!

@appleparan
Copy link

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
Copy link
Owner

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
Copy link
Author

CR34L commented Aug 24, 2013

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 added a commit to mrwokkel/Mason that referenced this issue Aug 30, 2013
@mrwokkel
Copy link
Contributor

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

mrwokkel added a commit to mrwokkel/Mason that referenced this issue Aug 30, 2013
DrewDahlman added a commit that referenced this issue Aug 30, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants