Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/jquery.columnizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
// text nodes. smaller numbers will result in higher accuracy
// column widths, but will take slightly longer
accuracy : false,
// false to round down column widths (for compatibility)
// true to conserve all decimals in the column widths
precise : false,
// don't automatically layout columns, only use manual columnbreak
manualBreaks : false,
// previx for all the CSS classes used by this plugin
Expand All @@ -65,7 +68,18 @@
}
if(options.debug) { // assert is off by default
this.debug=options.debug;
}
}
if(!options.setWidth) {
if (options.precise) {
options.setWidth = function (numCols) {
return 100 / numCols;
};
} else {
options.setWidth = function (numCols) {
return Math.floor(100 / numCols);
};
}
}

/**
* appending a text node to a <table> will
Expand Down Expand Up @@ -445,7 +459,7 @@
$inBox.data("columnizing", true);

$inBox.empty();
$inBox.append($("<div style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
$col = $inBox.children(":last");
appendSafe($col, $cache.clone());
maxHeight = $col.height();
Expand Down Expand Up @@ -488,15 +502,15 @@
className = (i === 0) ? prefixTheClassName("first") : "";
className += " " + prefixTheClassName("column");
className = (i == numCols - 1) ? (prefixTheClassName("last") + " " + className) : className;
$inBox.append($("<div class='" + className + "' style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div class='" + className + "' style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
}

// fill all but the last column (unless overflowing)
i = 0;
while(i < numCols - (options.overflow ? 0 : 1) || scrollHorizontally && $destroyable.contents().length){
if($inBox.children().length <= i){
// we ran out of columns, make another
$inBox.append($("<div class='" + className + "' style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div class='" + className + "' style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
}
$col = $inBox.children().eq(i);
if(scrollHorizontally){
Expand Down