<tr>
<container>
<row>
- <column num="four">
- Explicitly declare four col
- <div class="bloop">
- bloop
- </div>
+ <column class="green">
+ I'm evenly
</column>
- <column num="eight">eight col</column>
+ <column class="blue">distributed</column>
+ <column class="red">into 3 columns</column>
</row>
</container>
<container>
<row>
- <column num="two">
- <center>two col centered</center>
- </column>
- <column num="eight">
- <center>eight col centered</center>
- </column>
- <column num="two">
- <center>two col centered</center>
- </column>
- </row>
- </container>
-
- <container>
- <row>
- <column class="green">
- I'm evenly
+ <column class="green" small='8'>
+ .large-4 .small-8
</column>
- <column class="blue">distributed</column>
- <column class="red">into</column>
- <column class="green">two</column>
- <column class="blue">columns</column>
- <column class="red">each</column>
+ <column class="blue" small='2'>.large-4 .small-2</column>
+ <column class="red" small='2'>.large-4 .small-2</column>
</row>
</container>
-
- <container>empty container</container>
- <row>empty row</row>
</tr>
</table>
</body>
var createCol = function(obj) {
var output = '';
+ var mQ = {small: 0, large: 0};
+ var colEven = '';
+
+ $.each(obj, function() {
+ var col = $(this);
+
+ // do the maths first
+ $.each( mQ, function(i, val) {
+ if (!col.attr(i)) {
+ // count the number of columns that do not have a specified width
+ mQ[i]++;
+
+ // at the final iteration
+ if (mQ[i] === obj.length) {
+ // divide the default grid number by the number of colums with no width
+ var evenSplit = Math.floor( 12 / (mQ[i]) );
+
+ // append the missing class to the column class
+ colEven += i + '-' + evenSplit + ' ';
+ }
+ };
+ });
+ });
$.each(obj, function(v,k) {
- var temp = ''
+ var temp = ''
var contents = $(this).html();
var colClass = 'columns ' + $(this).attr('class');
- var colNum;
- if ($(this).attr('num')) {
- colNum = $(this).attr('num');
- }
- else {
- // divide row evenly into number of column elements
- // round down, just in case
- var map = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"];
- var index = Math.floor( 12 / (obj.length) );
- colNum = map[index - 1];
- }
+ var colNum = '';
+ var col = $(this);
+
+ $.each( mQ, function(i, val) {
+ if (col.attr(i)) {
+ colNum += i + '-' + col.attr(i) + ' ';
+ };
+ });
+
// check if this is the last element in the row
+ // add previously calculated even class
if (v !== obj.length - 1) {
temp = '<td class="wrapper">'
- +'<table class="' + colClass + ' ' + colNum +'">'
+ +'<table class="' + colClass + ' ' + colNum + colEven +'">'
+'<tr><td>'
+ contents +'</td><td class="expander"></td></tr></table></td>';
} else {
temp = '<td class="wrapper last">'
- +'<table class="' + colClass + ' ' + colNum +'">'
+ +'<table class="' + colClass + ' ' + colNum + colEven +'">'
+'<tr><td>'
+ contents +'</td><td class="expander"></td></tr></table></td>';
}