Friday 13 July 2012

Emphasize site features/site collection features links with help from a custom action

I have been working with SharePoint for almost 2 years now, and still I have trouble finding the links to site features/site collection featues on the site settings page.

I have just come up with a solution to my frustration: Make javascript that emphasizes the links, and deploy it with a CustomAction. :D

Where's Waldo/the feature activation links


In my case I have made it as a custom action for portability reasons.

The structure of my project is as follows:


  • I have a site collection feature that activates the customaction.
  • Two modules - one with the custom action itself (names CustomAction), and one with the javascript files I'm using (named Assets). The latter modules is used to get the javascript files deployed to a library in SharePoint because you can't deploy physical files to the layouts folder with a sandboxed solution.

The custom action Elements.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="EC2D0A294F4C44868FF1E7DB7EA650E0"
              ScriptSrc="~SiteCollection/SiteAssets/Assets/jquery-1.7.2.min.js"
              Location="ScriptLink"
              Sequence="100">
  </CustomAction>
  <CustomAction Id="D2A0E5E1080D4C7ABA51361E574434DE"
               ScriptSrc="~SiteCollection/SiteAssets/Assets/myscript.js"
               Location="ScriptLink"
               Sequence="150">
  </CustomAction>
</Elements>



myscript.js:

function emphasize(elm) {
 
    var style = elm.attr('style');
    style += '; font-weight: bold;';
    elm.attr('style', style);  
}

$(document).ready(function () {
    var elm = $('a[href="/_layouts/ManageFeatures.aspx"]');
    emphasize(elm);
    elm = $('a[href="/_layouts/ManageFeatures.aspx?Scope=Site"]');
    emphasize(elm);

});



The custom action activates the two scripts when SharePoint loads. The sequece number defines in which order they are loaded. In my case I use jquery, so it is important, that the jQuery library is loaded before my script, that uses the library.

In my script I'm selecting the links to the feature activation page. For each of the I'm just adding a style that makes the link text bold - here you can get creative a do what ever. E.g. add a icon in front of the link, move the link to the top of its section or whatever. :)