Skip to content

Added columnClassFunc option to specify class selectors for column sizin... #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ Columnizer will add CSS classes to the columns it creates. Each column will have
<td style="text-align: right; padding-right: 10px;"><em>manualBreaks</em></td>
<td style="padding-left: 10px;">Defaults to false. Set to true if you only want to create columns with manual column breaks. If true, then width, height, columns options are ignored.</td>
</tr>
<tr>
<td style="text-align: right; padding-right: 10px;"><em>columnClassFunc</em></td>
<td style="padding-left: 10px;">Optional function that will be called for each column to generate custom class selectors for sizing instead of inline width.<br>Eg: columnClassFunc: function(col) { return "grid-" + (12/col); }</td>
</tr>
<tr>
<td style="text-align: right; padding-right: 10px;"><em>extraColumnClass</em></td>
<td style="padding-left: 10px;">Extra classes to add to each column.</td>
</tr>
</tbody>
</table>

Expand Down
20 changes: 15 additions & 5 deletions src/jquery.columnizer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// version 1.6.0
// version 1.6.1
// http://welcome.totheinter.net/columnizer-jquery-plugin/
// created by: Adam Wulf @adamwulf, [email protected]

Expand Down Expand Up @@ -38,7 +38,11 @@
manualBreaks : false,
// previx for all the CSS classes used by this plugin
// default to empty string for backwards compatibility
cssClassPrefix : ""
cssClassPrefix : "",
// if set use columnClassFunc(colNum) to set width's with custom classes instead of fixed percentiles
columnClassFunc: false,
// extra classes to add to each column wrapper
extraColumnClass: false
};
options = $.extend(defaults, options);

Expand Down Expand Up @@ -301,6 +305,7 @@
+ prefixTheClassName("first") + " "
+ prefixTheClassName("last") + " "
+ prefixTheClassName("column") + " "
+ options.extraColumnClass + " "
+ "' style='width:100%; float: " + options.columnFloat + ";'></div>")); //"
$col = $inBox.children().eq($inBox.children().length-1);
$destroyable = $cache.clone(true);
Expand Down Expand Up @@ -396,9 +401,12 @@
if($inBox.data("columnizing")) return;
$inBox.data("columnized", true);
$inBox.data("columnizing", true);

var targetWidth = !options.columnClassFunc ? "width:" + (Math.floor(100 / numCols))+ "%; " : "";
var targetClass = options.columnClassFunc ? options.columnClassFunc(numCols) : "";

$inBox.empty();
$inBox.append($("<div style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div class='" + targetClass + "'" + targetWidth + "float: " + options.columnFloat + ";'></div>"));
$col = $inBox.children(":last");
$col.append($cache.clone());
maxHeight = $col.height();
Expand Down Expand Up @@ -441,15 +449,17 @@
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>")); //"
className += options.extraColumnClass ? " " + options.extraColumnClass : "";
className += options.columnClassFunc ? " " + targetClass : "";
$inBox.append($("<div class='" + className + "' style='" + targetWidth + "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='" + targetWidth + "float: " + options.columnFloat + ";'></div>"));
}
$col = $inBox.children().eq(i);
if(scrollHorizontally){
Expand Down