gachseang / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
0 stars 0 forks source link

Infobox - setting content as a node fails the second time #84

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
On line 592 of infobox.js:
    if (!this.fixedWidthSet_) {
      this.div_.style.width = this.div_.offsetWidth + "px";
      this.div_.innerHTML = this.getCloseBoxImg_() + content; //<- this line
    }

Setting the innerHTML means that if you've passed in a node instead of a 
string, you get the content of the infobox set to the toString of the node, 
rather than its content. I'd imagine this snippet should be:

    if (!this.fixedWidthSet_) {
      this.div_.style.width = this.div_.offsetWidth + "px";
      this.div_.innerHTML = this.getCloseBoxImg_(); //this
      this.div_.appendChild(content); //and this
    }

Indeed there's some kind of IE fix above this bit that works similarly. I'm not 
familiar with the IE bug that's being fixed, so I can't say for sure.

This doesn't occur when you set the content the first time, as this code is 
within a if(this.div_), so doesn't get called.

Version: 1.1.5 of infobox.js (today's)

Browser / Operating System:
Safari 5/OS X

Original issue reported on code.google.com by maxhar...@gmail.com on 1 May 2011 at 12:55

GoogleCodeExporter commented 8 years ago

Original comment by garylitt...@gmail.com on 9 May 2011 at 6:20

GoogleCodeExporter commented 8 years ago
Check the trunk version at 
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/ to 
verify that it solves your problem.

Original comment by garylitt...@gmail.com on 9 May 2011 at 6:39

GoogleCodeExporter commented 8 years ago
Fixed in 1.1.6.

Original comment by garylitt...@gmail.com on 8 Jul 2011 at 4:01

GoogleCodeExporter commented 8 years ago
I'm afraid this still doesn't work in 1.1.8. The code right now is:

    if (!this.fixedWidthSet_) {
      this.div_.style.width = this.div_.offsetWidth + "px";
      if (typeof content.nodeType === "undefined") {
        this.div_.innerHTML = this.getCloseBoxImg_() + content; //here (1)
      } else {
        this.div_.innerHTML = this.getCloseBoxImg_();
        // Note: don't append the content node again //and here (2)
      }
    }

There are a few problems here --
1. Using '+ content' means that nodes aren't appended correctly; the content 
gets set to [Object object], or alike. This should be using appendChild(), 
surely.
2. I'm not sure what the thoughts were behind that note, but the result is an 
infobox with no content in.

This could be reproduced by calling setContent twice with a node.

Original comment by maxhar...@gmail.com on 1 Oct 2011 at 10:23

GoogleCodeExporter commented 8 years ago
Replace this line

        // Note: don't append the content node again //and here (2)

with

      this.div_.appendChild(content);

and tell me if it solves your problem.

Original comment by garylitt...@gmail.com on 1 Oct 2011 at 11:58

GoogleCodeExporter commented 8 years ago
Yes, it does -- this is the workaround I'm using at the moment.

Original comment by maxhar...@gmail.com on 2 Oct 2011 at 8:23

GoogleCodeExporter commented 8 years ago
OK, I've just tagged a 1.1.9 release to fix this.

Original comment by garylitt...@gmail.com on 2 Oct 2011 at 4:33