SharePoint 2010 Fix for Note Board SocialComment WebPart Default Text Using jQuery

SharePoint 2010 has a cool Note Board Web Part (a.k.a SPSWC:SocialCommentWebPart) that you can use to share with colleagues [microsoft.com]. However, when there are no comments posted it will display the following text:

There are no notes posted yet. You can use notes to comment on a page, document, or external site. When you create notes they will appear here and under your profile for easy retrieval. Other people can also view the notes you post.
Right click or drag and drop this link to your browser’s favorites or bookmarks toolbar to use notes to comment on external sites.Click here for more information about this and other social networking features in Microsoft SharePoint Server 2010.

I spent some time with a colleague trying to discover where in the documented SharePoint featureset this default text could be updated but with no luck. So together we worked out a short jQuery script to search for the text and remove it.

The web part is loaded asychronously even after jQuery’s ready event so a regular css declaration was not an option. So we wrapped everything in a recursive JavaScript setTimeout callback. Here is the basic idea:

<div id="NoteBoardContainer" style="display:none">
<SPSWC:SocialCommentWebPart runat="server" id="Noteboard" />
</div>   
<script type="text/javascript"> 
 jQuery(document).ready(function() {  
      HideNoteBoardDefaultText();  
 });  
 function HideNoteBoardDefaultText(){  
      var noNote = jQuery('#NoteBoardContainer*:contains("There are no notes posted yet. You can use notes to comment on a page"):last');  
      var hasNote = jQuery('#NoteBoardContainer img').attr("src");  
      if(typeof hasNote == 'undefined' && jQuery(noNote).text() == ""){  
           setTimeout(HideNoteBoardDefaultText,50);  
      }  
      else
      {  
           jQuery('#NoteBoardContainer).attr("style","display:block");  
           jQuery(noNote).text("");  
      }  
 }
</script>

We start the Note Board hidden and only unhide it when we determine it is showing something other than the default text to avoid any flicker effect. As listed, the code will terminates after the web part is done with its initial load. This means the default text can sneak back in (briefly) from when you delete all the comments on a page until the you load the page again. We could have added another setTimeout call to keep the script running in the background monitoring for this content. But given the considered risk vs reward to cover the edge case in our particular configuration, we decided not to leave the scripts running to constantly monitoring for the condition.

It would be cool to have real support for this feature, but the workaround fix performs fine, and the Note Board is a great success!