I was looking through the code of SharePoint’s Blank Web Part page layout, and I kept finding elements called _invisibleIfEmpty. Now, I’d noticed that some page layouts, such as the Splash page layout had borders on their web part zones which were only shown if the zone contained a web part. I was interested in how this might work. People keep asking for web parts with borders, preferrably ones with rounded corners.
The code on the page looked like:
<td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" height="100%">
<WebPartPages:WebPartZone runat="server" Title="Left" ID="CenterLeftColumn"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td>
…and there were a lot of table cells looking like that, and with that id. Lower in the page I then noticed:
Hmm. So if this function exists, it’s run. For it’s name, it sounds related. After some digging, I found it in defined in:
Interesting… IE5 is, well, pretty ancient now, so I’m guessing that this stuff is a bit, well, WSS2 legacy. What does the code do? Well, looking in one of those files:
var isNav=((agt.indexOf('mozilla')!=-1)&&((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1)));
for (var curElement=0; curElement < allElements.length; curElement++)
if ((isIE && allElements[curElement].childNodes.length==0)
|| (isNav && allElements[curElement].childNodes.length <=1))
I went and looked inside the Splash page layout and found that that is exactly how it works – the table cell’s borders don’t appear if the cell is empty:
However, the table cells do still appear to take up space – ‘cos each table cell has a width set:
If we took that width=”50%” away, though, the cells would just collapse as normal for empty table cells in HTML.