Created
February 21, 2017 22:47
-
-
Save lucawen/ff5d9527e489aa40a7fb6b1693ebe476 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function FilterByAttribute(mainElementName, itemElementName, attributeName, addSpace){ | |
addSpace = addSpace || false; | |
var divList = $(itemElementName); | |
divList.sort(function (a, b) { | |
var attributeA = $(a).data(attributeName); | |
var attributeB = $(b).data(attributeName); | |
if(IsStringNumber(attributeA) || IsStringNumber(attributeB)){ | |
return $(a).data(attributeName) > $(b).data(attributeName); | |
} else { | |
return String.prototype.localeCompare.call(attributeA.toLowerCase(), attributeB.toLowerCase()); | |
} | |
}); | |
$(mainElementName).html(divList); | |
if(addSpace){ | |
$(mainElementName+" hr.hr-agora").remove(); | |
$(mainElementName+" "+itemElementName+":not(:first)").prepend("<hr class='hr-agora'>"); | |
} | |
} | |
function IsStringNumber(value) { | |
return Math.floor(value) == value && $.isNumeric(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment