2016-03-22 15:02:39 +00:00
|
|
|
!function(a){a.fn.stupidtable=function(b){return this.each(function(){var c=a(this);b=b||{},b=a.extend({},a.fn.stupidtable.default_sort_fns,b),c.on("click.stupidtable","thead th",function(){var d=a(this),e=0,f=a.fn.stupidtable.dir;d.parents("tr").find("th").slice(0,d.index()+1).each(function(){var b=a(this).attr("colspan")||1;e+=parseInt(b,10)}),e-=1;var g=d.data("sort-default")||f.ASC;d.data("sort-dir")&&(g=d.data("sort-dir")===f.ASC?f.DESC:f.ASC);var h=d.data("sort")||null;null!==h&&(c.trigger("beforetablesort",{column:d.index(),direction:g}),c.css("display"),setTimeout(function(){var i=b[h];c.children("tbody").each(function(b,c){var d=[],h=a(c),j=h.children("tr").not("[data-sort-ignore]");j.each(function(b,c){var f=a(c).children().eq(e),g=f.data("sort-value"),h="undefined"!=typeof g?g:f.text();d.push([h,c])}),d.sort(function(a,b){return i(a[0],b[0])}),g!=f.ASC&&d.reverse(),j=a.map(d,function(a){return a[1]}),h.append(j)}),c.find("th").data("sort-dir",null).removeClass("sorting-desc sorting-asc"),d.data("sort-dir",g).addClass("sorting-"+g),c.trigger("aftertablesort",{column:d.index(),direction:g}),c.css("display")},10))})})},a.fn.stupidtable.dir={ASC:"asc",DESC:"desc"},a.fn.stupidtable.default_sort_fns={"int":function(a,b){return parseInt(a,10)-parseInt(b,10)},"float":function(a,b){return parseFloat(a)-parseFloat(b)},string:function(a,b){return a.localeCompare(b)},"string-ins":function(a,b){return a=a.toLocaleLowerCase(),b=b.toLocaleLowerCase(),a.localeCompare(b)}}}(jQuery);
|