-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.sort.min.js
More file actions
1 lines (1 loc) · 2.12 KB
/
jquery.sort.min.js
File metadata and controls
1 lines (1 loc) · 2.12 KB
1
(function(b){var a=function(){};a.prototype={extract:function(e,d){if(typeof this.extracts[d]!="undefined"){return this.extracts[d].apply(e)}else{return this.extracts["default"].call(e,d)}},extracts:{"default":function(d){return this[d]}},addExtract:function(e,d){this.extracts[e]=d}};var c=function(d){if(typeof d!="undefined"){this.rows=this.getRows(d)}this.extractor=new a};c.prototype={getRows:function(d){return d},compare:function(e,d){if(e==d){return 0}else{if(typeof e=="undefined"){return 1}if(typeof d=="undefined"){return -1}if(e>d){return 1}else{return -1}}},sort:function(d){var e=this;e.rows.sort(function(g,f){var h=0;for(var j=0;j<d.length&&h===0;j++){var m=!!d[j].inversed,l=e.extractor.extract(g,d[j].by),k=e.extractor.extract(f,d[j].by);if(m){h=e.compare(k,l)}else{h=e.compare(l,k)}}return h});return e.rows}};b.fn.sort=function(e){var d={processOptions:function(i){var h={};if("how" in i){h.how=(!Array.isArray(i.how)&&[i.how])||i.how}if("getRows" in i){h.getRows=i.getRows}else{h.getRows=function(){var q=[],o=b(this);if(o.children("tbody").length){o=o.children("tbody")}var m=o.children("tr");for(var k=0;k<m.length;k++){var p=m.eq(k),j=1;if(p.children("th").length){continue}p.children("td").each(function(){var s=b(this),t=Number(s.attr("rowspan"));if(t&&t>j){j=t}});if(!j){q.push(p[0])}else{var l=[p[0]];for(var r=k+j-1;k<r;k++){var n=b(l[l.length-1]).next()[0];l.push(n)}q.push(l)}}return q}}h.extracts=("extracts" in i)?i.extracts:{};h.classPrefix=("classPrefix" in i)?i.classPrefix:"";if(!("default" in h.extracts)){h.extracts["default"]=function(j){var k=b(this);return b.trim(k.children().filter("."+h.classPrefix+j).text())}}return h},updateTable:function(h,i){b(i).each(function(){var j=b(this);j.detach();h.append(j)});h.trigger("update")}};if(typeof e=="undefined"){throw"Initialization error: Sorter must init with arguments."}else{e=d.processOptions(e)}var f=this,g={dataKey:"sortData"};f.each(function(){var j=b(this);if(!j.data(g.dataKey)){j.data(g.dataKey,new c(e.getRows.apply(j)))}var k=j.data(g.dataKey);for(var h in e.extracts){k.extractor.addExtract(h,e.extracts[h])}var i=k.sort(e.how);d.updateTable(j,i)});return f}})(jQuery);