From b8b813c3364018c6b120988b8c0606414a89b6b8 Mon Sep 17 00:00:00 2001 From: Ruben Almeida Date: Thu, 18 Aug 2016 12:10:11 +0200 Subject: [PATCH] Better addStyleSheet function Simplification of the function "addStyleSheet()" using innerHTML instead of createTextNode --- colorPicker.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/colorPicker.js b/colorPicker.js index dd10b04..845f43e 100644 --- a/colorPicker.js +++ b/colorPicker.js @@ -306,19 +306,19 @@ prefixIsolate = _options.CSSPrefixIsolate ? _options.CSSPrefixIsolate+' ':'', urlData = 'data:image/png;base64,', addStyleSheet = function(cssText, id) { - var style = document.createElement('style'); + var style = document.createElement('style'), + head = document.head || document.getElementsByTagName("head")[0] || document.body; style.setAttribute('type', 'text/css'); if (id) { style.setAttribute('id', id); } - if (!style.styleSheet) { - style.appendChild(document.createTextNode(cssText)); - } - document.getElementsByTagName('head')[0].appendChild(style); if (style.styleSheet) { // IE compatible - document.styleSheets[document.styleSheets.length-1].cssText = cssText; + style.styleSheet.cssText = cssText; + } else { //other browsers + style.innerHTML = cssText; } + head.appendChild(style); }, processCSS = function(doesBAS64){ // CSS - system