Skip to content

Instantly share code, notes, and snippets.

@agentlame
Created July 30, 2013 01:14
Show Gist options
  • Select an option

  • Save agentlame/6109377 to your computer and use it in GitHub Desktop.

Select an option

Save agentlame/6109377 to your computer and use it in GitHub Desktop.
modtools pagination fix
// Function to sort items
function sortThings(order, asc) {
var pagination = $('#siteTable .nextprev');
var things = $('#siteTable .thing').sort(function (a, b) {
(asc) ? (A = a, B = b) : (A = b, B = a);
switch (order) {
case 'age':
var timeA = new Date($(A).find('time:first').attr('datetime')).getTime(),
timeB = new Date($(B).find('time:first').attr('datetime')).getTime();
return timeA - timeB;
case 'score':
var scoreA = $(A).find('.score:visible').text().match(numberRX),
scoreB = $(B).find('.score:visible').text().match(numberRX);
return scoreA - scoreB;
case 'reports':
var reportsA = $(A).find('.reported-stamp').text().match(numberRX),
reportsB = $(B).find('.reported-stamp').text().match(numberRX);
return reportsA - reportsB;
}
});
$('#siteTable').empty().append(things).append(pagination);
}
sortThings(listingOrder, sortAscending);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment