Skip to content

Commit

Permalink
Fixed regression, styled mode export failed in Firefox, plus offline …
Browse files Browse the repository at this point in the history
…export performance decreased after adding objectEach.
  • Loading branch information
TorsteinHonsi committed May 4, 2017
1 parent 3896549 commit 9aaef50
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions js/modules/exporting.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,8 @@ Chart.prototype.inlineStyles = function () {
dummy,
styleAttr,
blacklisted,
i;
i,
prop;

if (node.nodeType === 1 && unstyledElements.indexOf(node.nodeName) === -1) {
styles = win.getComputedStyle(node, null);
Expand All @@ -912,32 +913,40 @@ Chart.prototype.inlineStyles = function () {
dummySVG.removeChild(dummy);
}

// Loop over all the computed styles and check whether they are in the
// white list for styles or atttributes.
objectEach(styles, function (val, prop) {
// Loop over all the computed styles and check whether they are in
// the white list for styles or atttributes. Use a plain for-in loop
// because the styles object also contains numerically indexed
// pointers to its keys, and objectEach will fail in Firefox.
for (prop in styles) {
// Check against blacklist
blacklisted = false;
i = blacklist.length;
while (i-- && !blacklisted) {
blacklisted = blacklist[i].test(prop) || typeof val === 'function';
blacklisted = blacklist[i].test(prop) ||
typeof styles[prop] === 'function';
}

if (!blacklisted) {

// If parent node has the same style, it gets inherited, no need to inline it
if (parentStyles[prop] !== val && defaultStyles[node.nodeName][prop] !== val) {
// If parent node has the same style, it gets inherited, no
// need to inline it
if (
parentStyles[prop] !== styles[prop] &&
defaultStyles[node.nodeName][prop] !== styles[prop]
) {

// Attributes
if (inlineToAttributes.indexOf(prop) !== -1) {
node.setAttribute(hyphenate(prop), val);
node.setAttribute(hyphenate(prop), styles[prop]);

// Styles
} else {
cssText += hyphenate(prop) + ':' + val + ';';
cssText += hyphenate(prop) + ':' +
styles[prop] + ';';
}
}
}
});
}

// Apply styles
if (cssText) {
Expand Down Expand Up @@ -1033,7 +1042,7 @@ Chart.prototype.callbacks.push(function (chart) {

// Uncomment this to see a button directly below the chart, for quick
// testing of export
/*
//*
if (!chart.renderer.forExport) {
var button;

Expand Down

0 comments on commit 9aaef50

Please sign in to comment.