Fixed XenForo.DisplayIgnoredContent

Zumega

New member
I was playing with the 'Show Ignored Content' functionality and I was getting a JS error. In FF a security error and in Chrome a 'length' read error. So after some digging I found that since our implementation of XenForo has cross domain CSS added to the site I was getting the error in the XenForo.DisplayIgnoredContent function in the xenforo.js file. The error was happening when the JS went to manipulate the CSS and remove the rules for '.ignore'

To remove the errors I skip the JS that manipulates the CSS, if the stylesheet has a NULL href and the domain is different:

Code:
domain = "'/"+document.domain+"/'";
if (document.styleSheets)
{
    for (i = 0; i < (document.styleSheets.length-1); i++)
    {
        styleSheet = document.styleSheets[i];
        if((styleSheet.href != null) && (styleSheet.href.match(domain))){
            rules = (styleSheet.cssRules) ? styleSheet.cssRules : styleSheet.rules;
            for (j = 0; j < rules.length; j++)
            {
                rule = rules[j];
 
                if (rule.selectorText && rule.selectorText.toLowerCase() == '.ignored')
                {
                    if (styleSheet.deleteRule)
                    {
                        styleSheet.deleteRule(j);
                    }
                    else
                    {
                        styleSheet.removeRule(j);
                    }
                }
            }
        }
    }
}

Please add this to the xenforo.js as this could be use full to other developers, thanks.
 
Fixed this with a try-catch around the rules access. That seems to fix it for all browsers.
 
Top Bottom