Jump to content

MediaWiki:Common.js: Difference between revisions

making an attempt at getting sortable tables to sort on page load
(trying to find the <img>)
(making an attempt at getting sortable tables to sort on page load)
Line 480: Line 480:
}
}
addOnloadHook(uploadwizard_newusers);
addOnloadHook(uploadwizard_newusers);
/***** autosort_sortable ********
* Auto-sorts sortable tables by specified columns (why is this not built-in?!)
*
*  Maintainers: [[User:Iritscen]]
*/
function sortSortableTables()
{
  // Iterate over all <div> elements
  var divs = document.getElementsByTagName("div");
  for (var i = 0; i < divs.length; i++)
  {
      theDiv = divs[i];
      // If we found a sortable table...
      if (hasClass(theDiv, "sortable"))
      {
        // ...Look for sort button
        for (var i = 0; i < theDiv.length; i++)
        {
            var allTHs = Tables[i].getElementsByTagName("th");
            if (!allTHs) continue;
            for (var j = 0; j < allTHs.length; j++)
            {
              if (hasClass(allTHs[j], "headersort"))
              {
                  alert("Found the arrow.");
                  allTHs[j].trigger(click); // use jQuery's trigger() to send click event to this arrow
              }
            }
        }
      }
  }
}
addOnloadHook(sortSortableTables);