PDA

View Full Version : htmleditor + fontsize + google chrome



willeraser
18 Feb 2011, 6:46 AM
Hi,

It seems that using the font-size option in the htmleditor interface bugs with google chrome (v9.0.597.98) while it works with firefox.
When you try to use the source editor option to manually increase the font size then you try to increase it again with the icon, it reduces the font size to default size. Weird...

japanick
22 Nov 2011, 11:49 AM
Our team noticed the same thing with new versions of Safari (5.1) and Chrome (15).

After looking at the Ext source code, it looks like webkit browsers used to return the font size in pixels but now it returns the font size in a number 1 through 7 like the other browsers. The special case code for Safari and Chrome needed to be removed and then it works great!

Old code:

adjustFont: function(btn){
var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
doc = this.getDoc(),
v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);
if((Ext.isSafari && !Ext.isSafari2) || Ext.isChrome || Ext.isAir){


if(v <= 10){
v = 1 + adjust;
}else if(v <= 13){
v = 2 + adjust;
}else if(v <= 16){
v = 3 + adjust;
}else if(v <= 18){
v = 4 + adjust;
}else if(v <= 24){
v = 5 + adjust;
}else {
v = 6 + adjust;
}
v = v.constrain(1, 6);
}else{
if(Ext.isSafari){
adjust *= 2;
}
v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0);
}
this.execCmd('FontSize', v);
},

New code:

adjustFont: function(btn){
var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
doc = this.getDoc(),
v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);
if(Ext.isAir){
if(v <= 10){
v = 1 + adjust;
}else if(v <= 13){
v = 2 + adjust;
}else if(v <= 16){
v = 3 + adjust;
}else if(v <= 18){
v = 4 + adjust;
}else if(v <= 24){
v = 5 + adjust;
}else {
v = 6 + adjust;
}
v = v.constrain(1, 6);
}else{
v = Math.max(1, v+adjust);
}
this.execCmd('FontSize', v);
},

We left the Ext.isAir case because we were not sure if it would still need the special case or not, and we did not test Air clients. If you want to remove the air case as well the code gets much simper:

adjustFont: function(btn){
var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
doc = this.getDoc(),
v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);
v = Math.max(1, v+adjust);
this.execCmd('FontSize', v);
},