3
votes

I've got a problem with the presence indicators in sharepoint 2007 when I add more than one contact web part onto a page.

I noticed that I always got gray bubbles when more than one contact was added so I searched around the internet for a solution. Someone found that the ID of the img tag (of the presence indicator bubble) should not be unique. Because SharePoint automatically adds static ID's to the img tag I needed to override the ID. So I wrote this javascript code (copied the guid functions actually ;-)):

function S4() 
{
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
window.IMNRC = function(native) {
   return function(name, elem) {
       if(elem != null)
       {
       if(elem.id="contact_im,type=sip")
       {
           elem.id = guid();
       }
    }
    native(name, elem);    
    }
 }(window.IMNRC);

I don't know if it's good code, but when I added it to the page, the bubble showed the good presence of the contact. The only problem that I now have is that the menu does not work. When I hover over the presence indicator it becomes gray and all the links in the menu aren't working.

A collegue of me noticed that when he hovered over the presence indicator's a tooltip appeared with the name of the contact. Weird thing here is that the name did not matched the contact. When he refreshed he noticed that the name in the tooltip randomly changes. So I think this has something to do with me playing with the ID's of the img tag.

So now I have 2 options: - Or I need to start over and don't mess with the ID's off the img tag, and find another solution for the presence indicator problem - or I need to fix the menu problem.

Could someone help me with any of the 2 options?

Thanks!

2

2 Answers

1
votes

One thing that stands out to me immediately from a purely Javascript perspective is the following:

if(elem.id="contact_im,type=sip")

Should be:

if(elem.id=="contact_im,type=sip")

Which may be why your ID's are going all peculiar (they're being assigned instead of compared).

1
votes

Ok, I got it working :-). Thanks to Stuart who fixed my JavaScript code I was able to solve my problem. After the fix the menu problem was gone, but I still had a problem when I refreshed my page. The names linked to the presence indicator did not match the contact in the web part anymore. I noticed that the names where in complete opposite direction. I noticed that the IMNRC function I tried to override was called by another function who did this:

function QueuePopulateIMNRC(sipAddress, element)
{
    setTimeout("IMNRC('" + sipAddress + "', document.getElementById('" + element.id + "'));", 100);
}

where the element.id was the old element. I once read that JavaScript only remembers the last objects in case of a duplicate names so I was thinking this method call was causing the wrong names bug. I just needed to override the QueuePopulateIMNRC function so that the ID of my presence indicator gets changed at this moment (before the document.getelementbyid).

This is my final solution:

function S4() {
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function QueuePopulateIMNRC(sipAddress, element)
{
    if(element!=null)
    {
        if(element.id=="contact_im,type=sip")
        {
            element.setAttribute('id',guid());
        }
    }
    setTimeout("IMNRC('" + sipAddress + "', document.getElementById('" + element.id + "'));", 100);
}

If you add this piece of code in a hidden content editor webpart or directly in your master page your presence indicators will work when you add more than one contact web part.