From d91ba9e2f9e081cfb53edeb2e73037257abab423 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 8 Nov 2016 16:54:35 -0800 Subject: [PATCH] Move injected css to start of head --- core/css.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/css.js b/core/css.js index 32f47a6f0..7c42cff1a 100644 --- a/core/css.js +++ b/core/css.js @@ -84,9 +84,14 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { // Strip off any trailing slash (either Unix or Windows). Blockly.Css.mediaPath_ = pathToMedia.replace(/[\\\/]$/, ''); text = text.replace(/<<>>/g, Blockly.Css.mediaPath_); - // Inject CSS tag. + // Inject CSS tag at start of head. var cssNode = document.createElement('style'); - document.head.appendChild(cssNode); + if (document.head.firstChild) { + document.head.insertBefore(cssNode, document.head.firstChild); + } else { + document.head.appendChild(cssNode); + } + var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); Blockly.Css.styleSheet_ = cssNode.sheet;