-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.columnlist.js
36 lines (31 loc) · 1.19 KB
/
jquery.columnlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// jquery.columnlist.js
// @weblinc, @jsantell (c) 2012
;(function( $ ) {
$.fn.columnlist = function ( options ) {
options = $.extend( {}, $.fn.columnlist.defaults, options );
return this.each(function () {
var
$list = $( this ),
size = options.size || $list.data( 'columnList' ) || 1,
$children = $list.children( 'li' ),
perColumn = Math.ceil( $children.length / size ),
$column;
for (var i = 0; i < size; i++) {
$column = $('<ul />').appendTo( returnColumn( i ) );
for ( var j = 0; j < perColumn; j++ ) {
if ( $children.length > i * perColumn + j ) {
$column.append( $children[ i * perColumn + j ]);
}
}
$list.append( $column.parent() );
}
});
function returnColumn ( inc ) {
return $('<li class="' + options.incrementClass + inc + ' ' + options[ 'class' ] + '"></li>');
}
};
$.fn.columnlist.defaults = {
'class' : 'column-list',
incrementClass : 'column-list-'
};
})( jQuery );