Advertisement
xof

Mod for global.js to sort apps

xof
May 26th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   // --- BEGIN MOD TO STANDARD ---
  2.   // Applies to global.js
  3.   // To sort the apps list
  4.   // By Chti Xof, May 2015
  5.   // adapted from http://stackoverflow.com/questions/8837191/sort-an-html-list-with-javascript#8837300
  6.   var ul=document.querySelector("#apps .listing-apps");
  7.   var new_ul = ul.cloneNode(false);
  8.  
  9.   // Add all lis to an array
  10.   var lis = [];
  11.   for(var i = ul.childNodes.length; i--;){
  12.     if(ul.childNodes[i].nodeName === 'LI')
  13.     lis.push(ul.childNodes[i]);
  14.   }
  15.  
  16.   // Sort in ascending order
  17.   lis.sort(function(a, b){
  18.     return a.querySelectorAll("span")[1].innerHTML.localeCompare(b.querySelectorAll("span")[1].innerHTML);
  19.   });
  20.  
  21.   // Add them into the ul in order
  22.   for(var i = 0; i < lis.length; i++)
  23.     new_ul.appendChild(lis[i]);
  24.   ul.parentNode.replaceChild(new_ul, ul);
  25.   // --- END MOD TO STANDARD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement