Noticed this while trying to change the colors on adaptive / corolla theme (latest). I had to change the changeColor function in color.js to the following:

// Ratio is between 0 and 1
var changeColor = function(color, ratio, darker) {
  // Trim trailing/leading whitespace
  try {
    color = color.replace(/^\s*|\s*$/, '');

    // Expand three-digit hex
    color = color.replace(
        /^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i,
        '#$1$1$2$2$3$3'
    );

    // Calculate ratio
    var difference = Math.round(ratio * 256) * (darker ? -1 : 1),
        // Determine if input is RGB(A)
        rgb = color.match(new RegExp('^rgba?\\(\\s*' +
            '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
            '\\s*,\\s*' +
            '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
            '\\s*,\\s*' +
            '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
            '(?:\\s*,\\s*' +
            '(0|1|0?\\.\\d+))?' +
            '\\s*\\)$'
        , 'i')),
        alpha = !!rgb && rgb[4] != null ? rgb[4] : null,

        // Convert hex to decimal
        decimal = !!rgb? [rgb[1], rgb[2], rgb[3]] : color.replace(
            /^#?([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i,
            function() {
                return parseInt(arguments[1], 16) + ',' +
                    parseInt(arguments[2], 16) + ',' +
                    parseInt(arguments[3], 16);
            }
        ).split(/,/),
        returnValue;

    // Return RGB(A)
    return !!rgb ?
        'rgb' + (alpha !== null ? 'a' : '') + '(' +
            Math[darker ? 'max' : 'min'](
                parseInt(decimal[0], 10) + difference, darker ? 0 : 255
            ) + ', ' +
            Math[darker ? 'max' : 'min'](
                parseInt(decimal[1], 10) + difference, darker ? 0 : 255
            ) + ', ' +
            Math[darker ? 'max' : 'min'](
                parseInt(decimal[2], 10) + difference, darker ? 0 : 255
            ) +
            (alpha !== null ? ', ' + alpha : '') +
            ')' :
        // Return hex
        [
            '#',
            pad(Math[darker ? 'max' : 'min'](
                parseInt(decimal[0], 10) + difference, darker ? 0 : 255
            ).toString(16), 2),
            pad(Math[darker ? 'max' : 'min'](
                parseInt(decimal[1], 10) + difference, darker ? 0 : 255
            ).toString(16), 2),
            pad(Math[darker ? 'max' : 'min'](
                parseInt(decimal[2], 10) + difference, darker ? 0 : 255
            ).toString(16), 2)
        ].join('');
    }
    catch(e) {
      return '#000000';
    }
};
CommentFileSizeAuthor
#2 callstack.jpg533.48 KBbtopro
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

e0ipso’s picture

@btopro I would be useful to have the call stack for the moment of the JS failure.

Thanks!

btopro’s picture

FileSize
533.48 KB

here's a screenshot. I hate using try catches but I hate 1 JS error failing entire site even more :)

JuliaKoelsch’s picture

I just updated my module (from v7.x-2.2) and ran into this error. Well, my actual error message is:

Uncaught TypeError: Cannot read property 'replace' of null

I tried re-installing the module (disable, uninstall, install) but the error remained. This patch fixed the error. The error is problematic because it broke the admin menu, so caused issues on the entire backend.

js callstack:

Uncaught TypeError: Cannot read property 'replace' of null color.js?n6vb7o:13
changeColor color.js?n6vb7o:13
Drupal.behaviors.environment_indicatorToolbar.attach environment_indicator.js?n6vb7o:12
(anonymous function) drupal.js?n6vb7o:76
jQuery.extend.each jquery.js?v=1.7.1:652
Drupal.attachBehaviors drupal.js?n6vb7o:74
(anonymous function) drupal.js?n6vb7o:412
fire jquery.js?v=1.7.1:1046
self.fireWith jquery.js?v=1.7.1:1164
jQuery.extend.ready jquery.js?v=1.7.1:435
DOMContentLoaded

e0ipso’s picture

This may indicate that you don't have the appropriate variable set in your environment settings for the color. Please try to see if that fixes your problem.

supermoos’s picture

Seems to still be a problem. When I turn on advanced aggregation I get a JS error complaining like this: called from the function changeColor?

Uncaught TypeError: color.replace is not a function

e0ipso’s picture

Status: Needs work » Closed (won't fix)

Version for D7 is unmaintained. I am sorry for the inconvenience.