MediaWiki:Common.js: Difference between revisions

restoring safer code, it doesn't make a difference
(still trying to get sorter to run after page totally loads)
(restoring safer code, it doesn't make a difference)
Line 535: Line 535:
             if ($(theTable).hasClass("sortable") && $(theTable).hasClass("autosort"))
             if ($(theTable).hasClass("sortable") && $(theTable).hasClass("autosort"))
             {
             {
                var sortColumnNum = 1, curColumnNum = 0;
                 // First check if there is any by-column-x class at all, then take the time to figure out the value of x
                 // First check if there is any by-column-x class at all, then take the time to figure out the value of x
                 var patt = /by-column/;
                 var patt = /by-column/;
Line 545: Line 547:
                         {
                         {
                             //alert("Table " + j + " wants to sort by column " + col);
                             //alert("Table " + j + " wants to sort by column " + col);
                            sortColumnNum = col;


                             // Now look for sort button and click it
                             // Now look for sort button and click it
Line 553: Line 556:
                                 continue;
                                 continue;
                             }
                             }
                             else if (allTHs.length < col)
                             for (var k = 0; k < allTHs.length; k++)
                             {
                             {
                                 alert("There are only " + allTHs.length + " 'th' elements!");
                                 //alert("Class names for 'th' # " + k + " are " + allTHs[k].className);
                                 continue;
                                if ($(allTHs[k]).hasClass("headerSort"))
                                {
                                    curColumnNum++;
                                    if (curColumnNum == sortColumnNum)
                                    {
                                        alert("Clicking sort button (ID " + k + ") for column " + sortColumnNum);
                                        $(allTHs[k]).trigger("click"); // use jQuery's trigger() to send click event to this arrow
                                        return;
                                    }
                                 }
                             }
                             }
                            $(allTHs[col - 1]).trigger("click"); // use jQuery's trigger() to send click event to arrow button belonging to desired column
                         }
                         }
                     }
                     }
Line 567: Line 578:
}
}


window.addEventListener("load", sortSortableTables);
$(sortSortableTables);