Jump to content

MediaWiki:Common.js: Difference between revisions

testing addition of choosable column to autosorting table code
(restoring XEB; it's back in working order!)
(testing addition of choosable column to autosorting table code)
Line 533: Line 533:


/***** autosort_sortable ********
/***** autosort_sortable ********
  * Auto-sorts sortable tables by first column (why is this not built-in?!)
  * Auto-sorts sortable tables by a given column (why is this not built-in?!)
  * You must opt in for this feature by placing "autosort" in the list of
  * You must opt into this feature by placing "autosort" in the list of
  * the table's classes along with "sortable"
  * the table's classes along with "sortable"
  *
  *
Line 556: Line 556:
             if (hasClass(theTable, "sortable") && hasClass(theTable, "autosort"))
             if (hasClass(theTable, "sortable") && hasClass(theTable, "autosort"))
             {
             {
              var sortColumnNum = 1, curColumnNum = 0;
              if (hasClass(theTable, "by-column"))
                  sortColumnNum = 2;
                 // ...Look for sort button and click it
                 // ...Look for sort button and click it
                 var allTHs = theTable.getElementsByTagName("th");
                 var allTHs = theTable.getElementsByTagName("th");
Line 563: Line 567:
                     if (hasClass(allTHs[k], "headerSort"))
                     if (hasClass(allTHs[k], "headerSort"))
                     {
                     {
                         $(allTHs[k]).trigger("click"); // use jQuery's trigger() to send click event to this arrow
                         curColumnNum++;
                        return;
                        if (curColumnNum == sortColumnNum)
                        {
                          $(allTHs[k]).trigger("click"); // use jQuery's trigger() to send click event to this arrow
                          return;
                        }
                     }
                     }
                 }
                 }