SharePoint: integrate the Lync presence control in your pages and web parts

For one organizational chart page I needed to incorporate the Lync presence control next to each name. Practically I wanted to replicate what you get when you show a list containing a people picker field, but without using a field of this type.

 

I have found the article Integrate Lync into your intranet sites using the NameCtrl plug-in.

Only a few notes on the article:

  • 'case' is a JavaScript keyword, so when it is used as a field in the DIV, it has to be enclosed between quotes;
  • when creating the id of the control, in the getId function, it's needed to use a replaceAll function for SIDs like name.surname@domain.com

SharePoint and JavaScript CSOM

I'm relizing that I'm spending too much time googling the same topics over and over (on JavaScript programming), so I list here a few solution I need in a recurrent way.

 

JavaScript: how understand if page is opened in iFrame, and get its url

 

Javascript: how get url parameters

  • function to get query string parameters:
    function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
    }
  • source: How to get URL parameters with Javascript?

 

Javascript: function to format numbers

 

Javascript: function to format date-times

 

Javascript: how html encode strings

 

jQuery: how write a custom filter method

SharePoint: how add submenus in the top link bar

In SharePoint, without the Publishing Feature enabled, it's not possible to add sub-menus in the top link bar (except for sub-sites and related pages).

This is quite limiting, because it doesn't allow to organize menus in sites with many pages.

Luckily, I have found the solution in the article How can I add a dropdown menu to the Sharepoint Foundation top navigation bar?

Essentially, it's enough to import the file spf-dropdown2010.js or spf-dropdown2013.js after jQuery.

 

I have tried the solution above, and it worked, but it had the following:

  • PRO: possibility for the user to customize the sub-menus via SharePoint UI
  • CON: each time the page is loaded, the sub-menu items are seen for a short time
  • CON: for internal pages without the script, the sub-menus are not generated and so this doesn't give a nice UI (this point is valid in case it's not possible to modify the master page)

 

So I have changed implementation of the solution with the code below:

   $("span.menu-item-text:contains('TopMenu1')")

      .closest('li.static')

      .addClass('dynamic-children')

      .append('<UL class=dynamic></UL>')

      .find('ul')

      .append('<LI class="spfDropdowns-submenuitem dynamic"><A class="menu-item dynamic" href="Url1"><SPAN class=additional-background><SPAN class=menu-item-text>Descr1</SPAN></SPAN></A></LI>')

      .append('<LI class="spfDropdowns-submenuitem dynamic"><A class="menu-item dynamic" href="Url2"><SPAN class=additional-background><SPAN class=menu-item-text>Descr2</SPAN></SPAN></A></LI>');