diff --git a/src/platforms/platform.dom.js b/src/platforms/platform.dom.js index c70d73963aa..3f41c5bbfee 100644 --- a/src/platforms/platform.dom.js +++ b/src/platforms/platform.dom.js @@ -304,17 +304,19 @@ function removeResizeListener(node) { } } -function injectCSS(platform, css) { - // https://stackoverflow.com/q/3922139 - var style = platform._style || document.createElement('style'); - if (!platform._style) { - platform._style = style; - css = '/* Chart.js */\n' + css; - style.setAttribute('type', 'text/css'); - document.getElementsByTagName('head')[0].appendChild(style); +function injectCSS(platform, cssRules) { + if (!platform._stylesheet) { + var styleElement = document.createElement('style'); + styleElement.setAttribute('type', 'text/css'); + document.getElementsByTagName('head')[0].appendChild(styleElement); + + platform._stylesheet = styleElement.sheet; } - style.appendChild(document.createTextNode(css)); + cssRules.forEach(function(cssRule) { + // index is required for IE11 + platform._stylesheet.insertRule(cssRule, 0); + }); } module.exports = { @@ -328,16 +330,15 @@ module.exports = { initialize: function() { var keyframes = 'from{opacity:0.99}to{opacity:1}'; - injectCSS(this, + injectCSS(this, [ // DOM rendering detection // https://davidwalsh.name/detect-node-insertion - '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' + - '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' + + '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}', '.' + CSS_RENDER_MONITOR + '{' + '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' + 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' + '}' - ); + ]); }, acquireContext: function(item, config) {