allow string based values for comboboxarray
[roojs1] / Roo / util / CSS.js
index 41e286f..1102f8c 100644 (file)
@@ -26,30 +26,49 @@ Roo.util.CSS = function(){
    /**
     * Very simple dynamic creation of stylesheets from a text blob of rules.  The text will wrapped in a style
     * tag and appended to the HEAD of the document.
-    * @param {String} cssText The text containing the css rules
+    * @param {String|Object} cssText The text containing the css rules
     * @param {String} id An id to add to the stylesheet for later removal
     * @return {StyleSheet}
     */
-   createStyleSheet : function(cssText, id){
-       var ss;
-       var head = doc.getElementsByTagName("head")[0];
-       var rules = doc.createElement("style");
-       rules.setAttribute("type", "text/css");
-       if(id){
-           rules.setAttribute("id", id);
-       }
+    createStyleSheet : function(cssText, id){
+        var ss;
+        var head = doc.getElementsByTagName("head")[0];
+        var nrules = doc.createElement("style");
+        nrules.setAttribute("type", "text/css");
+        if(id){
+            nrules.setAttribute("id", id);
+        }
+        if (typeof(cssText) != 'string') {
+            // support object maps..
+            // not sure if this a good idea.. 
+            // perhaps it should be merged with the general css handling
+            // and handle js style props.
+            var cssTextNew = [];
+            for(var n in cssText) {
+                var citems = [];
+                for(var k in cssText[n]) {
+                    citems.push( k + ' : ' +cssText[n][k] + ';' );
+                }
+                cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
+                
+            }
+            cssText = cssTextNew.join("\n");
+            
+        }
+       
+       
        if(Roo.isIE){
-           head.appendChild(rules);
-           ss = rules.styleSheet;
+           head.appendChild(nrules);
+           ss = nrules.styleSheet;
            ss.cssText = cssText;
        }else{
            try{
-                rules.appendChild(doc.createTextNode(cssText));
+                nrules.appendChild(doc.createTextNode(cssText));
            }catch(e){
-               rules.cssText = cssText; 
+               nrules.cssText = cssText; 
            }
-           head.appendChild(rules);
-           ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
+           head.appendChild(nrules);
+           ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
        }
        this.cacheStyleSheet(ss);
        return ss;
@@ -90,12 +109,12 @@ Roo.util.CSS = function(){
    },
 
    // private
-   cacheStyleSheet : function(ss){
+   cacheStyleSheet : function(stylesheet){
        if(!rules){
            rules = {};
        }
        try{// try catch for cross domain access issue
-           var ssRules = ss.cssRules || ss.rules;
+           var ssRules = stylesheet.cssRules || stylesheet.rules;
            for(var j = ssRules.length-1; j >= 0; --j){
                rules[ssRules[j].selectorText] = ssRules[j];
            }