Skip to content

Commit 4e891f4

Browse files
committed
Merge pull request adamwulf#169 from RoboterHund/master
added options.precise, true <=> no Math.floor on column width (default false)
2 parents 77aa639 + 1480877 commit 4e891f4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/jquery.columnizer.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
// text nodes. smaller numbers will result in higher accuracy
4242
// column widths, but will take slightly longer
4343
accuracy : false,
44+
// false to round down column widths (for compatibility)
45+
// true to conserve all decimals in the column widths
46+
precise : false,
4447
// don't automatically layout columns, only use manual columnbreak
4548
manualBreaks : false,
4649
// previx for all the CSS classes used by this plugin
@@ -65,7 +68,18 @@
6568
}
6669
if(options.debug) { // assert is off by default
6770
this.debug=options.debug;
68-
}
71+
}
72+
if(!options.setWidth) {
73+
if (options.precise) {
74+
options.setWidth = function (numCols) {
75+
return 100 / numCols;
76+
};
77+
} else {
78+
options.setWidth = function (numCols) {
79+
return Math.floor(100 / numCols);
80+
};
81+
}
82+
}
6983

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

447461
$inBox.empty();
448-
$inBox.append($("<div style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
462+
$inBox.append($("<div style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
449463
$col = $inBox.children(":last");
450464
appendSafe($col, $cache.clone());
451465
maxHeight = $col.height();
@@ -488,15 +502,15 @@
488502
className = (i === 0) ? prefixTheClassName("first") : "";
489503
className += " " + prefixTheClassName("column");
490504
className = (i == numCols - 1) ? (prefixTheClassName("last") + " " + className) : className;
491-
$inBox.append($("<div class='" + className + "' style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
505+
$inBox.append($("<div class='" + className + "' style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
492506
}
493507

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

0 commit comments

Comments
 (0)