Widget:indexSorterGrouper/sandbox: Difference between revisions
Jump to navigation
Jump to search
More debugging |
Adding functions step by step |
||
Line 55: | Line 55: | ||
}); | }); | ||
}]); | }]); | ||
function orderByName(currentButton) { | |||
var sortOrder = tdollSorterActiveButton(currentButton); | |||
var comparer = function (a, b) { | |||
var nameA=$(a).data('name').toLowerCase(); | |||
var nameB=$(b).data('name').toLowerCase(); | |||
if (nameA < nameB) return -1 * sortOrder; | |||
if (nameA > nameB) return 1 * sortOrder; | |||
return 0; | |||
}; | |||
var grouper = function (parent, elements) { | |||
var currentLetter = getFirstLetterGroup($(elements).first().data('name')); | |||
var groupHeader = $("<h3><span class="mw-headline" id="Some_heading">").text(currentLetter.toUpperCase() + "...").addClass("addedbysorter"); | |||
groupHeader.insertBefore(elements.first()); | |||
$.grep(elements, function(element, i) { | |||
var currentLetter = getFirstLetterGroup($(element).data('name')); | |||
var nextElementLetter = getFirstLetterGroup($(elements[i+1]).data('name')); | |||
if (currentLetter !== nextElementLetter) { | |||
var groupHeaderText = nextElementLetter.toUpperCase() + "..."; | |||
if (groupHeaderText.trim() != "...") { | |||
var groupHeader = $("<h3 />").text(groupHeaderText).addClass("addedbysorter"); | |||
groupHeader.insertAfter(element); | |||
} | |||
} | |||
return true; | |||
}); | |||
}; | |||
tdollSorter(comparer, grouper); | |||
} | |||
function getFirstLetterGroup(element) { | |||
if (!element || element == null) { | |||
return " "; | |||
} | |||
var letter = element.charAt(0); | |||
if (letter >= "0" && letter <= "9") { | |||
letter = "#"; | |||
} | |||
return letter.toLowerCase(); | |||
} | |||
</script><div style="display:inline-block"> | </script><div style="display:inline-block"> | ||
<button class="gf-button" data-tdollsortbutton="true" disabled data-initialsort="true" onclick="orderByClassRarityName(this);">By Class>Rarity>Name</button> | <button class="gf-button" data-tdollsortbutton="true" disabled data-initialsort="true" onclick="orderByClassRarityName(this);">By Class>Rarity>Name</button> |
Revision as of 00:21, 27 July 2024
Released on this server: