Low impact text changing in SharePoint with jQuery

Mike Smith over at Tech Training Notes had a nice simple post a few weeks back on changing the default text displayed at the bottom of stock web parts in SharePoint. For example discussion boards show this text when it's blank:

"There are no items to show in this view of the "Test" discussion board. To create a new item, click "New" above. 

That's great but what if the "New" link isn't avaiable (if you turn off the full toolbar and put a discussion list on a page this would happen). Or what if you don't like calling it a discussion board (for various reasons) and want to say forum. Or want to provide additional information.

His solution is a little bit of JavaScript and then pushing his function into an array _spBodyOnLoadFunctionNames (which is a list of scripts SharePoint will run when the page loads). Here's the original version:

   1:  <script type="text/javascript">
   2:   
   3:  function ChangeDiscussionMessage()
   4:  {  
   5:      var a = document.getElementsByTagName("TD")  
   6:      for (var i=0;i<a.length;i++)  
   7:      {    
   8:          if (a[i].className=="ms-vb")    
   9:          {      
  10:              if (a[i].innerText.indexOf("There are no items to show in this view")>-1)      
  11:              {         
  12:                  a[i].innerHTML = "There are no active discussions";      
  13:              }    
  14:          }  
  15:      }
  16:  }
  17:   
  18:  _spBodyOnLoadFunctionNames.push("ChangeDiscussionMessage") 
  19:   
  20:  </script>

Here's a more simplified jQuery version:

   1:  <script type="text/javascript">
   2:   
   3:  $(document).ready(function(){
   4:      $("td .ms-vb:contains('There are no items to show in')").text('There are no active discussions');
   5:  });
   6:   
   7:  </script>

P.S. I'm still trying to find time to write up the blog post from this last weekend's code camp and will post the SharePoint developer resources soon!

1 Comment

  • jQuery is fast-becoming, oh hell - it already is - the band aid for fixing up SharePoint without having to delve into the master pages, layout or custom web parts. In my travels, I've accomplished more with a few lines of jQuery than dozens of lines of XML, ASP.NET and c#...

Comments have been disabled for this content.