-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sorting functionality to category pages (#596)
* Add sort menu to category pages * Use CSS grid for cards The way that Semantic UI does columns for the cards is a massive pain to override (it uses negative margins for everything), and this was making the menu glitch out on mobile. CSS grid is supported by every major browser now, so there's no reason not to use it. * Remove data-license attribute * Make dropdown full width on mobile * Move dropdown to the right This seems more in line with how UI is laid out on other sites I've seen. * Don't generate sort attributes for archived crates
- Loading branch information
1 parent
d8e9e57
commit 9f60c5d
Showing
7 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function sortCrates(attribute, numeric, ascending) { | ||
var section = $("#crates-section .card-grid"); | ||
var cards = section.children(".card"); | ||
|
||
var default_value = numeric ? 0 : ""; | ||
|
||
cards.sort(function (a, b) { | ||
var aAttr = a.getAttribute(attribute) || default_value; | ||
var bAttr = b.getAttribute(attribute) || default_value; | ||
|
||
if (numeric) { | ||
aAttr = parseInt(aAttr); | ||
bAttr = parseInt(bAttr); | ||
} else { | ||
aAttr = aAttr.toUpperCase(); | ||
bAttr = bAttr.toUpperCase(); | ||
} | ||
|
||
if (aAttr > bAttr) { | ||
return ascending ? 1 : -1; | ||
} else if (aAttr < bAttr) { | ||
return ascending ? -1 : 1; | ||
} else { | ||
return 0; | ||
} | ||
}); | ||
|
||
cards.detach().appendTo(section); | ||
} | ||
|
||
$(document).ready(function () { | ||
var sortDropdown = $("#sort-menu"); | ||
|
||
sortDropdown.dropdown({ | ||
onChange: function (value, text, selected) { | ||
var type = selected[0].getAttribute("data-type"); | ||
var order = selected[0].getAttribute("data-order"); | ||
|
||
sortCrates(value, type == "num", order == "asc"); | ||
}, | ||
}); | ||
}); |
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
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
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
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