From 441479f1b4d0c52d92486572af487e92680ead15 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 19 Apr 2012 10:15:29 +0200 Subject: [PATCH] Added function to dynamically apply stylesheets --- js/Utils.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/Utils.js b/js/Utils.js index d7571acef..d1bc5a8c3 100755 --- a/js/Utils.js +++ b/js/Utils.js @@ -270,4 +270,25 @@ utils.toggleClass = function(el,className,status) { } }; +utils.applyStyleSheet = function(id,css) { + var el = document.getElementById(id); + if(document.createStyleSheet) { // Older versions of IE + if(el) { + el.parentNode.removeChild(el); + } + doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd", + ' '); // fails without   + } else { // Modern browsers + if(el) { + el.replaceChild(document.createTextNode(css), el.firstChild); + } else { + el = document.createElement("style"); + el.type = "text/css"; + el.id = id; + el.appendChild(document.createTextNode(css)); + document.getElementsByTagName("head")[0].appendChild(el); + } + } +}; + })();