PDA

View Full Version : DomHelper applyStyles: IE bug



aefitzhugh
2 Apr 2007, 11:19 AM
I found that for string property values, applyStyles() passes the value without first trimming leading whitespace. E.g., if the style string is "background-color: red;", it passes " red" (note the leading space) as the value to setStyle(), and this fails in IE6.

I patched this in setStyles() by trimming the whitespace when the incoming value param is typeof "string". I think the real solution is to patch the regex pattern in applyStyles, but I'm too afraid of regex patterns to mess with that :-). I believe the second match expression below, "([^;]*)", should be modified to omit leading whitespace:


applyStyles : function(el, styles){
if(styles){
el = Ext.fly(el);
if(typeof styles == "string"){
var re = /\s?([a-z\-]*)\:([^;]*);?/gi;
var matches;
while ((matches = re.exec(styles)) != null){
el.setStyle(matches[1], matches[2]);
}
}else if (typeof styles == "object"){
for (var style in styles){
el.setStyle(style, styles[style]);
}
}else if (typeof styles == "function"){
Ext.DomHelper.applyStyles(el, styles.call());
}
}
},


(belated congrats on the release!)

jack.slocum
2 Apr 2007, 11:33 AM
Try this:

var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;

and let me know if it corrects it for you.

aefitzhugh
2 Apr 2007, 12:30 PM
Yes, that appears to do it, thanks! That is definitely a better patch than what I had in place.

-- Andy