Created
October 23, 2012 14:15
-
-
Save bloodyowl/3938983 to your computer and use it in GitHub Desktop.
JS pagination
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
// requires Array.range mixin | |
function paginate(list, itemsPerPage){ | |
// @list : Array, what to paginate | |
// @itemsPerPage : Number | |
var fragment = DOM.createFragment(); | |
Array.range(0, Math.ceil(list.length / itemsPerPage)).forEach(function(item){ | |
var page = DOM.create("div").setAttr("id", "page-" + item).appendTo(fragment); | |
if(item != 0) page.addClass("hidden"); | |
Array.range(itemsPerPage * item, itemsPerPage * item + itemsPerPage).forEach(function(i){ | |
if(list[i] == null) return; | |
page.insert({ bottom : list[i]}) | |
}) | |
}) | |
return fragment | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment