Skip to content

Instantly share code, notes, and snippets.

@zackbloom
Created December 3, 2013 18:36
Show Gist options
  • Save zackbloom/7774909 to your computer and use it in GitHub Desktop.
Save zackbloom/7774909 to your computer and use it in GitHub Desktop.
Bookmarklet to run sortable.js (http://github.hubspot.com/sortable/docs/welcome/) on every table on the page
javascript:(function()%7B(function()%7Bvar%20a%2Cb%2Cc%2Cd%2Ce%2Cf%3Ba%3D%22table%5Bdata-sortable%5D%22%2Cc%3D%2F%5E-%3F%5B%C2%A3%24%C2%A4%5D%3F%5B%5Cd%2C.%5D%2B%25%3F%24%2F%2Cf%3D%2F%5E%5Cs%2B%7C%5Cs%2B%24%2Fg%2Ce%3D%22ontouchstart%22in%20document.documentElement%2Cb%3De%3F%22touchstart%22%3A%22click%22%2Cd%3D%7Binit%3Afunction(b)%7Bvar%20c%2Ce%2Cf%2Cg%2Ch%3Bfor(null%3D%3Db%26%26(b%3D%7B%7D)%2Cnull%3D%3Db.selector%26%26(b.selector%3Da)%2Ce%3Ddocument.querySelectorAll(b.selector)%2Ch%3D%5B%5D%2Cf%3D0%2Cg%3De.length%3Bg%3Ef%3Bf%2B%2B)c%3De%5Bf%5D%2Ch.push(d.initTable(c))%3Breturn%20h%7D%2CinitTable%3Afunction(a)%7Bvar%20b%2Cc%2Ce%2Cf%2Cg%3Bif(1%3D%3D%3Da.tHead.rows.length%26%26%22true%22!%3D%3Da.getAttribute(%22data-sortable-initialized%22))%7Bfor(a.setAttribute(%22data-sortable-initialized%22%2C%22true%22)%2Ce%3Da.querySelectorAll(%22th%22)%2Cb%3Df%3D0%2Cg%3De.length%3Bg%3Ef%3Bb%3D%2B%2Bf)c%3De%5Bb%5D%2C%22false%22!%3D%3Dc.getAttribute(%22data-sortable%22)%26%26d.setupClickableTH(a%2Cc%2Cb)%3Breturn%20a%7D%7D%2CsetupClickableTH%3Afunction(a%2Cc%2Ce)%7Bvar%20f%3Breturn%20f%3Dd.getColumnType(a%2Ce)%2Cc.addEventListener(b%2Cfunction()%7Bvar%20b%2Cg%2Ch%2Ci%2Cj%2Ck%2Cl%2Cm%2Cn%2Co%2Cp%2Cq%2Cr%2Cs%2Ct%2Cu%3Bfor(j%3D%22true%22%3D%3D%3Dthis.getAttribute(%22data-sorted%22)%2Ck%3Dthis.getAttribute(%22data-sorted-direction%22)%2Cb%3Dj%3F%22ascending%22%3D%3D%3Dk%3F%22descending%22%3A%22ascending%22%3Af.defaultSortDirection%2Cm%3Dthis.parentNode.querySelectorAll(%22th%22)%2Cn%3D0%2Cq%3Dm.length%3Bq%3En%3Bn%2B%2B)c%3Dm%5Bn%5D%2Cc.setAttribute(%22data-sorted%22%2C%22false%22)%2Cc.removeAttribute(%22data-sorted-direction%22)%3Bfor(this.setAttribute(%22data-sorted%22%2C%22true%22)%2Cthis.setAttribute(%22data-sorted-direction%22%2Cb)%2Cl%3Da.tBodies%5B0%5D%2Ch%3D%5B%5D%2Ct%3Dl.rows%2Co%3D0%2Cr%3Dt.length%3Br%3Eo%3Bo%2B%2B)g%3Dt%5Bo%5D%2Ch.push(%5Bd.getNodeValue(g.cells%5Be%5D)%2Cg%5D)%3Bfor(j%3Fh.reverse()%3Ah.sort(f.compare)%2Cu%3D%5B%5D%2Cp%3D0%2Cs%3Dh.length%3Bs%3Ep%3Bp%2B%2B)i%3Dh%5Bp%5D%2Cu.push(l.appendChild(i%5B1%5D))%3Breturn%20u%7D)%7D%2CgetColumnType%3Afunction(a%2Cb)%7Bvar%20e%2Cf%2Cg%2Ch%2Ci%3Bfor(i%3Da.tBodies%5B0%5D.rows%2Cg%3D0%2Ch%3Di.length%3Bh%3Eg%3Bg%2B%2B)if(e%3Di%5Bg%5D%2Cf%3Dd.getNodeValue(e.cells%5Bb%5D)%2C%22%22!%3D%3Df%26%26f.match(c))return%20d.types.numeric%3Breturn%20d.types.alpha%7D%2CgetNodeValue%3Afunction(a)%7Breturn%20a%3Fnull!%3D%3Da.getAttribute(%22data-value%22)%3Fa.getAttribute(%22data-value%22)%3A%22undefined%22!%3Dtypeof%20a.innerText%3Fa.innerText.replace(f%2C%22%22)%3Aa.textContent.replace(f%2C%22%22)%3A%22%22%7D%2Ctypes%3A%7Bnumeric%3A%7BdefaultSortDirection%3A%22descending%22%2Ccompare%3Afunction(a%2Cb)%7Bvar%20c%2Cd%3Breturn%20c%3DparseFloat(a%5B0%5D.replace(%2F%5B%5E0-9.-%5D%2Fg%2C%22%22))%2Cd%3DparseFloat(b%5B0%5D.replace(%2F%5B%5E0-9.-%5D%2Fg%2C%22%22))%2CisNaN(c)%26%26(c%3D0)%2CisNaN(d)%26%26(d%3D0)%2Cd-c%7D%7D%2Calpha%3A%7BdefaultSortDirection%3A%22ascending%22%2Ccompare%3Afunction(a%2Cb)%7Bvar%20c%2Cd%3Breturn%20c%3Da%5B0%5D.toLowerCase()%2Cd%3Db%5B0%5D.toLowerCase()%2Cc%3D%3D%3Dd%3F0%3Ad%3Ec%3F-1%3A1%7D%7D%7D%7D%2CsetTimeout(d.init%2C0)%2Cd.init(%7Bselector%3A%20'table'%7D)%3B%7D).call(this)%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment