Menu

#162 getWidth() / Height() problems with NS6

Verified
open
nobody
5
2001-08-23
2001-08-23
No

...
DynAPI.onLoad = function() {
label1 = new Label('Some text')
DynAPI.document.addChild(label1)
// returns a value with IE/NS - Win32
alert(label1.getWidth())

label2 = new Label('Some text')
d = new DynLayer()
d.addChild(label2)
DynAPI.document.addChild(d)
// returns a value with NS4 / IE - Win32
//but 'null' with NS 6.1 - Win32, DyAPI 2.54
alert(label2.getWidth())
}

Discussion

  • Nobody/Anonymous

    Logged In: NO

    I have a similar problem with NS6.2... I have the following:
    DynLayer.prototype.addPopupMenu = function
    (x,yAct,menuNames,menuLinks,menucolor,bordercolor)
    {
    var borderLayer = new DynLayer(null,(x-
    4),yAct,0,0,bordercolor);
    DynAPI.document.addChild(borderLayer);

    var spacerLayer = new DynLayer
    

    (null,1,0,0,0,menucolor);
    borderLayer.addChild(spacerLayer);

    var menuLayer = new DynLayer
    

    (null,2,0,0,0,menucolor);
    spacerLayer.addChild(menuLayer);
    var menuText = "";
    for (var i = 0; i < menuNames.length; i++)
    {
    menuText += "<A href=\""+menuLinks[i]+"\"
    class=\"menu\">"+menuNames[i]+"</A><BR>";
    }

    menuLayer.setHTML\(menuText\);   
    var w = menuLayer.getContentWidth\(\); 
    var h = menuLayer.getContentHeight\(\);
    menuLayer.setSize\(w,h\);
    
    spacerLayer.setSize\(\(menuLayer.getWidth\(\)+4\),
    

    (menuLayer.getHeight()+2));

    borderLayer.setSize\(\(spacerLayer.getWidth\(\)+2\),
    

    (spacerLayer.getHeight()+1));
    }

    In NS6.2, a thin layer loads without any text... the only
    workaround is to set borderLayer.setSize(200,200) or some
    other actual numbers.

     
  • Eric LE ROY

    Eric LE ROY - 2001-12-05

    Logged In: YES
    user_id=179452

    Got the same problem....and this is why my dynTabStrip
    object does not work under NS6

    I'm trying to find a solution
    Best Regards
    Lankou

     
  • Robert Rainwater

    Logged In: YES
    user_id=16618

    This is a bug in Mozilla. It doesn't set the offsetWidth
    immediately after creating the element. The only workaround
    at the moment is to use some sort of timeout and then
    retrieve the offsetWidth/Height.

    Rob

     
  • Eytan Heidingsfeld

    Logged In: YES
    user_id=50900

    I have a partial solution. Since there is no sleep or wait
    in JS you can't have syncrouns code that works here so I
    wrote 2 async functions to that call a specified callback:

    /* Code snip */

    DynLayer.prototype.cbGetContentWidth = function()
    {
    this.asyncw(this.elm.offsetWidth);
    this.elm.style.width = this.tw;
    }
    DynLayer.prototype.asyncGetContentWidth=function(result)
    {
    this.tw = this.elm.style.width;
    this.elm.style.width = "auto";
    this.asyncw = result;
    setTimeout("DynObject.all
    ['"+this.id+"'].cbGetContentWidth()",1);

    };
    DynLayer.prototype.cbGetContentHeight = function()
    {
    this.asynch(this.elm.offsetHeight);
    this.elm.style.height = this.th;
    }
    DynLayer.prototype.asyncGetContentHeight=function(result)
    {
    this.th = this.elm.style.height;
    this.elm.style.height = "auto";
    this.asynch = result;
    setTimeout("DynObject.all
    ['"+this.id+"'].cbGetContentHeight()",1);
    };
    /* End of Snip */
    An example usage:
    function alertWidth(w)
    {
    alert(w);
    }
    if (is.ns6)
    myLayer.asyncGetContentWidth(alertWidth);

     
  • Bruce Tennant

    Bruce Tennant - 2002-02-14

    Logged In: YES
    user_id=419209

    The current method in DynLayer 2.9 and 2.5.6. It actually
    breaks NS6.2.

    NS6.2 does not initially set style.width. So what happens
    is this.

    INITIALLY: offsetWidth = correct value
    set style.width = "auto"
    offsetWidth = still correct value
    set style.width = back to prior value (empty string)
    offsetWidth = 0

    So in NS 6.2, you DON'T want to use the style.width trick
    because by manually setting style.width = '' (empty string)
    it resets offsetWidth to 0.

    I added the following statements to getContentWidth/Height
    for NS

    if (dynapi.ua.ns4) return this.doc.width;
    else if (dynapi.ua.ie) {
    if (dynapi.ua.platform=="mac") return
    this.elm.offsetWidth;
    return parseInt(this.elm.scrollWidth);
    }
    // added by BT 2/13/2002
    else if (dynapi.ua.ns6) {
    return parseInt(this.elm.offsetWidth);
    }
    // -----
    else {
    ....

    Now after reading this bug report, I may need to add a
    minor version check rather than just for ns6. It looks
    like the NS bug was fixed in 6.2.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.