-
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.44 KB
/
sortable.min.js
File metadata and controls
2 lines (2 loc) · 3.44 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!=(h=a.tHead)?h.rows.length:void 0)&&"true"!==a.getAttribute("data-sortable-initialized")){for(a.setAttribute("data-sortable-initialized","true"),d=a.querySelectorAll("th"),b=f=0,g=d.length;g>f;b=++f)c=d[b],"false"!==c.getAttribute("data-sortable")&&e.setupClickableTH(a,c,b);return a}},setupClickableTH:function(a,d,f){var g,h,i,j,k,l,m;for(j=e.getColumnType(a,f),g=!1,i=function(b){var c,h,i,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;if(!g){for(g=!0,setTimeout(function(){return g=!1},0),o="true"===this.getAttribute("data-sorted"),p=this.getAttribute("data-sorted-direction"),k=o?"ascending"===p?"descending":"ascending":j.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(F=q.rows,x=0,B=F.length;B>x;x++)i=F[x],n.push(i);for(n.reverse(),h=document.createDocumentFragment(),D=0,C=n.length;C>D;D++)m=n[D],h.appendChild(m);q.appendChild(h)}else{for(t=null!=j.compare?j.compare:function(a,b){return b-a},c=function(a,b){return a[0]===b[0]?a[2]-b[2]:j.reverse?t(b[0],a[0]):t(a[0],b[0])},E=q.rows,l=v=0,z=E.length;z>v;l=++v)m=E[l],s=e.getNodeValue(m.cells[f]),null!=j.comparator&&(s=j.comparator(s)),n.push([s,m,l]);for(n.sort(c),h=document.createDocumentFragment(),w=0,A=n.length;A>w;w++)m=n[w],h.appendChild(m[1]);q.appendChild(h)}return"function"==typeof window.CustomEvent&&"function"==typeof a.dispatchEvent?a.dispatchEvent(new CustomEvent("Sortable.sorted",{bubbles:!0})):void 0}},m=[],k=0,l=c.length;l>k;k++)h=c[k],m.push(b(d,h,i));return m},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);