Jump to content

MediaWiki:Common.js: Difference between revisions

replacing obsolete hasClass() with $(element).hasClass()
(is this necessary?)
(replacing obsolete hasClass() with $(element).hasClass())
Line 81: Line 81:
     appendCSS('.iezoomfix div, .iezoomfix table {zoom: 1;}');
     appendCSS('.iezoomfix div, .iezoomfix table {zoom: 1;}');
}
}
/* Test if an element has a certain class
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*
* @deprecated:  Use $(element).hasClass() instead.
*/
var hasClass = (function ()
{
    var reCache = {};
    return function (element, className)
    {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();




Line 138: Line 122:
         for (var j = 0; j < Cells.length; j++)
         for (var j = 0; j < Cells.length; j++)
         {
         {
             if (hasClass(Cells[j], "hovercell"))
             if ($(Cells[j]).hasClass("hovercell"))
             {
             {
                 $(Cells[j]).mouseover(new Function("evt", "showDescrip(this.id, true);"));
                 $(Cells[j]).mouseover(new Function("evt", "showDescrip(this.id, true);"));
Line 237: Line 221:
     for (var i = 0; i < Tables.length; i++)
     for (var i = 0; i < Tables.length; i++)
     {
     {
         if (hasClass(Tables[i], "collapsible"))
         if ($(Tables[i]).hasClass("collapsible"))
         {
         {
             /* only add button and increment count if there is a header row to work with */
             /* only add button and increment count if there is a header row to work with */
Line 271: Line 255:
     for (var i = 0; i < tableIndex; i++)
     for (var i = 0; i < tableIndex; i++)
     {
     {
         if (hasClass(NavigationBoxes[i], "collapsed") || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], "autocollapse")))
         if ($(NavigationBoxes[i]).hasClass("collapsed") || (tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass("autocollapse")))
         {
         {
             collapseTable(i);
             collapseTable(i);
         }  
         }  
         else if (hasClass(NavigationBoxes[i], "innercollapse"))
         else if ($(NavigationBoxes[i]).hasClass("innercollapse"))
         {
         {
             var element = NavigationBoxes[i];
             var element = NavigationBoxes[i];
             while (element = element.parentNode)
             while (element = element.parentNode)
             {
             {
                 if (hasClass(element, "outercollapse"))
                 if ($(element).hasClass("outercollapse"))
                 {
                 {
                     collapseTable(i);
                     collapseTable(i);
Line 319: Line 303:
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
         {
         {
             if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic'))
             if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic"))
             {
             {
                 NavChild.style.display = 'none';
                 NavChild.style.display = 'none';
Line 332: Line 316:
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
         {
         {
             if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic'))
             if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic"))
             {
             {
                 NavChild.style.display = 'block';
                 NavChild.style.display = 'block';
Line 350: Line 334:
     {
     {
         // if found a navigation bar
         // if found a navigation bar
         if (hasClass(NavFrame, "NavFrame"))
         if ($(NavFrame).hasClass("NavFrame"))
         {
         {
             indexNavigationBar++;
             indexNavigationBar++;
Line 358: Line 342:
             NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
             NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');


             var isCollapsed = hasClass(NavFrame, "collapsed");
             var isCollapsed = $(NavFrame).hasClass("collapsed");
             /*
             /*
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
Line 368: Line 352:
             for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling)
             for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling)
             {
             {
                 if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent'))
                 if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent"))
                 {
                 {
                     if (NavChild.style.display == 'none')
                     if (NavChild.style.display == 'none')
Line 380: Line 364:
                 for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
                 for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling)
                 {
                 {
                     if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent'))
                     if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent"))
                     {
                     {
                         NavChild.style.display = 'none';
                         NavChild.style.display = 'none';
Line 392: Line 376:
             for (var j = 0; j < NavFrame.childNodes.length; j++)
             for (var j = 0; j < NavFrame.childNodes.length; j++)
             {
             {
                 if (hasClass(NavFrame.childNodes[j], "NavHead"))
                 if ($(NavFrame.childNodes[j]).hasClass("NavHead"))
                 {
                 {
                     NavToggle.style.color = NavFrame.childNodes[j].style.color;
                     NavToggle.style.color = NavFrame.childNodes[j].style.color;
Line 548: Line 532:
             var theTable = tables[j];
             var theTable = tables[j];
             // If we found a sortable table that is asking for autosort...
             // If we found a sortable table that is asking for autosort...
             if (hasClass(theTable, "sortable") && hasClass(theTable, "autosort"))
             if ($(theTable).hasClass("sortable") && $(theTable).hasClass("autosort"))
             {
             {
                 var sortColumnNum = 1, curColumnNum = 0;
                 var sortColumnNum = 1, curColumnNum = 0;


                 // Take advantage of fact that hasClass() uses regex; if there is any by-column-x class at all,
                 // First check if there is any by-column-x class at all, then take the time to figure out the value of x
                // then take the time to figure out the value of x
                 if ($('div[theTable.className*="by-column-"]'))
                 if (hasClass(theTable, "by-column.."))
                 {
                 {
                     for (var col = 1; col < 10; col++)
                     for (var col = 1; col < 10; col++)
                     {
                     {
                         var colOption = "by-column-" + col;
                         var colOption = "by-column-" + col;
                         if (hasClass(theTable, colOption))
                         if ($(theTable).hasClass(colOption))
                         {
                         {
                             sortColumnNum = col;
                             sortColumnNum = col;
Line 572: Line 555:
                 for (var k = 0; k < allTHs.length; k++)
                 for (var k = 0; k < allTHs.length; k++)
                 {
                 {
                     if (hasClass(allTHs[k], "headerSort"))
                     if ($(allTHs[k]).hasClass("headerSort"))
                     {
                     {
                         curColumnNum++;
                         curColumnNum++;