-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortable.mega-advanced.min.js
1 lines (1 loc) · 1.14 KB
/
sortable.mega-advanced.min.js
1
document.addEventListener("click",function(e){var r,t=" dir-d ",a=" dir-u ",n=/ dir-(u|d) /,s="data-sort",c=e.target;function i(e,t){e.className=e.className.replace(n,"")+t||""}function l(e,t){var a=e.cells[r];return a.hasAttribute(s)||a.setAttribute(s,t.getData(a)),a.getAttribute(s)}var o=[{useMe:function(){return/\bsize\b/.test(c.className)},getData:function(e){var t=e.innerText.match(/(\d+)([kMGT])B/);return t[1]*Math.pow(1e3,{k:1,M:2,G:3,T:4}[t[2]])}},{useMe:function(){return/\bdate\b/.test(c.className)},getData:function(){return cell.innerText.replace(/(\d+)\/(\d+)\/(\d+)/,"$3$1$2")}},{useMe:function(){return!0},getData:function(e){return e.innerText}}];if("TH"==c.nodeName){var u=c.offsetParent;if(/\bsortable\b/.test(u.className)){for(var d=c.parentNode.cells,f=0;f<d.length;f++)d[f]===c?r=f:i(d[f]);var N=t;-1!==c.className.indexOf(t)&&(N=a),i(c,N);var v,b=u.tBodies[0],m=[].slice.call(b.cloneNode(!0).rows,0),g=N==a;for(f=0;f<o.length&&!(v=o[f]).useMe();f++);m.sort(function(e,t){if(e=l(e,v),t=l(t,v),g){var a=e;e=t,t=a}return isNaN(e-t)?e.localeCompare(t):e-t});var h=b.cloneNode();for(f=0;f<m.length;f++)h.appendChild(m[f]);u.replaceChild(h,b)}}});