Ticket #1958: style-fix.patch

File style-fix.patch, 1.9 kB (added by peller, 2 years ago)

patch from Josh Steiger (IBM)

  • Users/peller/Documents/workspace-dojo/0.4.1_working/src/html/style.js

     
    444444        if(URI){// fix paths in cssStr 
    445445                cssStr = dojo.html.fixPathsInCssText(cssStr, URI); 
    446446        } 
    447         var style = doc.createElement("style"); 
    448         style.setAttribute("type", "text/css"); 
    449         // IE is b0rken enough to require that we add the element to the doc 
    450         // before changing it's properties 
    451         var head = doc.getElementsByTagName("head")[0]; 
    452         if(!head){ // must have a head tag  
    453                 dojo.debug("No head tag in document, aborting styles"); 
    454                 return; //      HTMLStyleElement 
    455         }else{ 
    456                 head.appendChild(style); 
    457         } 
    458         if(style.styleSheet){// IE 
    459                 var setFunc = function(){  
    460                         try{ 
    461                                 style.styleSheet.cssText = cssStr; 
    462                         }catch(e){ dojo.debug(e); } 
    463                 }; 
    464                 if(style.styleSheet.disabled){ 
    465                         setTimeout(setFunc, 10); 
     447        var style; 
     448        var styleElements = doc.getElementsByTagName("style"); 
     449        if(styleElements.length == 0 ) { 
     450                style = doc.createElement("style"); 
     451                // IE is b0rken enough to require that we add the element to the doc 
     452                // before changing it's properties 
     453                var head = doc.getElementsByTagName("head")[0]; 
     454                if(!head){ // must have a head tag  
     455                        dojo.debug("No head tag in document, aborting styles"); 
     456                        return; 
    466457                }else{ 
    467                         setFunc(); 
     458                        head.appendChild(style); 
    468459                } 
    469         }else{ // w3c 
    470                 var cssText = doc.createTextNode(cssStr); 
    471                 style.appendChild(cssText); 
     460        }else{ 
     461                style = styleElements[0]; 
    472462        } 
     463        style.setAttribute("type", "text/css"); 
     464                if(style.styleSheet){// IE 
     465                style.styleSheet.cssText+= "\n" + cssStr; 
     466                }else{ // w3c 
     467                        var cssText = doc.createTextNode("\n" + cssStr); 
     468                        style.appendChild(cssText); 
     469        } 
    473470        return style;   //      HTMLStyleElement 
    474471} 
    475472