User:Iritscen/TestSpace.js: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(apparently so)
m (wait, this *does* work? +cat test)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Put test JS here! */
/* Put test JS here! */
/***** autosort_sortable ********
* Auto-sorts sortable tables by specified columns (why is this not built-in?!)
*
*  Maintainers: [[User:Iritscen]]
*/


function sortSortableTables()
/*[[Category:Userspace]]*/
{
  // Iterate over all <div> elements
  var divs = document.getElementsByTagName("div");
  if (!divs) return;
  for (var i = 0; i < divs.length; i++)
  {
      var theDiv = divs[i];
      var tables = theDiv.getElementsByTagName("table");
      if (!tables) continue;
      for (var j = 0; j < tables.length; j++)
      {
        var theTable = tables[j];
        // If we found a sortable table...
        if (hasClass(theTable, "sortable"))
        {
            // ...Look for sort button
            var allTHs = theTable.getElementsByTagName("th");
            if (!allTHs) continue;
            for (var k = 0; k < allTHs.length; k++)
            {
              if (hasClass(allTHs[k], "headerSort"))
              {
                  $(allTHs[k]).trigger("click"); // use jQuery's trigger() to send click event to this arrow
                  return;
              }
            }
        }
      }
  }
}
 
addOnloadHook(sortSortableTables);

Latest revision as of 15:10, 8 April 2023

/* Put test JS here! */

/*[[Category:Userspace]]*/