From c822c054683ff7ef3cb091888d0b1044eb9e27c6 Mon Sep 17 00:00:00 2001
From: Jochen Keil
Date: Tue, 26 Mar 2013 11:28:43 +0100
Subject: [PATCH] Option for adding gaps to columns
Setting gap to a non-zero value, e.g. 40 will add 20px to the left and
right of each column as additional gap. This is done by setting the
margin-{left,right} css style. Columns themselves are resized to width - gap.
---
src/jquery.columnizer.js | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/jquery.columnizer.js b/src/jquery.columnizer.js
index 6099c4a..8456d8f 100644
--- a/src/jquery.columnizer.js
+++ b/src/jquery.columnizer.js
@@ -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
@@ -49,6 +51,8 @@
}
}
+ options.width += options.gap;
+
return this.each(function() {
var $inBox = options.target ? $(options.target) : $(this);
var maxHeight = $(this).height();
@@ -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;
@@ -398,7 +402,14 @@
$inBox.data("columnizing", true);
$inBox.empty();
- $inBox.append($("")); //"
+ $inBox.append($( ""
+ )
+ ); //"
$col = $inBox.children(":last");
$col.append($cache.clone());
maxHeight = $col.height();
@@ -441,7 +452,14 @@
className = (i === 0) ? prefixTheClassName("first") : "";
className += " " + prefixTheClassName("column");
className = (i == numCols - 1) ? (prefixTheClassName("last") + " " + className) : className;
- $inBox.append($("")); //"
+ $inBox.append($( ""
+ )
+ ); //"
}
// fill all but the last column (unless overflowing)
@@ -449,7 +467,14 @@
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($("")); //"
+ $inBox.append($( ""
+ )
+ ); //"
}
$col = $inBox.children().eq(i);
if(scrollHorizontally){