Skip to content
Closed
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
33 changes: 29 additions & 4 deletions src/jquery.columnizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
var defaults = {
// default width of columns
width: 400,
// optional gap (in px) between columns
gap: 0,
// optional # of columns instead of width
columns : false,
// true to build columns once regardless of window resize
Expand Down Expand Up @@ -49,6 +51,8 @@
}
}

options.width += options.gap;

return this.each(function() {
var $inBox = options.target ? $(options.target) : $(this);
var maxHeight = $(this).height();
Expand Down Expand Up @@ -164,7 +168,7 @@
if($item[0].nodeType == 3){
// it's a text node, split it up
var oText = $item[0].nodeValue;
var counter2 = options.width / 18;
var counter2 = (options.width - options.gap) / 18;
if(options.accuracy)
counter2 = options.accuracy;
var columnText;
Expand Down Expand Up @@ -398,7 +402,14 @@
$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.width - options.gap) + "px;"
+ "float: " + options.columnFloat + ";"
+ "margin-left:" + options.gap / 2 + "px;"
+ "margin-right:" + options.gap / 2 + "px;"
+ "'></div>"
)
); //"
$col = $inBox.children(":last");
$col.append($cache.clone());
maxHeight = $col.height();
Expand Down Expand Up @@ -441,15 +452,29 @@
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 style='"
+ "width: " + (options.width - options.gap) + "px;"
+ "float: " + options.columnFloat + ";"
+ "margin-left:" + options.gap / 2 + "px;"
+ "margin-right:" + options.gap / 2 + "px;"
+ "'></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 style='"
+ "width: " + (options.width - options.gap) + "px;"
+ "float: " + options.columnFloat + ";"
+ "margin-left:" + options.gap / 2 + "px;"
+ "margin-right:" + options.gap / 2 + "px;"
+ "'></div>"
)
); //"
}
$col = $inBox.children().eq(i);
if(scrollHorizontally){
Expand Down