-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathsortable.min.js
More file actions
2 lines (2 loc) · 3.42 KB
/
sortable.min.js
File metadata and controls
2 lines (2 loc) · 3.42 KB
1
2
/*! sortable.js 0.8.0 */
(function(){var a,b,c,d,e,f,g;a="table[data-sortable]",d=/^-?[£$¤]?[\d,.]+%?$/,g=/^\s+|\s+$/g,c=["click"],f="ontouchstart"in document.documentElement,f&&c.push("touchstart"),b=function(a,b,c){return null!=a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},e={init:function(b){var c,d,f,g,h;for(null==b&&(b={}),null==b.selector&&(b.selector=a),d=document.querySelectorAll(b.selector),h=[],f=0,g=d.length;g>f;f++)c=d[f],h.push(e.initTable(c));return h},initTable:function(a){var b,c,d,f,g,h;if(1===(null!=(g=a.tHead)?g.rows.length:void 0)&&"true"!==a.getAttribute("data-sortable-initialized")){for(a.setAttribute("data-sortable-initialized","true"),b=0,h=a.tHead.rows[0].cells,d=0,f=h.length;f>d;d++)c=h[d],"false"!==c.getAttribute("data-sortable")&&"TH"===c.tagName&&e.setupClickableTH(a,c,b),b+=c.colSpan;return a}},setupClickableTH:function(a,d,f){var g,h,i,j,k,l;for(i=e.getColumnType(a,f),h=function(b){var c,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I;if(b.handled===!0)return!1;for(b.handled=!0,o="true"===this.getAttribute("data-sorted"),p=this.getAttribute("data-sorted-direction"),k=o?"ascending"===p?"descending":"ascending":i.defaultSortDirection,r=this.parentNode.querySelectorAll("th"),u=0,y=r.length;y>u;u++)d=r[u],d.setAttribute("data-sorted","false"),d.removeAttribute("data-sorted-direction");if(this.setAttribute("data-sorted","true"),this.setAttribute("data-sorted-direction",k),q=a.tBodies[0],n=[],o){for(I=q.rows,E=0,C=I.length;C>E;E++)h=I[E],n.push(h);for(n.reverse(),F=0,D=n.length;D>F;F++)m=n[F],q.appendChild(m)}else{for(t=null!=i.compare?i.compare:function(a,b){return b-a},g=function(a,b){return a[0]===b[0]?a[2]-b[2]:i.reverse?t(b[0],a[0]):t(a[0],b[0])},G=q.rows,l=v=0,z=G.length;z>v;l=++v)for(m=G[l],j=0,H=m.cells,w=0,A=H.length;A>w;w++)c=H[w],j===f&&(s=e.getNodeValue(c),null!=i.comparator&&(s=i.comparator(s)),n.push([s,m,l])),j+=c.colSpan;for(n.sort(g),x=0,B=n.length;B>x;x++)m=n[x],q.appendChild(m[1])}return"function"==typeof window.CustomEvent&&"function"==typeof a.dispatchEvent?a.dispatchEvent(new CustomEvent("Sortable.sorted",{bubbles:!0})):void 0},l=[],j=0,k=c.length;k>j;j++)g=c[j],l.push(b(d,g,h));return l},getColumnType:function(a,b){var c,d,f,g,h,i,j,k,l,m,n;if(d=null!=(l=a.querySelectorAll("th")[b])?l.getAttribute("data-sortable-type"):void 0,null!=d)return e.typesObject[d];for(m=a.tBodies[0].rows,h=0,j=m.length;j>h;h++)for(c=m[h],f=e.getNodeValue(c.cells[b]),n=e.types,i=0,k=n.length;k>i;i++)if(g=n[i],g.match(f))return g;return e.typesObject.alpha},getNodeValue:function(a){var b;return a?(b=a.getAttribute("data-value"),null!==b?b:"undefined"!=typeof a.innerText?a.innerText.replace(g,""):a.textContent.replace(g,"")):""},setupTypes:function(a){var b,c,d,f;for(e.types=a,e.typesObject={},f=[],c=0,d=a.length;d>c;c++)b=a[c],f.push(e.typesObject[b.name]=b);return f}},e.setupTypes([{name:"numeric",defaultSortDirection:"descending",match:function(a){return a.match(d)},comparator:function(a){return parseFloat(a.replace(/[^0-9.-]/g,""),10)||0}},{name:"date",defaultSortDirection:"ascending",reverse:!0,match:function(a){return!isNaN(Date.parse(a))},comparator:function(a){return Date.parse(a)||0}},{name:"alpha",defaultSortDirection:"ascending",match:function(){return!0},compare:function(a,b){return a.localeCompare(b)}}]),setTimeout(e.init,0),"function"==typeof define&&define.amd?define(function(){return e}):"undefined"!=typeof exports?module.exports=e:window.Sortable=e}).call(this);