-
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.
- Loading branch information
1 parent
eba921b
commit 542b140
Showing
5 changed files
with
73 additions
and
4 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 .cards"); | ||
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