Timothy J. Warren
7afdab80ac
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good
1 line
1.2 KiB
JavaScript
1 line
1.2 KiB
JavaScript
(()=>{let e=null,t=null,s="",r=e=>e.cells.item(t).textContent.toLowerCase(),n=(t,s)=>{let n=r(t),a=r(s);if(console.log("Comparing "+n+" and "+a),e.classList.contains("numeric")){let e=n.replace("episodes: ","").replace("-",0).split("/"),t=a.replace("episodes: ","").replace("-",0).split("/");e.length>1?(n=parseInt(e[0],10)/parseInt(e[1],10),a=parseInt(t[0],10)/parseInt(t[1],10)):(n=parseInt(e[0],10),a=parseInt(t[0],10))}else parseInt(n,10)&&(n=parseInt(n,10),a=parseInt(a,10));return n>a?1:n<a?-1:0},a=()=>{let t="sorting-asc"!==s?"sorting-asc":"sorting-desc";return e.className=(e.className.replace(s,"")+" "+t).trim(),s=t},l=()=>(e.classList.remove("sorting-asc","sorting-desc"),e.classList.add("sorting"),s=""),i=r=>{if(e&&t!==r.target.cellIndex&&l(),"th"===(e=r.target).nodeName.toLowerCase()){t=e.cellIndex;let r=e.offsetParent.getElementsByTagName("tbody")[0],l=Array.from(r.rows);l&&(l.sort(n),"sorting-asc"===s&&l.reverse(),a(),r.innerHtml="",l.forEach(e=>{r.appendChild(e)}))}};return{init:()=>{let e=document.getElementsByTagName("th"),t=[];for(let s=0,r=e.length;s<r;s++){let r=e[s];r.classList.add("sorting"),r.classList.add("testing"),t.push(r.onclick=i)}return t}}})().init(); |