From: Bill W. <bil...@us...> - 2000-12-03 21:21:18
|
Bug report: date: 20001203 by: Bill Wheaton in: dynapi-2000.11.07-danwidgets.zip::dynapi/js/lib/dynapi/gui/label.js ua: IE5 (v5.00.2314.1003) symtom: label text is always default (courier new 10pt black) despite changing with font setting methods. possible cause: The Label object's setText method reads: Label.prototype.setText = function(text) { this.text = text || '' var styled = '<font point-size='+this.font.size+ ' family="'+this.font.family+'">'+this.text+'</b>' if (this.font.bold) styled = '<b>'+styled+'</b>' var width = this.wrap? 'width='+this.w : '' var wrap = this.wrap? '':'nowrap' this.textFull = '<table '+width+' cellpadding='+this.padding+ ' cellspacing=0 border=0><td align="'+ this.align+'" '+wrap+'>'+styled+'</td></table>' this.setHTML(this.textFull) } I think, that in setting the <font> it should end with </font>, not </b>, like: Label.prototype.setText = function(text) { this.text = text || '' var styled = '<font point-size='+this.font.size+ ' family="'+this.font.family+'">'+this.text+'</font>' if (this.font.bold) styled = '<b>'+styled+'</b>' var width = this.wrap? 'width='+this.w : '' var wrap = this.wrap? '':'nowrap' this.textFull = '<table '+width+' cellpadding='+this.padding+ ' cellspacing=0 border=0><td align="'+ this.align+'" '+wrap+'>'+styled+'</td></table>' this.setHTML(this.textFull) } Also, in the constructor I changed the line that reads: this.font = {} to: this.font = {bold : false, size : '9pt', family : "arial"} to give it some default values, which seems to work better in my IE5 (v5.00.2314.1003) Suggestion: Use a style instead of font tags: Label.prototype.setText = function(text) { // set the text if it there is any. if not then leave it alone // this will allow myLabel.setText() instead of myLabel.setText // (myLabel.text) which should not be allowed . (myLabel.setText // (myLabel.getText()) would be ok, but cumbersome.) this.text = text||this.text||'' var styled = '<div style="font-family:' + this.font.family + '; font-size:'+this.font.size + (this.bold?';font-weight:bold':'') + '; text-align:' + this.align + ';">' +this.text+'</div>' var width = this.wrap? 'width='+this.w : '' var wrap = this.wrap? '':'nowrap' // probably not much reason to keep textFull around after setHTML call, so do 'var ' instead of 'this.'. //Also, include the <tr></tr> tags in the table. NS browsers can be pretty picky about that. var textFull = '<table '+width+' cellpadding='+this.padding+ ' cellspacing=0 border=0><tr><td align="'+ this.align+'" '+wrap+'>'+styled+'</td></tr></table>' this.setHTML(textFull) } The div is needed to make the text-align work, span doesn't cut it. Perhaps the table should be dispensed with in favor of doing the whole thing as a layer with clipping. (unless there is a problem with using a div in which case you have to use a table... which may have been the original reason) Side Effects: I haven't figured out why, when the Label is used as part of the Button, I can't click on the label portion. I tried adding a cover, but no go. setSelectable didn't seem to do anything. -bw ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1 |