Created
May 31, 2014 21:56
-
-
Save JAW-Dev/51b51f5fedb60257b28c to your computer and use it in GitHub Desktop.
Simple List Spliter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function($) { | |
// Split Browse Archive checkboxes into vertically alphabetized Omega columns. | |
var num_cols = 3, | |
container = $('.split-list'), | |
listItem = 'li', | |
listClass = 'sub-list'; | |
// For each exposed filter that has checkboxes. | |
container.each(function() { | |
// Figure out how many elements should be in each column. | |
var items_per_col = new Array(), | |
items = $(this).find(listItem), | |
min_items_per_col = Math.floor(items.length / num_cols), | |
difference = items.length - (min_items_per_col * num_cols); | |
for (var i = 0; i < num_cols; i++) { | |
if (i < difference) { | |
items_per_col[i] = min_items_per_col + 1; | |
} else { | |
items_per_col[i] = min_items_per_col; | |
} | |
} | |
// Assign the elements to the appropriate column. | |
for (var i = 0; i < num_cols; i++) { | |
$(this).append($('<ul ></ul>').addClass(listClass)); | |
for (var j = 0; j < items_per_col[i]; j++) { | |
var pointer = 0; | |
for (var k = 0; k < i; k++) { | |
pointer += items_per_col[k]; | |
} | |
$(this).find('.' + listClass).last().append(items[j + pointer]); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment