Widget:indexSorterGrouper: Difference between revisions
Jump to navigation
Jump to search
Added grouping for class/rarity |
Fixed Index grouping |
||
Line 191: | Line 191: | ||
var grouper = function (parent, elements) { | var grouper = function (parent, elements) { | ||
var | var firstIndex = elements.first().data('index'); | ||
var groupHeader = $("<h3 />").text("..." + firstTen).addClass("addedbysorter"); | var firstTen = Math.ceil(parseInt(firstIndex) / 10) * 10; | ||
var groupHeader = $("<h3 />").text(getNumberText(firstIndex) + "..." + getNumberText(firstTen)).addClass("addedbysorter"); | |||
groupHeader.insertBefore(elements.first()); | groupHeader.insertBefore(elements.first()); | ||
$.grep(elements, function(element, i) { | $.grep(elements, function(element, i) { | ||
if (elements <= i+1) { | |||
return true; | |||
} | } | ||
var nextElement = $(elements[i+1]); | |||
createIndexGroup(element, nextElement); | |||
return true; | return true; | ||
}); | }); | ||
Line 213: | Line 209: | ||
tdollSorter(comparer, grouper); | tdollSorter(comparer, grouper); | ||
} | |||
function getNumberText(val) { | |||
if (!val || isNaN(val)) { | |||
return ""; | |||
} | |||
return "" + val; | |||
} | |||
function createIndexGroup(element, nextElement) { | |||
var currentTen = Math.ceil(parseInt($(element).data('index')) / 10) * 10; | |||
var nextElementTen = Math.ceil(parseInt(nextElement.data('index')) / 10) * 10; | |||
if (currentTen !== nextElementTen) { | |||
var linebreaker = $("<br />").addClass("addedbysorter"); | |||
linebreaker.insertAfter(element); | |||
var groupHeaderText = getNumberText(currentTen) + "..." + getNumberText(nextElementTen); | |||
if (!isNaN(nextElementTen)) { | |||
var groupHeader = $("<h3 />").text(groupHeaderText).addClass("addedbysorter"); | |||
groupHeader.insertAfter(linebreaker); | |||
} | |||
} | |||
} | } | ||
Revision as of 17:57, 1 May 2018
Released on this server: