Created
April 25, 2014 16:46
-
-
Save amcdnl/11295869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calcLayout: function (item, idx, col) { | |
// if we dont have anything or I'm the first | |
if (col.length === 1 || idx === 0) { | |
item.col = 1; | |
item.row = 1; | |
} else { | |
var sizeraoo = { | |
1: 4, // 100% | |
1.5: 3, // 75% | |
//3: 1.3, // 33% | |
2: 2, // 50% | |
1: 1 // 25% | |
}; | |
var prev = col[idx - 1]; | |
if((prev.sizex + sizeraoo[item.sizex]) > 4){ | |
item.row = prev.row + 1; | |
item.col = 1; | |
} else { | |
item.row = prev.row; | |
// col = 1 sizex 3 ... col 3 sizex 4 | |
item.col = (prev.col + prev.sizex) + 1; | |
} | |
/* | |
Goal: determine what column for save && % width for display | |
cols start at 1 ... end at 4 | |
sizex equals: | |
1 == 100% == 1 | |
1.5 == 75% == 3/4 | |
2 == 50% == 1/2 | |
3 == 33% == 1/3 | |
4 == 25% == 1/4 | |
Cases: | |
2 + 2 | |
1 | |
3 + 3 + 3 | |
1.5 + 4 | |
4 + 4 + 4 + 4 | |
2 + 3 ... 2 = row 2 | |
*/ | |
// find the previous one and chk | |
// its column and sizex... only add if greater than 1 though | |
/*var prev = col[idx - 1]; | |
var prevSizeX = prev.sizex === 1 ? 4 : prev.sizex; | |
var prevWidth = (prevSizeX + (prev.col - 1)); | |
var curSizeX = item.sizex === 1 ? 4 : item.sizex; | |
// if the total of me and the previos is greater | |
// the max, i'm on the next row first column | |
// e.g. prevWidth: 2, sizex: 3 | |
if ((prevWidth + curSizeX) > 4) { | |
item.row = prev.row + 1; | |
item.col = 1; | |
} else { | |
// if we are smaller than total cols (4), | |
// we are on the same row as our prev item | |
// e.g. prev.sizex: 2 prev.col: 1, sizex: 2 | |
if (prevWidth + curSizeX <= 4) { | |
item.row = prev.row; | |
item.col = prevWidth + 1; | |
} | |
}*/ | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment