lucawen
2/21/2017 - 10:47 PM

filter.js

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);
}